There are plenty of guides explaining how to back up FreeNAS - now TrueNAS - servers. Personally, I found them either vague in what they actually back up and what will be the final outcome or they get way too complicated for people of home NAS servers who want something that "just works". So here it is how I am periodically backing up my FreeNAS server to USB external drives.
Expected Result
Destination_Pool ==>This is the destination pool we want to backup TO.
---Backup_Source_Pool ==> This is the top-level dataset that will be created of the source pool.
---Dataset1
---Dataset2
---Sub-dataset
---Dataset3
Note how the original datasets of the Source_Pool all appear under Destination_Pool/Backup_Source_Pool. This means that another pool (say Source_Pool#2, not shown in the example above) may also be backed up to the Destination_Pool, e.g. to a dataset called Destination_Pool/Backup_Source_Pool#2. This would then also contain the full dataset and child dataset layout of this Source_Pool#2. Provided that the Destination_Pool has enough capacity, several pool dataset may be backed up to for example, a single USB drive.
Considerations
- Data deliberately deleted over time from Source_Pool should also be deleted on the Destination_Pool inside the backups. I do not want to hoard data that I deleted for a good reason.
- The snapshot used for backing up data must not be deleted until a newer backup was made using another, newer snapshot. In other words, always keep the latest snapshot of the system. Deleting all snapshots will require a full backup of the entire pool.
- Permissions and ACLs are retained.
If in any doubt, check man zfs.
Overview
- Identify source and destination datasets where backups should be made from and to.
- Create a snapshot of the source dataset.
- Send and receive dataset stream using zfs send | zfs receive to destination pool.
- For future backups, send incremental backups using the same method.
Initial Backup
- Create an initial snapshot of Source_Pool. I prefer doing this through the UI using a recursive snapshot. (Recursive means that all Datasets within Source_Pool will also be snapshotted, otherwise only data directly in the main Dataset directory will be snapshotted! Short: if you want the entire Pool, use recursive.)
Note: I highly recommend using and sticking to a naming style for snapshots. I am using,Source_Pool@BACKUP-20200814
and will adhere to this. - Create a dataset called Backup_Source_Pool under the Destination_Pool. I prefer doing this from the UI as well.
- Use ssh to log in to the FreeNAS server and verify the snapshot is there,
zfs list -t snapshot
if thre are too many snapshots, search for the correct one, e.g.
zfs list -t snapshot | grep @BACKUP-20200814
- Assuming both Source_Pool and Destination_Pool are present and mounted in the system, proceed by making the initial backup. Note: this requires root access, so
sudo -i
(sudo zfs send ... Does not work!)
zfs send -Rv Source_Pool@BACKUP-20200814 | zfs receive -Fdu Destination_Pool/Backup_Source_Pool
Incremental Backup
- you already have an initial backup, and
- you still have the snapshot of that backup (including the snapshots of all Sub-datasets if it was a recursive snapshot).
- Create a new recursive snapshot, this will be,
Source_Pool@BACKUP-20200815 - Use ssh to log in to the FreeNAS server and check the Snapshots available
zfs list -t snapshot | grep Source_Pool@BACKUP
Hopefully there will be,
Source_Pool@BACKUP-20200814
Source_Pool@BACKUP-20200815 Assuming both Source_Pool and Destination_Pool are present and mounted in the system, proceed by making the incremental backup. Note: this requires root access, so
sudo -i
(sudo zfs send ... Does not work!)zfs send -Rv -i Source_Pool@BACKUP-20200814 Source_Pool@BACKUP-20200815 | zfs receive -Fdu Destination_Pool/Backup_Source_Pool
Snapshot keeping strategy
Reference
- zfs send [-DvRp] [-[iI] snapshot] snapshot
- Creates a stream representation of the second snapshot, which is written to standard output. The output can be redirected to a file or to a different
system (for example, using ssh(1). By default, a full stream is generated.
-D
- Perform dedup processing on the stream. Deduplicated streams cannot be received on systems that do not support the stream deduplication feature.
- -i snapshot
- Generate an incremental stream from the first snapshot to the second snapshot. The incremental source (the first snapshot) can be
specified as the last component of the snapshot name (for example, the part after the @), and it is assumed to be from the same file system as the
second snapshot.
If the destination is a clone, the source may be the origin snapshot, which must be fully specified (for example, pool/fs@origin, not just @origin).
- -I snapshot
- Generate a stream package that sends all intermediary snapshots from the first snapshot to the second snapshot. For example, -I @a fs@d is similar to -i @a fs@b; -i @b fs@c; -i @c fs@d. The incremental source snapshot may be specified as with the -i option.
- -R
- Generate a replication stream package, which will replicate the
specified filesystem, and all descendent file systems, up to the named
snapshot. When
received, all properties, snapshots, descendent file systems, and clones
are preserved.
If the -i or -I flags are used in conjunction with the -R flag, an incremental replication stream is generated. The current values of properties, and current snapshot and file system names are set when the stream is received. If the -F flag is specified when this stream is received, snapshots and file systems that do not exist on the sending side are destroyed.
- -p
- Send properties.
- -v
- Print verbose information about the stream package generated.
- The format of the stream is committed. You will be able to receive your streams on future versions of ZFS.
- zfs receive [-vnFu] filesystem|volume|snapshot
zfs receive [-vnFu] [-d | -e] filesystem- Creates a snapshot whose contents are as specified in the
stream provided on standard input. If a full stream is received, then a
new file system is created
as well. Streams are created using the zfs send subcommand, which by default creates a full stream. zfs recv can be used as an alias for zfs
receive.
If an incremental stream is received, then the destination file system must already exist, and its most recent snapshot must match the incremental stream's source. For zvols, the destination device link is destroyed and recreated, which means the zvol cannot be accessed during the receive operation.
When a snapshot replication package stream that is generated by using the zfs send -R command is received, any snapshots that do not exist on the sending location are destroyed by using the zfs destroy -d command.
The name of the snapshot (and file system, if a full stream is received) that this subcommand creates depends on the argument type and the -d or -e option.
If the argument is a snapshot name, the specified snapshot is created. If the argument is a file system or volume name, a snapshot with the same name as the sent snapshot is created within the specified filesystem or volume. If the -d or -e option is specified, the snapshot name is determined by appending the sent snapshot's name to the specified filesystem. If the -d option is specified, all but the pool name of the sent snapshot path is appended (for example, b/c@1 appended from sent snapshot a/b/c@1), and if the -e option is specified, only the tail of the sent snapshot path is appended (for example, c@1 appended from sent snapshot a/b/c@1). In the case of -d, any file systems needed to replicate the path of the sent snapshot are created within the specified file system.
-d
- Use all but the first element of the sent snapshot path (all but the pool name) to determine the name of the new snapshot as described in the paragraph above.
- -e
- Use the last element of the sent snapshot path to determine the name of the new snapshot as described in the paragraph above.
- -u
- File system that is associated with the received stream is not mounted.
- -v
- Print verbose information about the stream and the time required to perform the receive operation.
- -n
- Do not actually receive the stream. This can be useful in conjunction with the -v option to verify the name the receive operation would use.
- -F
- Force a rollback of the file system to the most recent snapshot before performing the receive operation. If receiving an incremental replication stream (for example, one generated by zfs send -R -[iI]), destroy snapshots and file systems that do not exist on the sending side.
No comments:
Post a Comment