ZFS Send & Receive
ZFS send and receive are foundational tools for data replication, backup, and disaster recovery in ZFS environments. These commands enable efficient transfer of dataset states between systems, leveraging ZFS's snapshot capabilities to minimize data duplication. By combining send (which generates a stream of changes) with receive (which applies that stream to a target dataset), administrators can synchronize data across systems, create point-in-time backups, or recover from catastrophic failures.
Basic Usage¶
The zfs send command creates a snapshot stream of a dataset, while zfs receive applies that stream to a target dataset. For a full replication:
# Create a snapshot
zfs snapshot tank/data@backup-20231001
# Send the snapshot to a remote system (via SSH or a pipe)
zfs send tank/data@backup-20231001 | ssh user@remote-host "zfs receive tank/data"
For local backups, you can pipe the stream to a file or another system. The -R flag ensures recursive inclusion of all child datasets:
Incremental Sends¶
Incremental sends transfer only the changes since a specified snapshot, reducing bandwidth and time. Use the -i (incremental) flag with a base snapshot:
# First, send a full snapshot
zfs send tank/data@initial | zfs receive tank/data
# Later, send incremental changes
zfs send -i tank/data@initial tank/data@current | zfs receive tank/data
The target system must have the base snapshot (initial) pre-existing. Incremental sends are ideal for regular backups or real-time replication.
Advanced Options¶
-
Compression: Use
-cto compress the send stream, reducing network bandwidth usage: -
Encryption: Secure data in transit with SSH or TLS (e.g., via
opensslorscp): -
Force Receiving: Use
-Fto overwrite existing data on the target (caution required):
Disaster Recovery Example¶
In a disaster recovery scenario, send and receive can restore data from a remote backup. Suppose a system fails and needs recovery:
-
Backup System: Regularly send snapshots to a remote server:
-
Recovery System: Restore the latest snapshot:
For partial recovery, you can extract specific snapshots from a stream:
Key takeaways¶
zfs sendandreceiveenable efficient data replication and backup by leveraging ZFS snapshots.- Incremental sends (
-i) minimize data transfer by tracking changes since a base snapshot. - Use compression and encryption to secure data in transit during replication.
- Always verify target datasets exist and match the source structure before receiving.
- Combine with SSH or network tools for secure, cross-system disaster recovery workflows.