Restoring a from a zipped snapshot

Unruffled

Cadet
Joined
Feb 25, 2021
Messages
4
I was looking for a way to backup my iSCSI LUN. There are couple of posts on the forum, but no clear answer as to how to do it. Then I found this post.


The idea is to create a snapshot of the zvol, compress it to a .gz file, then back it up. I modified the script slightly to try stuff.

Code:
#!/bin/sh

snapshot_name=$1@$(date +%Y-%m-%d)
target=$2

echo "Creating snapshot $snapshot_name..."
zfs snapshot $snapshot_name

echo "Saving to $target"
zfs send --verbose $snapshot_name | gzip > $target

echo "Deleting snapshot..."
zfs destroy $snapshot_name


Then I would create a cron job that would look like this.

/path/to/script.sh pool/path/to/zvol /path/to/file.gz

But there is no explanation on how to restore from a backup. What would be the command?
 

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
Well, before we get to restore, make sure you are backing up a quiet volume. Any ZFS zVol in use can be problematic to restore. The absolutely best way for a clean backup, is either un-mount the iSCSI volume from the client. Or shut the client down. Your call if you want to go to this extra effort. I would for at least monthly backups. But weekly or daily, you can take a risk.


Now for the restore:
gzip -dc $target | zfs receive -vd POOL zfs destroy $1@$(date +%Y-%m-%d)

Their are options to discard the pool name, (-d), or all but the dataset name, (-e), from the backup data. These can be useful depending on how you want to restore the data.

After the restore, you will have a left over snapshot that is not needed on the restored zVol. You can and probably should remove it. Thus, I show an example above.

As for the receive target, I vaguely recall their being something path expansion. So check it out on a test system, like a VM.
 
Top