Is Btrfs Receive-Command Atomic

backupbtrfs

Short Version: I'm doing regular backups with help of Btrfs send and receive commands. The snapshot which contains the data to be backed up (SOURCE) is a read-only snapshot. Creating this snapshot with Btrfs is atomic. The backup then is made using a combination of Btrfs send and receive commands. My question is: Does the Btrfs receive command also create the backup snapshot atomically on the destination volume?

Long Version: For my daily backup strategy I use Btrfs to send changes of a source sub-volume to a backup-drive. The sub-volume I want to backup is located in SOURCE, while the backup itself will be stored in DEST.

Before I can make a backup, I need a read-only snapshot of SOURCE which I will store below SOURCE itself in a sub-directory called .snapshots. This is done with the commands

btrfs subvolume snapshot -r SOURCE SOURCE/.snapshots/current_backup
sync

The sync command above is needed according to the Btrfs-wiki to make btrfs send work. Now I want to send the snapshot called current_backup to a backup volume DEST on a different drive. I do this with the command

btrfs send SOURCE/.snapshots/current_backup | btrfs receive DEST

My question is about the btrfs receive part of this backup process: Does this happen atomically? In other words: Is the backup on volume DEST only available if it has been completely received and written?

Best Answer

No, it is not atomic. Btrfs receive does create a subvolume, so that's atomic, but initially the subvolume is empty. Then, btrfs receive fills the subvolume with the incoming data.

You can test this by cd'ing to DEST while performing the backup and doing ls or find repeatedly.