Backing up a LXD server

I was just going through the documentation of Backing up a LXD Server. It’s recommended on it for full backup:

Full backup

A full backup would include the entirety of /var/lib/lxd or A full backup would include the entirety of /var/lib/lxd or /var/snap/lxd/common/lxd for snap users.

You will also need to appropriately backup any external storage that you made LXD use, this can be LVM volume groups, ZFS zpools or any other resource which isn’t directly self-contained to LXD.

But if we take the full backup of /var/snap/lxd/common/lxd it will due to symlink will also include the backup of the instances and images as they are mounted on paths here.

So will it be better if this section contains the directory necessary for restore + ZFS or LVM or BTRFS pool containers and instances separately?

/var/snap/lxd/common/lxd as seen from the host doesn’t include any mounts as those are hidden in a separate namespace. If you’re using loop based storage, then it will include /var/snap/lxd/common/lxd/disks at which point you don’t need to handle the storage separately.

From host I can cd into and check the contents of /var/snap/lxd/common/lxd/storage-pools/local and also within it the contents of each container with sudo privileges .

I will still try to backup this directory using borgbackup (with sudo privileges) and let you know if it backups the containers as well or not. My initial guess is borgbackup will be backing up this directory contents of storage-pools as well.

Ah, that normally can only happen if:

  • Using a dir storage pool
  • Using a btrfs storage pool where the source was set to /var/snap/lxd/common/lxd/storage-pools/NAME

For the dir case, it’s easy, just backup /var/snap/lxd/common/lxd including all the storage-pool bits and you’ll be fine.

For the btrfs case, technically the same thing, but it getsa bit trickier because of the subvolumes that you’d want to somehow backup in a way that’s restorable…
That’s where btrfs specific tooling may get involved as you’d effectively want something like a btrfs-aware rsync which would let you backup from one location to another, conserving all your btrfs subvolumes and their relationships (and quotas).

I’ve never done that part with btrfs myself, I’ve done it with zfs plenty of times (zfs snapshot -r + zfs send | zfs receive). btrfs has similar concepts, I just don’t know the state of the tooling for this.

Actually instead of using btrfs send or receive I planned to use borgbackup for the whole LXD cluster given its simple and good tooling for backup.

Since I am using hetzner with its storage-box it makes it much easier given they have borgbackup supported on storage-box directly so I do not need another server.