Software >> OS >> Unix >> Solaris >> zfs >> how to backup and restore zfs snaphot

Saving a ZFS Snapshot

The simplest form of the zfs send command is to save a copy of a snapshot. For example:  

# zfs send tank/dana@040706 > /dev/rmt/0

You can save incremental data by using the zfs send i option. For example:

# zfs send -i tank/dana@040706 tank/dana@040806 > /dev/rmt/0

Note that the first argument is the earlier snapshot and the second argument is the later snapshot.

If you need to store many copies, you might consider compressing a ZFS snapshot stream representation with the gzip command. For example:

# zfs send pool/fs@snap | gzip > backupfile.gz

Restoring a ZFS Snapshot

When you restore a file system snapshot, the file system is restored as well. The file system is unmounted and is inaccessible while it is being restored. In addition, the original file system to be restored must not exist while it is being restored. If a conflicting file system name exists, zfs rename can be used to rename the file system. For example:  

# zfs send tank/gozer@040706 > /dev/rmt/0

.
.
# zfs receive tank/gozer2@today < /dev/rmt/0
# zfs rename tank/gozer tank/gozer.old
# zfs rename tank/gozer2 tank/gozer

You can use zfs recv as an alias for the zfs receive command.

When you restore an incremental file system snapshot, the most recent snapshot must first be rolled back. In addition, the destination file system must exist. In the following example, the previous incremental saved copy of tank/dana is restored.

# zfs rollback tank/dana@040706
cannot rollback to 'tank/dana@040706': more recent snapshots exist
use '-r' to force deletion of the following snapshots:
tank/dana@now
# zfs rollback -r tank/dana@040706/
# zfs recv tank/dana < /dev/rmt/0

During the incremental restore process, the file system is unmounted and cannot be accessed.