ZFS Send and Receive

ZFS gives you the ability to send and receive data. Whether that is by combining snapshots, creating full and incremental backups, or simply replicating data between servers.

In this article we provide a number of examples of using ZFS send and receive

Local Backup with Send

This is a simple process by performing a send of a snapshot then output it to the file. For example:

# zfs send pinky/oradata@now > /backups/`date +%m%d%Y`/pinky-oradata.zsnd

Note: zfs send only creates the backups. In order to restore them we will to use the zfs receive

Local Restore with Receive

With the basic restore it is very easy, simply specify the file system to restore to, and then define the file to pull it from. For example:

# zfs receive pinky/restoredfilesystem < /backup/03152013/pinky-oradata.zsnd

Note: In the above command, we are performing a redirection back into the ZFS receive command from the file

Local Copy of a File System — Full Clone

Occasionally you may have the need to perform a full copy clone. With a normal zfs clone you will end up with a zero copy clone (copy-on-write), you will also have additional dependency when using zfs clones, which require a little extra caution. If using zfs send and receive to make a copy, then there is no interdependency.

# zfs send pinky/oradata@now | zfs receive pinky/copyoradata

In the above example, we concat both send and receive commands with just a simple pipe to separate the send and receive statements.

Local Compressed Backup with Send

If you want to store your backups in a compressed form. All we need to do is insert a gzip into the mix.

# zfs send pinky/oradata@now | gzip > /backup/`date +%m%d%Y`/pinky-oradata.zsnd.gz

In the above example, we simply combine a pipe with a redirect, and will give us a compressed file.

Local Compressed Restore with Receive

Now that we have backups, we need to restore them.

# gunzip -c -d /backup/03152013/pinky-oradata.zsnd.gz | zfs receive pinky/copyoradata

In the above example, we unzip the file, and pipe that into the zfs receive statement.

Local Encrypted (and Compressed) Backup with Send

Some workloads have serious security requirements. This will encrypt and compress the contents of the file system into a backup file. In this example we are using encrypt/decrypt to perform the encryption with aes, I also was unable to get the piping and redirection working without also injecting gzip as well.

# zfs send pinky/oradata@now | encrypt -a aes | gzip > /backup/`date +%m%d%Y`/pinky-oradata.zsnd.aes.gz
Enter passphrase:
Re-enter passphrase:

Since we are not using any keys with encrypt, it will simply prompt us for a passphrase. Remember when using encryption your data becomes worthless if you do not.

Local Encrypted (and Compressed) Restore with Receive

Decrypting and restoring the backup file is pretty straight forward, unzip the file, pipe it through decrypt and pipe it into zfs. For example:

# gunzip -c -d /backup/03152013/pinky-oradata.zsnd.aes.gz | decrypt -a aes | zfs receive pinky/copyoradata
Enter passphrase:

Note: Use the passphrase that you used when encrypting the backup to decrypt it.

Remote Copy of a File System — Full Clone

Generally, full clones are needed from one server to another, perhaps for data migration. We can use the following example:

# zfs send pinky/oradata@now | ssh root@192.168.0.21 "zfs receive pinky/copyoradata"