What is the correct way to to btrfs Backups using btrbk?

Hey people!

I use the Fedora BTRFS setup just “cuz it works” and it is fine. But I really need a good backup solution and I would like to profit from btrfs and btrbk here.

I am on Fedora Kinoite, and have an empty HDD that is also 1TB in size. I need to encrypt it with LUKS and use it over USB.

Problems: I have no idea how to do that.

>> sudo btrfs filesystem show -d --human-readable                                                                                                                       
Label: 'fedora_fedora'  uuid: abcd1234
        Total devices 1 FS bytes used 863.60GiB
        devid    1 size 929.91GiB used 929.91GiB path /dev/mapper/luks-xxxx-yyyy

>> lsblk
# ...
nvme0n1                                       259:0    0 931,5G  0 disk  
├─nvme0n1p1                                   259:1    0   600M  0 part  /boot/efi
├─nvme0n1p2                                   259:2    0     1G  0 part  /boot
└─nvme0n1p3                                   259:3    0 929,9G  0 part  
  └─luks-xxxx-yyyy                            253:0    0 929,9G  0 crypt /var/home
                                                                         /var
                                                                         /sysroot/ostree/deploy/fedora/var
                                                                         /usr
                                                                         /etc
                                                                         /
                                                                         /sysroot

Also, I have ~/Big-Files and ~/Sync-Phone that I dont want to be backed up, as it is not that important and not only on my device.

So using rsync that would be pretty easy, but I would like to benefit of all that BTRFS stuff like mirroring etc. I would like to:

  • mirror my /var/lib/flatpak and /var/home/user only
  • exclude the said directories, can I put them into a different BTRFS subvolume while keeping them in that location?
  • define how many mirrored files I need
  • exclude some directories (Cryptomator) from keeping old files as these would be useless I suppose.

The strength of btrbk is automating snapshots and replicating them to another device. It’s not quite the same thing as mirroring, there’s a delay depending on how often the subvolume is snapshot and then replicated.

But btrfs definitely makes it cheap to do this often. Rsync will likely be easier to setup if you’re familiar with it. But it does require deep traversal on both sides to know what things have changed. Btrfs incremental send and receive can figure this out cheaply without deep traversal on both sides.

Whatever you want to replicate, needs to be a subvolume. A snapshot is also called a subvolume snapshot, it’s just a pre-populated subvolume. You can nest subvolumes within subvolumes. If you snapshot the parent, the snapshot does not descend (recursively) into nested subvolumes. So you can use subvolumes to both define what should and should not be snapshot.

Btrfs doesn’t really care about how you do the layout but I tend toward thinking of the flat layout Fedora is using for subvolumes that should be snapshot. And nested layout for subvolumes that I want to prevent snapshotting from descending into. Of course, you can still snapshot those nested subvolumes, or even irregularly.

thanks! So do you know if it is possible to create a subvolume in the subvolume /var/home and put an existing directory in there? I think that would be a good first step to sort my mess

Yes. It will behave like a directory, except it will have a different st_dev which some utilities will see as “crossing a file system boundary”, e.g. cp -x will not cross into subvolumes, but would cross into directories. So the nested subvolume is more than a directory but for the most part it behaves like one.