Lxc image import and ZFS

I’m trying to work out the best (simplest and most efficient) way to backup and restore my ZFS pool backed LXD containers whilst retaining all snapshots intact.

I would prefer to do this by backing up the lxd config and using the zfs send command to backup the LXD containers dataset onto a ZFS dataset on a remote machine not running LXD. The backing up bit should be easy enough but it is the restore process I’m not sure about as I’m really hoping to avoid having to create any tarballs for the rootfs because one of my containers root disk is about 165 GB so creating and restoring tarballs is quite a lengthy process.

Looking at the output of lxc image import --help it appears that I might indeed be able to import a container from a directory/dataset without having to create a tarball of the rootfs first. Is this the case? I’m not sure because I don’t think that the help output for lxc image import is correct anyway because it neglects to mention the need for the metadata tarball. As I understand it, the correct way to use lxc image import with tarballs is like so:

$ lxc image import <metadata tarball> <rootfs tarball>

I’m OK with having to use a metadata tarball to import my rootfs directory/dataset into LXD but I’m hoping there is no need to provide a rootfs tarball and that I will simply be able to point it to a directory (ZFS dataset) on my LXD server and it would restore all the snapshots correctly so that LXD is aware of them.

If this is not currently possible could this feature be added please or is there another way to pull this off without rootfs tarballs?

Thanks

lxc image import is really just for images, since you’re talking about snapshots, I suspect you care more about instances.

For those, you can use your ZFS tooling to sync to another server and then sync back to recover. Once the datasets are back the way they were, you can use lxd recovery to re-create the DB records from the data in ZFS (it will contain all instances & instance snapshots data and will know what storage pool to put things in, but will not contain config data on profiles or networks, so those you’d want to re-create ahead of time).

1 Like

Thanks Stéphane, that sounds simple enough for my liking.

I’m running LXD 4.0 stable (4.19) under 20.04 and I don’t seem to have the lxd recovery option. Is the recovery feature only available in the LXD beta or edge snaps?

Sorry, lxd recover should be the command, it’s definitely in 4.19.