Saving and Restoring ZFS Data

The zfs send command creates a stream representation of a snapshot that is written to standard output. By default, a full stream is generated. You can redirect the output to a file or to a different system. The zfs receive command creates a snapshot whose contents are specified in the stream that is provided on standard input. If a full stream is received, a new file system is created as well. You can save ZFS snapshot data and restore ZFS snapshot data and file systems with these commands. See the examples in the next section.

The following solutions for saving ZFS data are provided:

Consider the following when choosing a solution for saving ZFS data:

Saving ZFS Data With Other Backup Products

In addition to the zfs send and zfs receive commands, you can also use archive utilities, such as the tar and cpio commands, to save ZFS files. All of these utilities save and restore ZFS file attributes and ACLs. Check the appropriate options for both the tar and cpio commands.

For update-to-date information about issues with ZFS and third-party backup products, please see the Solaris Express release notes.

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/[email protected] > /dev/rmt/0

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

# zfs send -i tank/[email protected] tank/[email protected] > /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/[email protected] | 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/[email protected] > /dev/rmt/0

# zfs receive tank/[email protected] < /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/[email protected]
cannot rollback to 'tank/[email protected]': more recent snapshots exist
use '-r' to force deletion of the following snapshots:
tank/[email protected]
# zfs rollback -r tank/[email protected]/
# zfs recv tank/dana < /dev/rmt/0

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

Remote Replication of ZFS Data

You can use the zfs send and zfs recv commands to remotely copy a snapshot stream representation from one system to another system. For example:

# zfs send tank/[email protected] | ssh newsys zfs recv sandbox/[email protected]

This command saves the tank/[email protected] snapshot data and restores it into the sandbox/restfs file system and also creates a [email protected] snapshot on the newsys system. In this example, the user has been configured to use ssh on the remote system.