How to backup a ZFS dataset

I have a ZFS dataset that I use as VM storage and I want to back that up to another ZFS pool on the same machine. Currently I'm just using rsync to copy the most recent weekly snapshot to that pool but it's slow and uses a lot of resources. So I want to start over using zfs send recv but I'm not sure exactly how to do it.

If I make a script that does an incremental zfs send recv of the most recent weekly snapshot using the previous weekly snapshot as the earlier snapshot will that work?

something like this:

zfs send -i previous_snapshot current_snapshot | zfs recv backups/virtual

Where the script will work out which is the most recent and which is the second most recent to use in the command. The script will also delete the oldest snapshot once a certain number has been reached.

Are there any problems with this? Basically I just want to send the snapshot data without having to copy the whole filesystem every time and without having to unmount the dataset.

1 Like

So to answer your question, scripting ZFS replication is how you want to do it. Otherwise you're stuck manually doing a zfs send each time you want to replicate, and that's just no fun at all.

But it's important to note, this has already been done, and done really, really well. Sanoid is your friend.

Here's an excerpt from the sanoid.conf file.

# zpool/dataset
[protopool/certdisks]
use_template = freenasesque

# Define my own template to look like what FreeNAS offers me
[template_freenasesque]
hourly = 48
daily = 0
monthly = 0
yearly = 0
autosnap = yes
autoprune = yes

# One of the default templates, allowing you to create snapshots like traditional tape backup.
[template_production]
hourly = 36
daily = 30
monthly = 3
yearly = 0
autosnap = yes
autoprune = yes

There's also a template for a backup dataset, in case you want something like your primary server keeping only the last 2 weeks of snapshots handy, but a backup server keeps like the last 6 months of snapshots handy. Not as useful in your scenario, I don't think. But it's worth mentioning.

Demo.

3 Likes

That looks like pretty much what I'm looking for, thanks