Backups with ZFS over the wire

Okay, let’s say you are a proud owner of a system and use ZFS. Now lets assume that you lost a disk from your storage and want a fast backup of your data without the hassle of packing up everything, checking for permissions and so on. If the target system has ZFS too, then this will be fun for you, because I will show you, how to make a backup of a ZFS partition and all its descendants in some small steps.

First, you have to build a recursive snapshot for the backup. This can be done with

zfs snapshot -r tank/testpartition@backup-today

After that the real magic happens. We send this snapshot over ssh and import it on the other side.

zfs send -R tank/testpartition@backup-today | ssh target.machine "zfs recv -u tank/backup-machine"

Now all partitions from =tank/testpartition= will be put in =tank/backup-machine= and everything will be preserved. Links will be links, permissions will be the same. The flag =-u= is to prevent mounting the partitions on the target machine or else all partitions will be mounted as they were before.

As this sends the complete dataset over the wire, it is not that usable for backups every day. For this use case, use incremental sends (with the option =-i=). On the receiving side, nothing changes.

Thanks at this point to shl for showing me ZFS.