In this lesson, you will learn how to leverage Btrfs send and receive streams to create highly efficient, bandwidth-optimized off-site backups of your data.
The Core Concept
When you need to back up a large dataset to a remote server, copying every single file is slow and wastes network bandwidth. Instead, Btrfs allows you to convert the difference between two snapshots into a compact, binary "stream." This stream contains only the data that changed, making it perfect for incremental synchronization over slow or expensive network connections.
Think of it like a "delta" update: if you have a 1TB subvolume and you take a snapshot, then change only 10MB of data, the send command will generate a stream representing just those 10MB.
Implementation
To use this, you must have two snapshots of the same subvolume: a "parent" (the base) and a "clone" (the new state).
- Generate the stream: You "send" the difference from your local machine, often piping it over
sshto a destination server. - Receive the stream: The destination server uses the
receivecommand to apply those changes to its own Btrfs volume.
Here is how you would sync an incremental change:
# Send the incremental change from 'snapshot_v2' based on 'snapshot_v1'
btrfs send -p /mnt/btrfs/snapshots/v1 /mnt/btrfs/snapshots/v2 | \
ssh user@remote-backup "btrfs receive /mnt/backup_drive/subvolumes"
In this command:
-p /mnt/btrfs/snapshots/v1tells Btrfs that the first snapshot is the common ancestor, so it only calculates what changed since then.- The pipe (
|) sends that binary data directly to the remote server without needing to save an intermediate file on your local disk. btrfs receiveon the remote end reconstructs the state of the second snapshot exactly, byte-for-byte, using only the delta stream.
Because this happens at the file-system block level rather than the file level, it is incredibly fast and ignores file metadata changes that don't affect data content, saving you significant time during daily maintenance.
Key Takeaway: By piping incremental Btrfs snapshots through send and receive, you minimize network traffic by only transmitting the specific data blocks that have changed since your last backup.