Btrfs send and receive: Replicating Snapshots Off the Machine

Btrfs send and receive: Replicating Snapshots Off the Machine

Snapshots give you a rollback point in milliseconds. They do not give you a backup, because they share blocks with the original on the same filesystem. send and receive are how a snapshot leaves the machine.

Why not rsync

rsync works and is the right tool across different filesystems. On Btrfs to Btrfs it is doing unnecessary work.

rsync must compare. It walks both trees, stats everything, and works out what differs. That cost is proportional to the number of files, not to how much changed. A million-file filesystem with one modified file still takes a full scan on both ends.

Btrfs already knows. Two snapshots have a known block-level relationship, so the filesystem can produce the difference directly. No scanning, no comparison.

The practical difference on a large filesystem with few changes is minutes versus hours.

A full send

# snapshots must be read-only to send
sudo btrfs subvolume snapshot -r /data /data/.snapshots/2026-11-23
sudo sync

# to another filesystem
sudo btrfs send /data/.snapshots/2026-11-23 \
  | sudo btrfs receive /mnt/backup/

# over ssh
sudo btrfs send /data/.snapshots/2026-11-23 \
  | ssh backup-host 'sudo btrfs receive /mnt/backup/'

# to a file, for a non-Btrfs destination
sudo btrfs send /data/.snapshots/2026-11-23 | zstd > /mnt/usb/2026-11-23.btrfs.zst

-r is not optional. A send describes an exact state, so a snapshot that can change underneath the operation would produce an inconsistent stream. Btrfs refuses.

The received copy also arrives read-only, which matters for the next part.

Incremental sends

Where this becomes worth doing.

# yesterday's snapshot exists on both sides already
sudo btrfs subvolume snapshot -r /data /data/.snapshots/2026-11-24

# send only what changed since
sudo btrfs send -p /data/.snapshots/2026-11-23 /data/.snapshots/2026-11-24 \
  | ssh backup-host 'sudo btrfs receive /mnt/backup/'

-p names the parent: a snapshot that both sides already have, identically. The stream then contains only the difference.

The parent relationship is the thing to protect. Three rules follow:

  1. Keep at least one common snapshot on both sides. Delete it on the destination and the next incremental fails
  2. Do not modify the received snapshots. They are read-only for this reason; making one writable breaks it as a parent
  3. Retention policies must be aware of each other. A script that prunes the destination independently of the source will eventually remove the last common parent
# verify both sides agree before relying on it
sudo btrfs subvolume list -r /data | tail -5
ssh backup-host 'sudo btrfs subvolume list -r /mnt/backup' | tail -5

# received snapshots carry a uuid linking them to the source
sudo btrfs subvolume show /mnt/backup/2026-11-23 | grep -E 'UUID|Received'

The Received UUID field is what Btrfs uses to match a parent. If it is empty on the destination, that snapshot cannot serve as a parent, which is usually the cause of a failure that looks inexplicable.

A workable script

#!/usr/bin/env bash
# /usr/local/bin/btrfs-replicate
set -euo pipefail

SRC=/data
SNAPDIR=/data/.snapshots
DEST_HOST=backup-host
DEST_PATH=/mnt/backup
KEEP=14

today=$(date +%F)
new="$SNAPDIR/$today"

# the most recent snapshot that also exists on the destination
parent=$(ssh "$DEST_HOST" "ls -1 $DEST_PATH" | sort | tail -1 || true)

sudo btrfs subvolume snapshot -r "$SRC" "$new"
sync

if [[ -n "$parent" && -d "$SNAPDIR/$parent" ]]; then
    sudo btrfs send -p "$SNAPDIR/$parent" "$new" \
      | ssh "$DEST_HOST" "sudo btrfs receive $DEST_PATH"
else
    echo "no common parent, sending full stream" >&2
    sudo btrfs send "$new" | ssh "$DEST_HOST" "sudo btrfs receive $DEST_PATH"
fi

# prune, keeping enough that a parent always survives
ls -1d "$SNAPDIR"/* | sort | head -n -"$KEEP" | while read -r old; do
    sudo btrfs subvolume delete "$old"
done
ssh "$DEST_HOST" "ls -1d $DEST_PATH/* | sort | head -n -$KEEP | \
  xargs -r -n1 sudo btrfs subvolume delete"

Points worth lifting:

The parent is discovered from the destination, not assumed. That is what makes it recover from a missed run.

It falls back to a full send rather than failing, and says so on stderr.

Both sides prune to the same count, keeping the newest. Pruning only one side is how the parent chain breaks.

Our bash error handling guide covers set -euo pipefail, and flock and mktemp covers stopping two runs overlapping, which matters here because a half-finished receive is awkward.

Run it from a systemd timer rather than cron, so failures land in the journal:

# /etc/systemd/system/btrfs-replicate.service
[Unit]
Description=Replicate Btrfs snapshots
OnFailure=notify-failure@%n.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/btrfs-replicate

Our sending mail guide covers wiring the failure notification, since a replication job that silently stops is worse than one that was never set up.

# compress the stream, which matters over a WAN
sudo btrfs send -p "$parent" "$new" | zstd -3 \
  | ssh backup-host 'zstd -d | sudo btrfs receive /mnt/backup/'

# progress, since send gives none
sudo btrfs send "$new" | pv | ssh backup-host 'sudo btrfs receive /mnt/backup/'

pv is worth installing for this. send produces no progress output at all, and a multi-hour transfer with no feedback is unpleasant.

Note that ssh already compresses with -C, and doing both is wasted CPU. zstd in the pipe is usually better than ssh’s compression for this traffic. Our zstd guide covers the levels.

The restore, which is the part to test

# browse a received snapshot, it is just a subvolume
ls /mnt/backup/2026-11-23/

# restore a single file
cp /mnt/backup/2026-11-23/path/to/file /data/path/to/file

# restore everything, by sending back
sudo btrfs send /mnt/backup/2026-11-23 \
  | ssh original-host 'sudo btrfs receive /data/.restore/'

# from a stream file
zstd -d < /mnt/usb/2026-11-23.btrfs.zst | sudo btrfs receive /mnt/restore/

A received snapshot is browsable, which is the advantage over an opaque backup format. You can ls into it and pull one file out without restoring anything.

A stream file is not. It is opaque until received, and a corrupt file may be unrecoverable in full. For that reason, receiving into a live Btrfs filesystem is the better arrangement and stream files are for transport.

Test the restore. On a schedule, into a scratch subvolume. Our backups guide makes this point generally and it applies with force here, because the parent-chain mechanics give you more ways to end up with snapshots that cannot be used.

Limitations

Btrfs to Btrfs only, for a live destination. Our restic versus borg comparison covers tools that work anywhere and deduplicate across machines, which is a different and frequently better answer.

No encryption of the stream itself. ssh covers it in transit; at rest, the destination filesystem needs LUKS.

The whole subvolume, or nothing. No file-level selection, so excluding a cache directory means it was a separate subvolume from the start.

Version sensitivity. A stream from a much newer kernel may not be receivable by an older one.

For a single machine replicating to a single destination of the same filesystem, send and receive are the fastest and most faithful option available. For anything more varied, a dedicated backup tool is the better fit, and the two coexist happily.

Frequently Asked Questions

Why use btrfs send instead of rsync?

rsync has to walk both filesystems and compare to work out what changed, which costs time proportional to the number of files. Btrfs already knows which blocks changed between two snapshots, so an incremental send produces that difference directly with no scanning. On a filesystem with millions of files the difference is enormous.

Do snapshots count as backups?

No. A snapshot shares blocks with the original on the same filesystem, so a failed disk, an accidental filesystem format or corruption takes both. A snapshot is a fast local rollback point, and it becomes a backup only once a copy exists on different hardware.

What does read-only mean for send and receive?

A snapshot must be read-only to be sent, because the stream describes an exact state and a changing source would make it inconsistent. The received copy also arrives read-only, which protects the parent relationship that incremental sends depend on.

Why does my incremental send fail with a parent error?

Because the parent snapshot named with -p does not exist on the receiving side, or has been modified there. Incremental sends express a difference relative to a snapshot both ends have, so both must hold an identical read-only copy of it. Deleting old snapshots on the destination breaks future increments.

Can I send a Btrfs snapshot to a non-Btrfs filesystem?

Only as a file. The stream can be redirected to a file on any filesystem and restored later with receive, but it is opaque until then, so you cannot browse it and a corrupt file may be unusable. Receiving into a live Btrfs filesystem is the arrangement that gives you a browsable copy.

Is btrfs send safe to run over ssh?

Yes, and it is the normal way to use it. Pipe send into ssh and run receive on the far end. Compress the stream for a slow link, and consider that the receiving side needs a Btrfs filesystem and sufficient privileges to create subvolumes.