BTRFS incremental backup to external drive with Snapper

Snapper creates timeline for your BTRFS file system. You can send those timelines to an external hard drive for backup. This method is way better than rsync, as every single change to your filesystem is preserve.

A better way of doing this kind of thing might be Btrbk, but it is not available in the default Debian repository. Although it is available in Neurodebian repository. I have Snapper set up already, so I didn't bother with trying to set up Btrbk.

Bootstrapping

The bootstrapping process will take a long time.

# $i is the ID of the backup
# $DRIVE is the mount point for the backup drive.
# $chosen_date is the date for the snapshot
 
mkdir /media/fangfufu/$DRIVE/home-$i-$chosen_date
btrfs send /home/.snapshots/$i/snapshot | btrfs receive /media/fangfufu/$DRIVE/home-$i-$chosen_date

Subsequent backup

We are transferring the diff between two backups. It is relatively fast.

# $i is the ID of the previous backup
# $j is the ID of the new backup
# $DRIVE is the mount point for the backup drive.
# $chosen_date is the date for the snapshot
 
mkdir /media/fangfufu/$DRIVE/home-$j-$chosen_date
btrfs send -p /home/.snapshots/$i/snapshot /home/.snapshots/$j/snapshot | btrfs receive /media/fangfufu/$DRIVE/home-$j-$chosen_date

Other notes

BTRFS subvolume can be set up in any subdirectory. In fact, assuming that Snapper is covering your /home, snapshots will be created at /home/.snapshots/$i/snapshot, where $i is the snapshot ID.

If you want to set up multiple BTRFS subvolumes in the same directory, they must have unique names. Because every single subvolume created by Snapper has the name snapshot, you have to put them into different sub-directories.

You have to have the parent snapshot, in order to receive the diff snapshot. Otherwise the filesystem will throw error. So you have transfer backup to the external drive at least once within the maximum retention period specified by your Snapper configuration. If you forget to do that, you have to redo the bootstrapping process.

References