ZFS Backups to External Hard Drives


ZFS allows to efficiently perform incremental backups to an external hard disk drive. Traditional backup tools such as rsync determine changes between two directories based on file system metadata including timestamps and compare modified files to identify the changed bytes. In contrast, ZFS offers snapshots and is able to store file differences when changes are being made. Thus, when backups are performed using ZFS tools, there is no need to identify changed bytes at backup time, since the file system is already aware of the changes. Unlike ZFS, rsync is not a file system, but an application and has to work on top of the file system. Therefore, rsync is unable to detect file system changes, while they are being made.

Under Solaris, the following commands allow one to check which disk drives are present:

ls -l /dev/rdsk
ls -l /dev/dsk
iostat -En

To see currently mounted ZFS file systems and their health status, use:

zpool list
zfs list
zpool status

The following example commands show how to configure disk drives:

# load disk drivers, attach to devices,
#  create /dev and /devices links, load device policy
devfsadm -c disk
# cleanup dangling device links
devfsadm -C -v
# list attachment points
cfgadm -a
# allow disk at sata2/1 to be used by Solaris
cfgadm -c configure sata2/1

To list ZFS pools which can be imported, run zpool import. Import specific pools using, e.g., zpool import extern01 where extern01 is the name of the pool to import. If you have not yet created a ZFS files system on the external disk, run zpool create extern01 c0t2d0 where extern01 is the name of the pool and c0t2d0 is the device name. zfs create automatically mounts the created file system. You can copy your backup files on it and run zpool export extern01 to save and unmount the pool. Later, use zfs import extern01 to mount the pool again (the -R option allows to specify a mount point). Do not run zfs create again, as the file system already exists.

The command zfs snapshot -r extern01@20140323 creates a snapshot named 20140323 of extern01 including all its descendant datasets. zfs list -t snapshot displays all available snapshots. To transfer snapshot 20140323 to pool extern02 and display information about extern02, execute:

zfs send extern01@20140323 | zfs receive extern02
zpool history extern02
zfs list -t all -r extern02
zfs list -t all -o space -r extern02

In the following we create another recursive snapshot of pool extern01 and transfer the changes to extern02:

zfs snapshot -r extern01@20140401
zfs send -R -i 20140323 extern01@20140401 | zfs receive -Fduv extern02

We just performed an incremental backup with a simple command. Always make sure that you are able to restore your backup.

The zfs send and zfs receive commands can easily be combined with other UNIX tools including ssh and gzip as demonstrated in the Solaris ZFS Administration Guide. Check out this cheatsheet for further useful ZFS commands.