Btrfs Send and Receive Explained for Linux
The btrfs send and btrfs receive commands
are native Linux utilities designed for efficient data replication,
backups, and filesystem migration. They work by converting read-only
Btrfs subvolume snapshots into a standardized data stream that can be
transferred across storage devices, local paths, or networks, and then
reconstructed byte-for-byte on a target Btrfs filesystem. This
functionality provides a high-performance alternative to traditional
file-copying utilities like rsync by operating at the
filesystem block level rather than scanning individual files.
Core Purpose and Use Cases
The primary objective of the send and
receive feature is to move data reliably while minimizing
resource usage and execution time. Common use cases include:
- Local Backups: Cloning snapshots from an active OS drive to a secondary local storage drive.
- Remote Disaster Recovery: Streaming snapshot deltas over SSH to an offsite backup server.
- System and Drive Migration: Moving an entire operating system installation or user directory to a new storage drive without losing snapshot history or filesystem-level attributes.
How Btrfs Send and Receive Works
The mechanism functions as a pipeline consisting of two operations:
btrfs send: Reads a read-only snapshot on the source filesystem, analyzes its underlying B-trees, and serializes the metadata and data blocks into a continuous binary stream.btrfs receive: Accepts that binary stream from standard input on the destination filesystem and recreates the identical read-only snapshot.
Because the output of btrfs send is written directly to
standard output (stdout), it integrates seamlessly with
standard Unix pipes and utilities. It can be redirected into a raw file,
compressed using tools like zstd or gzip, or
piped through secure network shells like ssh.
Incremental Backups
The most powerful capability of this feature is incremental data
transfer. When utilizing the -p (parent) parameter,
btrfs send calculates the exact differences (deltas)
between an older snapshot and a newer one:
- No File Scanning: Traditional tools like
rsyncmust recursively traverse directory trees and compare file modification times or checksums to determine changes. Btrfs already tracks changed blocks internally via its Copy-on-Write (CoW) design. - Differential Streaming:
btrfs sendonly transmits the specific blocks modified or added between the parent and child snapshots. This results in fast execution times and low network bandwidth usage, even across filesystems containing millions of files.
Key Advantages
- Metadata Integrity: Transfers retain subvolume UUIDs, file permissions, ownership, timestamps, extended attributes (xattrs), and access control lists (ACLs) without alteration.
- Space Sharing Preservation: If multiple files share the same physical blocks due to Btrfs deduplication or CoW cloning, this deduplicated structure is preserved across the transfer, preventing storage bloat on the target.
- Lower I/O Overhead: By bypassing userspace file traversal and reading disk changes directly via filesystem metadata, the process creates significantly less disk thrashing compared to file-level synchronization tools.