Skip to content

ZFS snapshot send/recv: filesystem-native replication

Using zfs send and zfs receive to replicate snapshots between pools, with incremental streams, encryption-preserving raw mode, and the cron pattern we deploy on production datasets.

ZFS snapshots are atomic, copy-on-write, and free; zfs send turns one into a byte stream and zfs receive lands it back into another pool. This is filesystem-native replication — no rsync rescans, no per-file overhead, no userspace metadata layer. We use it as the primary “host-to-host” backup mechanism on ZFS-based stacks because it preserves snapshot lineage, runs incrementally, and works across pools of different geometry. This article walks through the wire-up, the incremental pattern, encrypted raw sends, and the rotation we deploy.

How to verify

A working send/recv setup looks like this:

zfs version
zfs list -t snapshot -o name,used,refer | head
zfs list -t snapshot -r tank/data
ssh backup-host zfs list -r tank/replica
zfs send tank/data@snap1 | ssh backup-host zfs receive -F tank/replica

The presence of paired snapshots on both pools — same names, same GUIDs — is what proves replication. Once the streams diverge (e.g. someone deletes a snapshot on either side), the incremental chain breaks and you need a fresh full.

What’s happening

A ZFS snapshot is a read-only reference to the state of a dataset at a moment in time. Because ZFS is copy-on-write, snapshots cost nearly nothing to create and only consume space as the live data diverges from them.

zfs send <dataset>@<snapshot> reads the on-disk record list for that snapshot and emits a stream — a self-describing binary format that includes all the data blocks plus the metadata needed to recreate the snapshot on another pool. zfs receive consumes that stream and writes it to the destination as a new snapshot.

The big win is the incremental form: zfs send -i @snap1 tank/data@snap2 emits only the blocks that changed between the two snapshots. The receiving side already has snap1, so it can apply the delta and end up with snap2 — same GUID, same content, same lineage. Future incrementals build on snap2.

The “raw” mode (zfs send -w) is what makes encrypted datasets portable. With -w, the stream contains the encrypted ciphertext blocks, and the receive side does not need the encryption key — it just stores the ciphertext. The destination pool can replicate an encrypted dataset without ever holding the key material. We use this everywhere a backup target is in a less-trusted location than the primary.

The procedure

  1. Create a snapshot. Tag it with a name your script can recognize (timestamp or counter).

    zfs snapshot tank/data@auto-2026-06-01
    zfs list -t snapshot -r tank/data
  2. Send the first full to the backup host. This is the bootstrap; later runs go incremental.

    zfs send -v tank/data@auto-2026-06-01 | \
      ssh root@backup zfs receive -Fu tank/replica/data

    -F rolls back the destination to match if it has diverged; -u keeps the dataset unmounted on the receiver (important — you don’t want the replica writable).

  3. Take the next snapshot and send the incremental.

    zfs snapshot tank/data@auto-2026-06-02
    zfs send -v -i @auto-2026-06-01 tank/data@auto-2026-06-02 | \
      ssh root@backup zfs receive -Fu tank/replica/data
  4. Automate. We use a per-dataset systemd timer that runs a small wrapper script:

    #!/usr/bin/env bash
    set -euo pipefail
    ds=tank/data
    dest=root@backup:tank/replica/data
    prev=$(zfs list -H -t snapshot -r -o name -s creation $ds | tail -1)
    new=$ds@auto-$(date +%Y%m%dT%H%M%S)
    zfs snapshot $new
    if [[ -n "$prev" && "$prev" != "$new" ]]; then
      zfs send -v -i $prev $new | ssh ${dest%%:*} zfs receive -Fu ${dest##*:}
    else
      zfs send -v $new | ssh ${dest%%:*} zfs receive -Fu ${dest##*:}
    fi
  5. Rotate snapshots on both sides. We typically retain hourly for 48h, daily for 30 days, weekly for 12 weeks, monthly for 12 months. zfs-auto-snapshot, sanoid/syncoid, and zrepl all handle this; for production we have moved most engagements to zrepl because its pull-based receiver model and built-in monitoring fit our operating pattern.

  6. Verify the chain.

    # Both sides should agree on snapshot GUIDs:
    zfs list -t snapshot -o name,guid -r tank/data | tail
    ssh root@backup zfs list -t snapshot -o name,guid -r tank/replica/data | tail

Operational notes

  • Once the source-side snapshot a receiver depends on is deleted, the incremental chain is broken. The fix is a fresh full — expensive on multi-TB datasets. Coordinate retention on both sides to keep the latest replicated snapshot alive on the source for at least one full retention period.
  • Bandwidth: zfs send does not compress on the wire. For across-region replication, pipe through mbuffer to smooth bursts and zstd to compress the stream — or use zfs send -c (compressed-record send) for zpool’s native compression.
  • -R (replicate hierarchy) and -p (include properties) are the difference between “ship the data” and “ship the dataset config”. For real DR you want both.
  • Receiving as root with full ssh access is the simplest setup but a big trust grant. Restrict the receiver SSH key with a forced command (zfs receive -F tank/replica/data) so the source side can only push the dataset it owns.
  • Encrypted raw send (-w) is mandatory when the destination is colocation / a hosted backup endpoint you do not trust to hold the key. The trade-off is that the destination can never zfs mount or read the data without the key — fine for backups, a constraint for “warm standby” scenarios.
  • zfs receive on a non-empty target needs -F to roll back, otherwise it bails. Be careful with -F on production replicas — it overwrites local changes.

In the engagements we run, ZFS send/recv is the spine of any ZFS-based backup strategy. We layer it under tooling like zrepl or sanoid/syncoid for the orchestration and add a third copy via BorgBackup or restic for the format-portable offsite. The full picture of how we operate this kind of stack is at /en/services/managed-operations/.