Appropriate backup strategy and workflow with BTRFS storage backends?

Hi there,

im quite new to LXD/LXC and still learning a lot, but I somehow have a feeling of „getting there“ :slight_smile:
Still, what I haven’t figured out is, how an appropriate backup strategy and workflow would look like. I have read the Docs (Backing up a LXD server - LXD - system container manager), some posts in this forum and e.g. this howto (How to backup and restore LXD containers).
My takeaway is that it comes down to just creating tarball of each instance and storing that away (lxc export & lxc storage volume export). But as I’m using BTRFS everywhere (also for the backup location which currently is an external HDD) I don’t like this solution very much. I was hoping to make use of BTRFS’ features like send/receive as each instance already is a BTRFS subvolume.
So basically I have the following questions on my mind, where I have not been able to find an answer yet:

  • Is it possible to send/receive an instance-subvolume (i.e. an previously created read-only snapshot of it of course) to an external HDD BTRFS volume and in case of failure importing it back?
  • In this scenario: How to deal with the LXD created snapshots of the instances?
  • Basically the same previous two questions appliy for custom storage volumes, but I expect this to work identical as with instances
  • How to backup the profiles, networking etc? (I.e. everything else that is needed to run the snapshotted instances)
  • How would I backup LXD itself to be able to be restored (and the snapshotted instances) e.g. in case the SSD containing the root filesystem and also LXD fails completely? Is it enough to just save „lxd init --dump“ and preseed that to a an init of a freshly installed lxd?

In the past (without „containerizing“ all my services), I was running my backups with a shell script, which I wrapped around „btrbk“ (btrbk - Summary) and found that to be very straight forward and easy to use. Is there any chance I can make use of that again?

My home server is running Ubuntu 20.04 LTS and I am providing my different services through LXD/LXC containers.

For example:

  • container “cloudserv” running seafile
  • container “webservice” running nginx and MariaDB

I have one SSD which holds the root filesystem and also the containers. The two exemplary containers are located on my SSD with btrfs filesystem. For data storage I am using an array of disks (also with BTRFS), where I have created another LXC storage pool with a storage volume which is the attached to the seafile container to hold all the data. The layout is something like this:

SSD

  • BTRFS Filsystem
    • Servers rootfs
    • LXD (via snap)
    • Storage Pool “Default”
      • container “cloudserv”
      • container “webservice”
      • images

HDDs

  • BTRFS Filesystem
    • Storage Pool “DataPool1”
      • custom storage volume “seafile-data” → attached to container “cloudserv”

ext. HDD

  • BTRFS Filesystem

As you can see, I currently have some confusion on how to do that backup stuff properly :slight_smile: Can anybody give some hints for appropriate backup workflow for LXD/LXC with BTRFS?

Thanks in advance an best regards,
sandman

Hi @sandman85,
I am using btrfs for my lxd as well.
To make use of the nice featues from btrfs with lxd, make sure that your lxd root directory is a btrfs subvolume. I use snap so I have a btrfs subvolume created at /var/snap/lxd.
After this you will be able to make snapshots with the lxc command:

lxc snapshot <container_name> <snap_name>

Setup another host with LXD on btrfs and create an LXD cluster between these two hosts.
https://linuxcontainers.org/lxd/advanced-guide/#setup-your-lxd-server-as-remote-server
Now you can copy the local snapshot to the remote LXD host with:

lxc copy <container_name>/<snap_name> <hostname_or_ip>:<name_of_the_container_on_other_host>

If it is important to have the same MAC-address on the backup, do on the backup host:

lxc config set <name_of_the_created_container_on_other_host> volatile.eth0.hwaddr <MAC_address>

I hope this can help you to figure out your way of backing things up!