FreeBSD

ZFS Snapshots, Send/Recv, and Disaster Recovery on FreeBSD 15

A ZFS snapshot on FreeBSD 15 took 0.03 seconds to create, and a busy hour of changes to our 3.6 GiB dataset sent as 286 MB. That is 11.8% of the full compressed stream. Those two numbers are the whole case for zfs send | zfs recv as a backup. The snapshot is atomic at the block level, and replication ships only the blocks that changed since the last one the replica holds.

Original content from computingforgeeks.com - post 166338

We replicate a dataset from one FreeBSD 15 host to another over SSH, using a delegated user instead of root on the receiver. It covers incremental streams, resume tokens, raw encrypted sends, holds, bookmarks, a cron job with retention, and a timed disaster-recovery restore. The full stream crossed SSH in 14.7 seconds on OpenZFS 2.4.2 (benchmarked November 2026 on FreeBSD 15.1), and every error message below was triggered on purpose in that lab.

Measured results: zfs send over SSH between two FreeBSD 15 hosts

Bytes on the wire and disk throughput decided these results; SSH tuning did not. Our replica wrote 139.7 MB/s in a single-stream dd test, and every compressed full send landed about 20% above that figure whichever flags we added. The table holds the figures from both hosts, two runs per method where the method was a throughput test:

OperationStream sizeWall timeRate
Full send, plain stream3.99 GB20.58 s / 20.41 s195 MB/s
Full send, -c (compressed blocks)2.44 GB14.74 s / 14.72 s166 MB/s
Full send, -c + aes128-gcm cipher2.44 GB14.55 s / 14.57 s168 MB/s
Full send, -c + aes128-gcm + mbuffer both ends2.44 GB14.82 s / 14.79 s165 MB/s
Incremental, 256 MiB rewritten + 1M log lines286 MB2.69 s106 MB/s
Incremental, one config line changed33.4 KBinside the 2.69 s runn/a
Resumed send after interruption2.44 GB of 3.23 GB15.51 s157 MB/s
Raw encrypted send (-w)290 MB2.02 s144 MB/s
Disaster restore, replica to source2.44 GB19.66 s124 MB/s
Snapshot creationn/a0.03 sn/a

How each number was taken matters as much as the number, so here is the method:

  • Hosts: two FreeBSD 15.1-RELEASE-p6 VMs (bench01 source, bench02 replica), 4 vCPU and 16 GB RAM each, one 40 GB network SSD per pool, same zone, so the link added well under a millisecond of latency.
  • Dataset: zroot/data with compression=zstd, holding a 2 GiB random file and a 1.6 GiB application log. ZFS stored it in 2.25 GB (ratio 1.60x), so the test mixes incompressible and highly compressible blocks.
  • Timing: /usr/bin/time -p around the whole pipeline, sender to zfs recv exit. Stream sizes come from zfs send -nvP, which prints the exact byte count without sending.
  • Disk ceiling: 3 GiB of random data copied onto the replica pool with compression off, followed by zpool sync, took 23.06 s, which is 139.7 MB/s.

Read the full-send rows against that ceiling. The plain stream moved 3.99 GB but the replica recompressed the logs before writing, so it still finished in 20.5 s. With -c the same logical dataset arrived in 28% less time, because ZFS shipped the zstd blocks as stored and the receiver wrote them without touching them. The AES-GCM cipher cut pipeline user CPU from 4.05-4.08 s to 1.20-1.46 s per run and changed nothing else, and mbuffer bought nothing on a sub-millisecond link. On this hardware we would run zfs send -c over a default SSH session and spend the tuning effort on the disks of the replica.

Full zfs send over SSH on FreeBSD 15 timed four ways: plain stream 20.58 s, compressed -c 14.74 s, AES-GCM cipher 14.55 s, mbuffer 14.82 s

Each method appears once in the capture, taken from the benchmark log. The rates in the table are stream bytes divided by the faster of the two wall times, so a slower run lands a point or two lower. The -c rows sit above the 139.7 MB/s dd figure, so treat that number as a rough single-stream reference for this disk rather than a hard ceiling.

Prerequisites

Two FreeBSD 15 hosts with ZFS and SSH between them are enough. A second pool on the same host also works for practice, but a replica on another box is the only kind that survives losing the first one. The lab used this layout:

  • Source, bench01: root on ZFS (zroot), the dataset to protect, root shell for every command unless the prompt says otherwise.
  • Replica, bench02 at 10.0.1.51: a separate pool named backup on its own disk (da1), and an unprivileged user repl that receives streams.
  • Packages: pv 1.12.0 and mbuffer 20260511 from the FreeBSD package repository, both optional and used only for measuring.

Install the two measuring tools on both hosts if you plan to repeat the benchmark. Key-based SSH is assumed. The SSH key authentication and hardening guide for FreeBSD 15 covers it, and the FreeBSD 15 install on KVM with ZFS gets you a root-on-ZFS host if you do not have one yet:

pkg install -y pv mbuffer

Pool layout is out of scope here. If you are still choosing between mirrors and raidz for the replica, read ZFS pool design on FreeBSD 15 first. The RAIDZ2 drive count guide shows how much usable space a backup pool of a given width gives you.

Step 1: Create the source dataset with an explicit mountpoint

Always pass -o mountpoint= when you create a dataset under zroot, because the official FreeBSD cloud and VM images ship the pool root with mountpoint=none. A host installed with bsdinstall gets /zroot instead and will not hit this, but the explicit option costs nothing on either. Our first attempt used a bare zfs create zroot/data, the dataset inherited none, and 3.6 GiB of test data quietly went into a plain /zroot/data directory on the root filesystem. Nothing errored. The check below is what exposed it:

zfs get -H -o name,property,value mountpoint,mounted zroot zroot/data
df -h /zroot/data

Both datasets report mounted no, and df names the root dataset as the filesystem that actually holds the path.

zroot	mountpoint	none
zroot	mounted	no
zroot/data	mountpoint	none
zroot/data	mounted	no
Filesystem            Size    Used   Avail Capacity  Mounted on
zroot/ROOT/default     33G    7.9G     25G    24%    /

Snapshots of an unmounted dataset are empty, so a backup built on that mistake protects nothing. Create the dataset with compression and a mountpoint set at creation time, since zstd only applies to blocks written after it is set:

zfs create -o compression=zstd -o mountpoint=/data zroot/data
zfs get -H -o name,property,value mountpoint,mounted,compression zroot/data

Now the dataset is mounted where the data will go. Run the same zfs get check after every zfs create in a script, because the unmounted case never returns an error code.

zroot/data	mountpoint	/data
zroot/data	mounted	yes
zroot/data	compression	zstd

After loading the 2 GiB random file and the 1.6 GiB log, zfs list -o name,used,refer,compressratio,logicalused zroot/data reported 2.25G used for 3.61G logical, a 1.60x ratio. The log alone went from 1.6G to 258M on disk, which is the effect zfs send -c keeps on the wire later.

Step 2: Take snapshots and read USED against WRITTEN

A snapshot records the block pointers of the dataset at one transaction group, so its cost does not depend on dataset size. Creating the first one took 0.03 seconds for 2.25 GB. Name snapshots with a sortable timestamp; replication scripts later pick the newest one by creation order, and a clear name makes the replica readable during an incident:

zfs snapshot zroot/data@2026-11-09_base
zfs list -t snapshot -o name,used,refer,creation zroot/data

A fresh snapshot shows 0B used because no block has diverged from the live dataset yet. Space only moves into the snapshot as the live data is overwritten, so a snapshot of a quiet dataset can sit for months at almost no cost.

NAME                         USED  REFER  CREATION
zroot/data@2026-11-09_base     0B  2.25G  Mon Nov  9 19:20 2026

After rewriting 256 MiB of the random file, appending a million log lines and taking two more snapshots, the written column becomes the useful one. used counts blocks only that snapshot still holds, while written counts what changed since the previous snapshot, which is roughly what the next incremental stream will carry:

zfs list -t snapshot -o name,used,refer,written zroot/data

The 273M written by @2026-11-10_0100 is 273 MiB, or 286 million bytes. That is the same figure the incremental estimate prints in Step 5, so written doubles as a free size forecast:

NAME                         USED  REFER  WRITTEN
zroot/data@2026-11-09_base   256M  2.25G    2.25G
zroot/data@2026-11-10_0100    56K  2.27G     273M
zroot/data@2026-11-10_0200     0B  2.27G      64K

To delete a run of snapshots, use the % range syntax rather than -r. In this lab zfs destroy zroot/data@2026-11-09_base%2026-11-10_0100 removed both snapshots in that range and nothing else. zfs destroy -r dataset@snap does something different: it destroys the snapshot of that name on every child dataset, which is easy to confuse in a hurry.

Step 3: Prepare the replica pool and a delegated receive user

Receive as an unprivileged user with zfs allow, not as root over SSH. A root key on the sender that can log in as root on the replica turns one compromised host into two. On bench02, create the pool, a read-only parent for everything from bench01, the user, and its permission set:

zpool create -o ashift=12 backup da1
zfs create -o readonly=on -o canmount=off backup/bench01
pw useradd repl -m -s /bin/sh -c "ZFS replication"
zfs allow -u repl create,mount,receive,hold,send,userprop,compression,readonly,canmount,mountpoint,encryption,keyformat,keylocation backup/bench01

Confirm the delegation landed on the parent and will apply to every dataset received under it:

zfs allow backup/bench01

Permissions print sorted, and destroy is deliberately absent. The set is Local+Descendent, so it applies to datasets that do not exist yet, which is what lets repl create them on the first receive.

---- Permissions on backup/bench01 -----------------------------------
Local+Descendent permissions:
	user repl canmount,compression,create,encryption,hold,keyformat,keylocation,mount,mountpoint,readonly,receive,send,userprop

Two settings here do real work. readonly=on on the parent is inherited by every received dataset, so nobody can write to the replica through its mountpoint, which prevents the “destination has been modified” error in the troubleshooting section. Leaving out destroy means a forced receive cannot prune history on the replica, a guard rail Step 9 measures. send is in the list because the disaster restore in Step 11 pulls data back through the same user.

Next, give root on bench01 a key for that user. Generate it on the source and print the public half:

ssh-keygen -t ed25519 -N "" -f /root/.ssh/id_ed25519 -C root@bench01
cat /root/.ssh/id_ed25519.pub
echo "10.0.1.51 bench02" >> /etc/hosts

On bench02, put that public key into authorized_keys for the replication user and lock the permissions down, replacing the key text with the line printed above:

mkdir -p /home/repl/.ssh
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyOnly root@bench01" >> /home/repl/.ssh/authorized_keys
chown -R repl:repl /home/repl/.ssh
chmod 700 /home/repl/.ssh
chmod 600 /home/repl/.ssh/authorized_keys

Back on bench01, log in once by name so known_hosts for root records the host key. Our first pipeline failed with Host key verification failed. because the key had been accepted under the IP address and not under bench02:

ssh -o StrictHostKeyChecking=accept-new repl@bench02 zfs list -r backup

A listing that comes back as repl proves both the key and the delegated read access. If it prompts for a password instead, the key line or the permissions on /home/repl/.ssh are wrong, and no zfs command will get past that.

NAME             USED  AVAIL  REFER  MOUNTPOINT
backup           552K  38.3G    96K  /backup
backup/bench01    96K  38.3G    96K  /backup/bench01

Both datasets are empty at 96K, and backup/bench01 shows a mountpoint even though canmount=off keeps it from ever being mounted. That parent exists only to carry the permissions and the read-only flag down to whatever arrives under it.

Step 4: Run the first full send with zfs recv -u

The first replication is a full stream of one snapshot, and with a delegated receiver it needs -u so ZFS does not try to mount the new dataset. Check the size first. -nvP is a dry run with byte counts, and comparing it with and without -c shows what compression saves on the wire:

zfs send -nvP zroot/data@2026-11-09_base
zfs send -nvP -c zroot/data@2026-11-09_base

Plain, the stream is 3.88 GB; compressed, it is 2.42 GB, a 37.5% cut for this mix of data. Random data gains nothing from -c, so the whole saving comes from the log file, and a dataset of logs or database dumps would save far more.

full	zroot/data@2026-11-09_base	3880627784
size	3880627784
full	zroot/data@2026-11-09_base	2424036936
size	2424036936

Send it next. pv in the middle is optional and only reports the rate.

zfs send -c zroot/data@2026-11-09_base | pv | ssh repl@bench02 zfs recv -u backup/bench01/data

Our first run of this pipeline left out -u. The 2.26 GiB arrived in 8 seconds at 273 MiB/s, then the receive ended with cannot mount '/backup/bench01/data': failed to create mountpoint: Permission denied, because a non-root user cannot create directories under /backup. The data was intact; only the mount failed. A replica does not need to be mounted, so -u on every receive is the clean fix, and the troubleshooting section covers the alternative.

Check what arrived on bench02, including two properties that tell you how the stream was built:

zfs list -t all -o name,used,refer,mounted,readonly -r backup/bench01
zfs get -H -o property,value,source compression,readonly backup/bench01/data

The snapshot is there at 2.25G, read-only through inheritance. Compression reads on default instead of zstd:

NAME                                  USED  REFER  MOUNTED  RDONLY
backup/bench01                       2.25G    96K  no       on
backup/bench01/data                  2.25G  2.25G  no       on
backup/bench01/data@2026-11-09_base     0B  2.25G  -        -
compression	on	default
readonly	on	inherited from backup/bench01

A plain zfs send carries data, not properties. The blocks stayed zstd-compressed because -c shipped them as stored, but new writes on that dataset would use the replica default (lz4). Add -p, or use -R as Step 9 and Step 11 do, when the replica must be a drop-in copy with the same settings.

Step 5: Send increments with -i and -I

An incremental stream carries only the blocks that differ between two snapshots, and the replica must already hold the older one. Every snapshot name from here on is a label from one continuous lab session, in which the troubleshooting errors and the -F test from Step 9 ran between the steps, so substitute the names of your own snapshots. -i sends the difference between exactly two snapshots. -I sends every snapshot in between as well, which is what you want after a missed run so the replica keeps the same history as the source:

zfs send -nvP -c -i @2026-11-09_base zroot/data@2026-11-10_0100
zfs send -nvP -c -I @2026-11-09_base zroot/data@2026-11-10_0200
zfs send -c -I @2026-11-09_base zroot/data@2026-11-10_0200 | ssh repl@bench02 zfs recv -u backup/bench01/data

Both snapshots crossed in 2.69 seconds of wall time. The -I estimate lists each hop separately, so a run that missed several snapshots shows exactly what it will carry.

zfs send -nvP estimates for incremental -i and -I streams on FreeBSD 15 showing a 286 MB increment and a 33 KB config change

The first hop is 286,144,256 bytes, 11.8% of the full compressed stream and 7.4% of the plain one. The second hop, one changed line in /data/app.conf, is 33,392 bytes, nearly all of it stream metadata. That ratio is why hourly replication of a mostly static dataset costs almost nothing: the price of a run follows the churn, not the size of the dataset.

Step 6: Resume an interrupted send with receive_resume_token

Use zfs recv -s for any stream that takes more than a few seconds, because it keeps the partial receive and gives you a token to continue from. Without -s an interrupted receive is discarded, and we confirmed that the hard way when an incremental of a runaway 17.9 GB dataset was killed and left nothing behind on the replica. To test resume on purpose, we sent a 3.23 GB snapshot of incompressible data through pv capped at 50 MB/s and cut the pipeline after 15 seconds:

timeout 15 sh -c 'zfs send zroot/images@2026-11-10_0800 | pv -q -L 50m | ssh repl@bench02 zfs recv -u -s backup/bench01/images'

The replica now holds a token in the receive_resume_token property. Feeding it to zfs send -nvP -t decodes it and prints what is left to send, then zfs send -t continues the stream:

TOKEN=$(ssh repl@bench02 zfs get -H -o value receive_resume_token backup/bench01/images)
zfs send -nvP -t "$TOKEN"
zfs send -t "$TOKEN" | ssh repl@bench02 zfs recv -u -s backup/bench01/images

Our full session, including a failed first attempt, is in the capture below. Read the token contents before resuming, because toname tells you which source snapshot must still exist.

Interrupted zfs send resumed with receive_resume_token on FreeBSD 15, token contents and the 15.51 second resume

The token records bytes = 0x2f2ebaf8, 791.6 MB already received, and the resumed stream is 2,435,286,840 bytes, so ZFS skipped 24.5% of the work. Our first resume attempt failed with “contains partially-complete state” because the zfs recv from the killed pipeline on the replica had not exited yet: USED kept climbing from 564M to 685M after the kill. Once pgrep showed no receive running, the same command finished in 15.51 seconds at 157 MB/s and the token property went back to -.

Keep the source snapshot alive until the resume completes. The token names the snapshot by GUID (toguid), and a rotation job that deletes it in the meantime makes the token useless; Step 8 shows how a hold prevents that.

Step 7: Replicate encrypted datasets with a raw send

A raw send (zfs send -w) ships the blocks of an encrypted dataset still encrypted, so the replica stores the data without ever holding the key. That makes an offsite box or a rented server a safe target. The source dataset uses a 32-byte raw key file:

openssl rand -out /root/secure.key 32 && chmod 600 /root/secure.key
zfs create -o encryption=aes-256-gcm -o keyformat=raw -o keylocation=file:///root/secure.key -o compression=zstd -o mountpoint=/secure zroot/secure

We copied the 1.6 GiB log into it as customers.csv, snapshotted, sent raw, then sent a second increment the wrong way and the right way:

zfs send -w zroot/secure@2026-11-10_0900 | ssh repl@bench02 zfs recv -u backup/bench01/secure
ssh repl@bench02 zfs get -H -o property,value encryption,keystatus,keylocation,encryptionroot backup/bench01/secure

On the replica, keystatus reads unavailable, which is the point of a raw send. Anyone with root on bench02 can list, send and destroy the dataset, but cannot read a byte of it.

Raw encrypted zfs send -w on FreeBSD 15 with keystatus unavailable on the replica and the inherited key must be loaded error

Raw streams also keep compression, because ZFS compresses before it encrypts: 1.73 GB of logical data at a 6.38x ratio crossed as a 290 MB stream in 2.02 seconds. The capture also shows the mistake to expect. Forgetting -w on the next increment produced cannot receive incremental stream: inherited key must be loaded, because a non-raw stream is plaintext and the replica would need the key to write it into the encrypted dataset. Once a dataset is replicated raw, every later send must be raw too.

The key file is now the single point of failure. It never leaves bench01 in this design, so store a copy somewhere that does not share the fate of the source host, or the replica becomes 290 MB of noise.

Step 8: Protect the replication chain with holds and bookmarks

A hold blocks deletion of the snapshot an incremental chain depends on, and a bookmark keeps that chain usable after the snapshot is gone. Place a hold with a tag of your choosing and try to delete the snapshot:

zfs hold replica-sync zroot/data@2026-11-10_0700
zfs holds zroot/data@2026-11-10_0700
zfs destroy zroot/data@2026-11-10_0700

ZFS refuses the destroy until the tag is released with zfs release replica-sync zroot/data@2026-11-10_0700:

NAME                        TAG           TIMESTAMP
zroot/data@2026-11-10_0700  replica-sync  Mon Nov  9 19:38 2026
cannot destroy snapshot zroot/data@2026-11-10_0700: it's being held. Run 'zfs holds -r zroot/data@2026-11-10_0700' to see holders.

A bookmark (# instead of @) stores only the transaction group and GUID, with no data blocks. The source can delete its snapshot to free space and still send increments from the bookmark, as long as the replica still has the matching snapshot:

zfs bookmark zroot/data@2026-11-10_0700 zroot/data#2026-11-10_0700
zfs snapshot zroot/data@2026-11-10_1100
zfs destroy zroot/data@2026-11-10_0700
zfs send -c -i zroot/data#2026-11-10_0700 zroot/data@2026-11-10_1100 | ssh repl@bench02 zfs recv -u backup/bench01/data

Listing needs -r: zfs list -t bookmark,snapshot zroot/data without it returned “operation not applicable to datasets of this type”, because the filesystem itself is neither a snapshot nor a bookmark. With -r, the bookmark lists with no USED value at all:

zfs list -t bookmark,snapshot -o name,used,refer -r zroot/data

The increment from the bookmark was a 29,296-byte stream and arrived as backup/bench01/data@2026-11-10_1100 on the replica:

NAME                         USED  REFER
zroot/data@2026-11-10_0200    56K  2.27G
zroot/data@2026-11-10_0300    56K  2.27G
zroot/data@2026-11-10_0400    56K  2.27G
zroot/data@2026-11-10_0500    56K  2.27G
zroot/data@2026-11-10_0600    56K  2.27G
zroot/data@2026-11-10_1100     0B  2.27G
zroot/data#2026-11-10_0700      -  2.27G

Use holds on the newest snapshot the replica has confirmed, and bookmarks when the source is short on space and keeps fewer snapshots than the replica. The script in Step 10 applies the hold automatically.

Step 9: Roll back, clone, and avoid the recv -F trap

Rollback is the fastest restore ZFS has, and it refuses to run when newer snapshots exist unless you pass -r. We needed it for real early in this lab, right after the first full send in Step 4: a log append that read and wrote the same file looped and grew /data to 17.9G before we killed it. Rolling back to the base snapshot was the fix, and the increments shown in Step 2 and Step 5 were taken again afterwards:

zfs rollback zroot/data@2026-11-09_base

Instead of guessing, ZFS lists what a forced rollback would delete. Read that list carefully, since every snapshot on it is gone for good once you add the flag.

cannot rollback to 'zroot/data@2026-11-09_base': more recent snapshots or bookmarks exist
use '-r' to force deletion of the following snapshots and bookmarks:
zroot/data@2026-11-10_0100
zroot/data@2026-11-10_0200

Add -r once you have read that list and agree to lose those snapshots:

zfs rollback -r zroot/data@2026-11-09_base

The forced rollback discarded about 15.6G of runaway writes and both newer snapshots in 0.62 seconds, and the log was back at its original 1,726,247,239 bytes. Rollback only moves backwards, so take a fresh snapshot first if any of the newer data might matter.

When you need the old data next to the current data, a clone is the better tool: a writable dataset that shares every unchanged block with its origin snapshot. Test an upgrade on it, compare configs, then throw it away:

zfs clone -o mountpoint=/data-test zroot/data@2026-11-10_1100 zroot/data-test
zfs list -o name,used,refer,origin zroot/data zroot/data-test
zfs destroy zroot/data@2026-11-10_1100

A fresh clone references the full 2.27G while using nothing of its own. Its origin snapshot cannot be deleted while it exists, so a forgotten test clone quietly blocks retention:

NAME              USED  REFER  ORIGIN
zroot/data       2.27G  2.27G  -
zroot/data-test     0B  2.27G  zroot/data@2026-11-10_1100
cannot destroy 'zroot/data@2026-11-10_1100': snapshot has dependent clones
use '-R' to destroy the following datasets:
zroot/data-test

Destroy the clone when you are done. If the clone turns out to be the version worth keeping, zfs promote zroot/data-test swaps the dependency: in our test the origin of zroot/data became zroot/data-test@2026-11-09_1946, and promoting zroot/data again swapped it back.

The trap is on the receiving side. zfs recv -F combined with a -R stream makes the replica match the source exactly, which includes destroying replica snapshots the source has already pruned. We pruned the two oldest snapshots on bench01, then sent the next increment with -R -F twice: once with the permission set from Step 3, and once after granting destroy to repl:

zfs send -R -c -I @2026-11-10_0600 zroot/data@2026-11-10_0700 | ssh repl@bench02 zfs recv -u -F -x mountpoint backup/bench01/data

Without destroy the replica silently kept all its snapshots and printed nothing. With it, the two oldest disappeared from the replica, also without a word:

zfs recv -F with a -R stream on FreeBSD 15: replica snapshots unchanged without destroy permission, two oldest deleted once destroy is delegated

A replica usually keeps a longer history than the source, so -F in a scheduled job can erase exactly the restore points you kept it for. A second surprise came with -R: the first such stream set mountpoint=/data on the replica dataset as a received property, which would mount the backup over /data on bench02 itself at the next boot. -x mountpoint on the receive drops it, as the last line of the capture shows. Three rules came out of those two runs, and the cron job in Step 10 follows all of them.

  • No -F in automation: a forced receive rolls back local changes and, with -R, prunes history without printing anything, so keep it for hand-run repairs.
  • No destroy for the receive user: without it a -R -F stream left all six old snapshots in place, which turns a silent loss into a harmless no-op.
  • -x mountpoint on every -R receive: the received property otherwise points the replica at the source path and mounts it there on the next boot.

Pruning on the replica then becomes its own job, run as root on bench02, where a compromised source host cannot reach it.

Step 10: Automate snapshot, send and retention with cron

A replication job needs four actions in order: snapshot, hold, incremental send, prune. The old trick for pruning, head -n -7 to drop all but the last seven lines, is GNU-only and fails on FreeBSD:

zfs list -H -t snapshot -o name zroot/data | head -n -7

FreeBSD head rejects the negative count outright. A cron job built on that pipe would fail on every run and leave snapshots piling up until the pool filled.

head: illegal line count -- -7

The script below counts snapshots and passes a positive number instead. It also asks the replica for its newest snapshot and uses that as the base of an -I stream, rather than trusting the newest snapshot on the source. Create it on bench01:

vi /usr/local/sbin/zfs-replicate.sh

Add the following, adjusting the four variables at the top for your dataset, target and retention:

#!/bin/sh
# Snapshot zroot/data, send everything newer than the replica's last snapshot, keep the newest 7 local snapshots.
set -eu
DS=zroot/data
DEST=backup/bench01/data
REMOTE=repl@bench02
KEEP=7
NOW=$(date +%Y-%m-%d_%H%M%S)
LAST=$(ssh -o BatchMode=yes "$REMOTE" zfs list -H -o name -t snapshot -s createtxg "$DEST" | tail -n 1)
if [ -z "$LAST" ]; then
  logger -t zfs-replicate "cannot read the last snapshot of $REMOTE:$DEST, nothing sent"
  exit 1
fi
BASE="$DS@${LAST#*@}"
zfs snapshot "$DS@$NOW"
zfs send -c -I "$BASE" "$DS@$NOW" | ssh -o BatchMode=yes "$REMOTE" zfs recv -u "$DEST"
zfs hold replica-sync "$DS@$NOW"
zfs release replica-sync "$BASE" 2>/dev/null || true
COUNT=$(zfs list -H -t snapshot -o name "$DS" | wc -l)
if [ "$COUNT" -gt "$KEEP" ]; then
  zfs list -H -t snapshot -o name -s createtxg "$DS" | head -n $((COUNT - KEEP)) | xargs -n 1 zfs destroy
fi
logger -t zfs-replicate "sent $BASE..$NOW to $REMOTE:$DEST"

Taking the base from the replica is what keeps the job alive after a bad run. Our first version of this script used the newest local snapshot as the base, so one failed send would leave a snapshot that never reached bench02, and every later run would fail on “does not match incremental source”. With the base read from the replica, -I carries every snapshot the replica is missing, including manual ones, and the hold only moves to a snapshot once the receive has succeeded. If the replica cannot be reached at all, the script logs it and exits before taking a snapshot.

We broke the job twice on purpose to prove that. First we removed the receive permission from repl on bench02 and took a manual snapshot after the failed run; then we moved the SSH key away. After restoring both, one ordinary run brought the replica up to date:

zfs-replicate.sh on FreeBSD 15 failing on a refused receive and a removed SSH key, then catching up with every missed snapshot

Both failures print an error and exit with status 1, and under cron that output is mailed to root. A failed receive never reaches the logger line, so that mail is the only signal for it. The catch-up run sent @2026-11-09_200808..2026-11-09_200821 in one stream, and the replica ended up holding the orphaned _200820 snapshot and manual-before-upgrade as well. Nothing needed a full resend.

Make it executable, run it once by hand, then schedule it. FreeBSD cron reads both /etc/cron.d and /usr/local/etc/cron.d; the second is meant for packages and did not exist on our 15.1 host, so the job goes in the first:

chmod 755 /usr/local/sbin/zfs-replicate.sh
/usr/local/sbin/zfs-replicate.sh
echo '*/15 * * * * root /usr/local/sbin/zfs-replicate.sh' > /etc/cron.d/zfs-replicate

After the 20:15 run fired from cron, the log, the local list and the replica list looked like this:

Cron run of zfs-replicate.sh at 20:15 on FreeBSD 15 with seven local snapshots kept and ten on the replica

The source holds exactly seven snapshots because the cron run pruned @2026-11-09_200808, while the replica has ten, since nothing in the job deletes there. That asymmetry is what you want: short retention where disk is expensive, long retention on the backup pool. Local pruning also removes manual snapshots once they age out; the replica keeps them, so restore a long-lived snapshot from there rather than holding it on the source, where a held snapshot would make the prune step fail. Prune the replica with a separate job on bench02, run as root, so a compromised source cannot shorten the backup history.

Step 11: Run a timed disaster-recovery restore

Restoring the full dataset from bench02 took 19.66 seconds for 2.44 GB, and the checksums matched. We removed the cron file, recorded SHA-256 sums of the random file and the config, destroyed zroot/data and zroot/secure, and pulled both back through the same repl account. The first destroy failed on the hold the replication script had placed on its newest snapshot, which is the hold doing its job. The snapshot names below are from our lab; use the newest one your replica holds, which zfs list -H -o name -t snapshot -s createtxg backup/bench01/data | tail -n 1 on bench02 prints:

sha256 -q /data/blobs/random.bin /data/app.conf | tee /root/before.sha256
zfs release replica-sync zroot/data@2026-11-09_1945
zfs destroy -r zroot/data
zfs destroy -r zroot/secure

Restore with a -R stream from the replica, so all snapshots and the received properties come back. The mountpoint has to be set on the receive, because Step 9 stripped it from the replica:

ssh repl@bench02 zfs send -R -c backup/bench01/data@2026-11-09_1945 | zfs recv -o mountpoint=/data zroot/data
sha256 -q /data/blobs/random.bin /data/app.conf | diff - /root/before.sha256 && echo checksums-match

Our timed run shows the restored snapshot list, the received zstd property and the checksum comparison. Compare checksums of real files after any restore drill, because a dataset that mounts is not proof that its contents are right.

Timed ZFS disaster recovery on FreeBSD 15: 2.44 GB restored from the replica in 19.66 seconds with matching SHA-256 checksums

At 124 MB/s the restore ran slower than the forward sends because bench01‘s pool was now the writer, on the same class of disk. Recovery time scales with stream size, and this lab restores about 7.4 GB per minute. A 1 TB dataset would need a little over two hours on these disks, which is the number to put in a runbook.

The encrypted dataset came back raw in 2.57 seconds and arrived locked, with keylocation=prompt inherited from the replica. Point it back at the key file and load it:

ssh repl@bench02 zfs send -w -R backup/bench01/secure@2026-11-10_1000 | zfs recv -o mountpoint=/secure zroot/secure
zfs set keylocation=file:///root/secure.key zroot/secure
zfs load-key zroot/secure && zfs mount zroot/secure
tail -n 1 /secure/customers.csv

Its last line is the row added before the second raw increment, so both snapshots survived the round trip.

row 16000001

Replication then picked up without a new full send. After one more config change, the next replication run (the first version of the script, which used the newest local snapshot as its base) sent zroot/data@2026-11-09_1946 as an increment on top of @2026-11-09_1945, the snapshot both sides shared after the restore. A drill that ends with the next scheduled run succeeding is the proof that matters; run one before you need it.

Step 12: Scrub both pools on a schedule

Replication copies blocks faithfully, including blocks that have rotted, so scrub the source and the replica. The FreeBSD periodic system has a built-in job that is off by default; the knob is daily_scrub_zfs_enable, and it scrubs each pool once its last scrub is older than daily_scrub_zfs_default_threshold, 35 days by default. Enable it on both hosts:

echo 'daily_scrub_zfs_enable="YES"' >> /etc/periodic.conf
zpool scrub -w zroot
zpool status zroot

With -w the command waits for the scrub to finish, which took 1 minute 40 seconds on the source pool. Scrub time grows with allocated data rather than pool size, so expect hours on a multi-terabyte replica and schedule it away from the replication window.

  pool: zroot
 state: ONLINE
  scan: scrub repaired 0B in 00:01:40 with 0 errors on Mon Nov  9 19:40:50 2026
config:

	NAME        STATE     READ WRITE CKSUM
	zroot       ONLINE       0     0     0
	  da0p4     ONLINE       0     0     0

errors: No known data errors

A scrub verifies data at rest, but it says nothing about whether replication is keeping up. Three figures from this lab are the ones we would graph on any replicated pair, because each one moves before a restore goes wrong.

  • Age of the newest replica snapshot: this is the real recovery point. With a 15 minute cron job it should never exceed about 30 minutes; anything older means the job is failing quietly.
  • written on each new source snapshot: it matched the 286 MB increment within rounding, so it is the best early warning for a send that will overrun its slot. The runaway log in Step 9 grew the dataset by about 15.6G in minutes, which is the kind of jump this figure exposes.
  • Restore rate: 124 MB/s here, which turns into the recovery time objective you can promise. Repeat the drill after any disk or network change, since the replica disk set every number in the results table.

Those three are cheap to collect with zfs list -p and a timestamp, and they catch the failure modes this lab produced before a real restore depends on them.

Troubleshooting zfs send and zfs receive errors

Every error below was produced in the two-host lab with the commands shown. Three of them came from one session against the replica:

zfs receive errors on FreeBSD 15: destination exists, most recent snapshot does not match incremental source, destination has been modified

Each heading below quotes one message so you can match it to your own terminal, followed by the cause we confirmed and the fix that worked.

cannot receive new filesystem stream: destination ‘backup/bench01/data’ exists

A full stream was sent to a dataset that already exists, usually because a script fell back to a full send after losing track of the last common snapshot. ZFS adds “must specify -F to overwrite it”. Do not add -F reflexively: check what the replica holds with ssh repl@bench02 zfs list -t snapshot backup/bench01/data and send an incremental from the newest snapshot both sides share. Overwrite with -F only when you have decided the history on the replica is disposable.

cannot receive incremental stream: most recent snapshot of backup/bench01/data does not match incremental source

The -i base is not the newest snapshot on the replica. In the lab the replica was at @2026-11-10_0200 and we sent -i @2026-11-10_0300. Ask the replica for its newest snapshot by creation order, then send from that one with -I so the skipped snapshots come along:

ssh repl@bench02 zfs list -H -o name -t snapshot -s createtxg backup/bench01/data | tail -1
zfs send -c -I @2026-11-10_0200 zroot/data@2026-11-10_0400 | ssh repl@bench02 zfs recv -u backup/bench01/data

If the source no longer has that snapshot and you made no bookmark of it, no incremental path exists and the only route is a new full send to a new dataset name.

cannot receive incremental stream: destination backup/bench01/data has been modified since most recent snapshot

Something wrote to the replica dataset after its last received snapshot. We reproduced it by setting readonly=off on the replica, mounting it and creating one file. zfs recv -F fixes it by rolling the replica back before applying the increment; our test file vanished without any message. The lasting fix is to keep the replica read-only so it cannot happen, which readonly=on on the parent in Step 3 already does:

zfs inherit readonly backup/bench01/data
zfs get -H readonly backup/bench01/data

Expect on with the source inherited from backup/bench01. A replica that somebody needs to inspect should be cloned or mounted read-only, never opened for writes, because one stray file blocks every later increment.

cannot mount ‘/backup/bench01/data’: failed to create mountpoint: Permission denied

A delegated user received a full stream without -u. The dataset and its data arrived; only the mount failed, because a non-root user cannot create the mountpoint directory. Add -u to every receive. If the replica must be browsable, mount it as root with zfs mount backup/bench01/data, which keeps the rights of the receive user narrow.

cannot receive resume stream: destination contains partially-complete state from “zfs receive -s”

We hit this when resuming seconds after killing the sender: the old zfs recv on the replica was still draining its buffer. Wait until ssh repl@bench02 pgrep -lf "zfs recv" returns nothing, read the token again, and resume. To abandon a partial receive instead, run zfs recv -A backup/bench01/images as root on the replica. The same command run as repl failed with cannot destroy 'backup/bench01/images': permission denied, because discarding the saved state is a destroy and the Step 3 permission set leaves that out on purpose.

cannot receive incremental stream: inherited key must be loaded

A non-raw incremental was sent to a replica that received the dataset raw. Repeat the send with -w, as in Step 7. Loading the key on the replica would also make the error go away, but it defeats the reason for a raw replica.

Host key verification failed. warning: cannot send: signal received

The SSH leg of the pipeline failed before zfs recv started, and zfs send died on the broken pipe. The known_hosts file for root had the replica under its IP address while the command used the name bench02. Connect once interactively with the exact name the script uses, and keep -o BatchMode=yes in scripts so a prompt can never hang a cron run.

The OpenZFS zfs-send manual documents every send flag used here, and the FreeBSD Handbook ZFS chapter covers delegation and pool administration in more depth. Two services in this series are obvious next datasets to replicate: the mailbox directory from the Postfix and Dovecot mail server on FreeBSD 15, and the guest disks from bhyve Linux VMs on FreeBSD 15.

Keep reading

Run Linux VMs on FreeBSD 15 with bhyve FreeBSD Run Linux VMs on FreeBSD 15 with bhyve Install Python 3 and pip on FreeBSD 15 FreeBSD Install Python 3 and pip on FreeBSD 15 How To Install and Configure OPNSense Firewall FreeBSD How To Install and Configure OPNSense Firewall Install Postfix + Dovecot Mail Server on FreeBSD 15 FreeBSD Install Postfix + Dovecot Mail Server on FreeBSD 15 Best FreeBSD Books for 2026: Absolute FreeBSD to FreeBSD Mastery Books Best FreeBSD Books for 2026: Absolute FreeBSD to FreeBSD Mastery Install Podman and run Containers in FreeBSD 14 Containers Install Podman and run Containers in FreeBSD 14

Leave a Comment

Press ESC to close