ZFS incremental replication: protect the baseline and test recovery

ZFS incremental replication: protect the baseline and test recovery

ZFS incremental replication: protect the baseline and test recovery

An overnight replication job finishes successfully, but when you try to recover the data, the shared snapshot has already been deleted—or another task has written to the receiving dataset, preventing the next incremental transfer. Accepting a backup target requires more than confirming that a transfer completed: the baseline must be traceable, the target must be protected against accidental writes, and the files must be readable independently. The following drill uses dedicated ZFS test datasets to work through the entire process without changing the layout of any production pool.

1. Define the test scope and recovery goals

This example assumes a working ZFS environment on Ubuntu 24.04, with commands run in Bash with administrator privileges. First confirm that zfsutils-linux is installed and the kernel module is available, then check the pools:

zfs version
zpool status -x
zpool list
zfs list -o name,mountpoint,used,available

The example assumes two existing, healthy pools, tank and vault, for sending and receiving respectively; replace these names to match your environment. The receiving dataset vault/replica-demo must not already exist, and /srv/replica-demo and /mnt/replica-verify must be unused. Allow enough space for the received data, retained snapshots, and subsequent changes—not just the current size of the source directory.

Qsfp dedicated servers come with two directly attached 1TB NVMe drives and no hardware RAID. This does not mean that a ZFS pool or mirror has already been configured. This guide does not create pools either, to avoid accidentally selecting a system drive. Two pools on the same machine are useful for testing commands, but they do not constitute an off-site backup. A real backup copy must also reside in a separate failure domain.

A snapshot captures a filesystem at a point in time; it does not automatically guarantee database transaction consistency. For a running database, first perform an application-supported backup or coordinate consistency, then create the snapshot used for replication.

2. Create a full baseline and protect the shared snapshot

Start by creating a dedicated test dataset and a small file. The mountpoint is set explicitly so that inherited properties cannot direct the test data to an unexpected location. Before running the commands, confirm again that a dataset with the same name does not exist.

set -euo pipefail
umask 077
zfs create -o mountpoint=/srv/replica-demo tank/replica-demo
printf 'replication baseline\n' > /srv/replica-demo/payload.txt
zfs snapshot tank/replica-demo@base
zfs hold replication tank/replica-demo@base

zfs send tank/replica-demo@base |
  zfs receive -u -o readonly=on -o mountpoint=none vault/replica-demo

-u prevents automatic mounting after reception, mountpoint=none keeps the receiving dataset from appearing at an application path, and readonly=on restricts ordinary file writes. These properties do not stop an administrator from destroying the dataset, nor do they make the storage immutable.

A hold prevents the protected source snapshot from being destroyed directly. It helps guard against cleanup jobs accidentally deleting the baseline, but an ordinary send stream does not automatically carry that protection over to the receiver. Record the hold tag and the conditions for releasing it; holds must not accumulate indefinitely. With pipefail enabled, a send failure will not be hidden by the receiving process's exit status.

Query the snapshot GUID on each side:

zfs get -H -o value guid tank/replica-demo@base
zfs get -H -o value guid vault/replica-demo@base
zfs holds tank/replica-demo@base

The GUIDs must match. Snapshots with the same name can represent different points in time, so matching names alone do not establish a shared baseline. Also check the receiver's read-only and mountpoint properties; a command producing no output is not a substitute for verification.

3. Send an incremental update and detect target divergence

Append a line to the file, then create a new snapshot. The test data is no longer changing when the checksum manifest is generated. In production, generate the manifest from a consistent snapshot or a controlled read-only view to avoid checksumming different content from the content being sent.

printf 'incremental update\n' >> /srv/replica-demo/payload.txt
zfs snapshot tank/replica-demo@next
(
  cd /srv/replica-demo
  sha256sum payload.txt
) > /root/replica-demo.sha256

zfs send -nP -i tank/replica-demo@base tank/replica-demo@next
zfs send -i tank/replica-demo@base tank/replica-demo@next |
  zfs receive -u vault/replica-demo

zfs get -H -o value guid tank/replica-demo@next
zfs get -H -o value guid vault/replica-demo@next

The dry run checks the incremental relationship and estimates the stream size. It is not a bandwidth test and does not guarantee that the receiver will accept the stream. After the actual receive operation, compare the new snapshot GUIDs and retain the pipeline's exit status and error output.

If an error reports that the destination has changed since the last snapshot, stop automatic retries first. Check whether the receiving dataset was mounted and written to, whether additional snapshots exist, and whether both sides are using the same baseline. Do not simply add -F: a forced rollback can discard changes on the target. If you cannot establish the scope of the impact, preserving the current state and receiving into a new dataset is safer than overwriting unknown data.

4. Clone the received snapshot and verify the files

An intact replication chain does not prove that application files are usable. Create a read-only clone from the received snapshot to keep the recovery test separate from the dataset that continues to receive updates. The clone depends on its original snapshot and must not be treated as another independent backup.

zfs clone -o readonly=on \
  -o mountpoint=/mnt/replica-verify \
  vault/replica-demo@next vault/verify-demo

findmnt -T /mnt/replica-verify
zfs get readonly,mountpoint vault/verify-demo
(
  cd /mnt/replica-verify
  sha256sum -c /root/replica-demo.sha256
)

Confirm that the mounted filesystem really comes from vault/verify-demo before accepting the checksum result. The test should report a successful file checksum check; also read the file and confirm that the appended line is present. The checksum manifest uses relative paths to avoid a false success caused by accidentally reading the source files.

For real backups, also check file counts, permissions, directory structure, and application recovery results. File hashes establish only that the selected files contain identical bytes; they do not replace checks that a database starts or that application queries work. If you use encrypted datasets, separately verify that the keys are available and can unlock the data. This example does not cover encrypted sends.

5. Advance the retention boundary only after verification

Move the shared baseline to next only after the new snapshot GUIDs match, the restored files pass checksum verification, and the application checks are complete. Protect the new baseline before releasing the old hold tag—never reverse this order:

zfs hold replication tank/replica-demo@next
zfs release replication tank/replica-demo@base
zfs list -t snapshot -o name,used,creation -s creation

Releasing a hold tag does not delete a snapshot. Deleting old snapshots must satisfy both recovery retention requirements and replication dependencies. Assess the sender and receiver separately rather than automatically deleting the same snapshots on both sides. Once the recovery clone is no longer needed, remove it by its explicit name; otherwise, it will continue to reference the snapshot and retain changed blocks.

At a minimum, the final record must include the source and target datasets, the shared snapshot GUID, the send method, exit status, checksum manifest, and recovery conclusion. For replication between machines, also verify the SSH host identity and apply least-privilege access rather than granting the transfer account full pool-management permissions. Reliable incremental backups let you identify the baseline from the records and actually recover data from the receiver—not merely point to a log entry saying that the job succeeded.

Frequently asked questions

Why must ZFS incremental replication retain a shared snapshot?

An incremental stream requires a baseline shared by the sender and receiver. Matching names are not enough: compare snapshot GUIDs and protect the baseline until the next transfer and recovery checks pass.

Should a changed destination be fixed with a forced rollback?

Not automatically. Inspect the snapshot chain and additional writes, preserve any required data, or receive into a new dataset. A forced rollback can discard destination-side data.

Qsfp AMD EPYC 7543P dedicated server from $470.9/month

Use these requirements to configure a server

Review memory, storage, bandwidth, IPs, and OS, then confirm the dedicated server configuration.