christoph ender's

blog

tuesday the 22nd of august, 2023

btrfs send and receive

brtfs snapshots are great for incremental backups – just create a snap from a working directory and keep on happily working on the original folder as you please: btrfs makes sure that only incremental changes from the snapshot to the current state will occupy space.

Replicating these backups to another volume using a simple copy operation doesn't however really work that great: as one would expect, simple copying can't reproduce the deduplication from the source device on the target space. This is where btrfs send and btrfs receive come in: You can stream a btrfs read-only subvolume including all it's metadata somewhere else:

btrfs send snap1 > snap1.bin
btrfs recevice in/ < snap1.bin

In the two lines above, the “snap1” directory along with it's btrfs-relevant metadata is written to “snap1.bin”. This can be transferred somewhere else and unpacked into some directory – “in” in this case – using btrfs receive. Once this has been completed, the incremental changes from “snap1“ to a “snap2” can be transferred using the following commands:

btrfs send -p snap1 snap2 > snap2.bin
btrfs recevice in/ < snap2.bin

This will reconstruct “snap2” based on the already present data from “snap1” and reconstruct the same deducpliation on the target space.