Sending a ZFS Snapshot
You can use the zfs send
command to send a copy of a snapshot stream and receive the snapshot stream in another pool on the same system or in another pool on a different system that is used to store backup data. For example, to send the snapshot stream on a different pool to the same system, use a command similar to the following example:
$ zfs send pool/diant@snap1 | zfs recv spool/ds01
Tip:
You can usezfs recv
as an alias for the zfs receive
command.
If you are sending the snapshot stream to a different system, pipe the zfs send
output through the ssh
command. For example:
sys1$ zfs send pool/diant@snap1 | ssh sys2 zfs recv pool/hsolo
When you send a full stream, the destination file system must not exist.
If you need to store many copies, consider compressing a ZFS snapshot stream representation with the gzip
command. For example:
$ zfs send pool/fs@snap | gzip > backupfile.gz
Example 8-1 Sending Incremental ZFS Data
You can send incremental data by using the zfs send
-i
option. For example:
sys1$ zfs send -i pool/diant@snap1 system1/diant@snap2 | ssh system2 zfs recv \ pool/hsolo
The first argument (snap1
) is the earlier snapshot and the second argument (snap2
) is the later snapshot. In this case, the pool/hsolo
file system must already exist for the incremental receive to be successful.
You can specify the incremental snap1 source as the last component of the snapshot name. You would then have to specify only the name after the @
sign for snap1, which is assumed to be from the same file system as snap2. For example:
sys1$ zfs send -i snap1 pool/diant@snap2 | ssh system2 zfs recv pool/hsolo
This shortcut syntax is equivalent to the incremental syntax.
The following message is displayed if you attempt to generate an incremental stream from a different file system snapshot1
:
cannot send 'pool/fs@name': not an earlier snapshot from the same fs
Accessing file information in the original received file system can cause the incremental snapshot receive operation to fail with a message similar to this one:
cannot receive incremental stream of pool/diant@snap2 into pool/hsolo: most recent snapshot of pool/diant@snap2 does not match incremental source
Consider setting the atime
property to off
if you need to access file information in the original received file system and if you also need to receive incremental snapshots into the received file system.
If you need to store many copies, consider compressing a ZFS snapshot stream representation with the gzip
command. For example:
$ zfs send pool/fs@snap | gzip > backupfile.gz
Example 8-2 Sending ZFS Data Using Raw Transfer
To send the stream in raw mode, use the -w compress
option.
The following example shows that the raw transfer stream for a given snapshot is smaller, even though the file system created after receiving the stream is the same as the original. First, create a file system called pool/compressed-fs
which you fill with data.
$ zfs create -o compression=gzip-6 pool/compressed-fs $ cp /usr/dict/words /pool/compressed-fs/
Next, create a snapshot and check the compression ratio. For comparison purposes, create two streams to see the difference in sizes between a regular transfer and a raw transfer, Note that the rawstream
file is smaller.
$ zfs snapshot pool/compressed-fs@snap $ zfs get compressratio pool/compressed-fs@snap NAME PROPERTY VALUE SOURCE pool/compressed-fs@snap compressratio 2.80x - $ zfs send pool/compressed-fs@snap > /tmp/stream $ zfs send -w compress pool/compressed-fs@snap > /tmp/rawstream $ ls -lh /tmp/*stream -rw-r--r-- 1 root root 100K Dec 23 18:23 /tmp/rawstream -rw-r--r-- 1 root root 304K Dec 23 18:23 /tmp/stream
Next, receive the raw transfer stream on its new location. Then to verify that the content is identical, compare the new file system to the original.
$ zfs receive pool/rawrecv </tmp/rawstream $ diff -r /pool/compressed-fs/ /pool/rawrecv/ $
Example 8-3 Sending ZFS Data From a Oracle Solaris 11.4.0 Dataset
The ability to use per record checksums in the output data stream is enabled by default. To transfer data to older systems, you must disable this feature using the nocheck
argument.
$ zfs send -s nocheck pool/diant@snap1 | zfs recv pool/ds01