Save and restore all lxd containers to local storage

(Brian Candler) #1

I would like to rebuild an LXD container host from scratch - changing it from btrfs to zfs, and making it ubuntu 18.04 + lxd3. I want to save the containers, rebuild this host onto the existing hardware and restore the containers back onto it. A few hours downtime is not a problem.

One option is to build a temporary host, use “lxc move” to move the containers onto it, and then after rebuild use “lxc move” to move them back. But that all has to be done over ethernet; plus of course I need another host.

I think it may be faster if I attached some local disk (e.g. fast USB3 drive, or an extra SATA drive). Is there a safe way to export containers and their settings to such storage, and re-import them into the rebuilt system?

I found this post from 2017, it suggests (ab)using the image publish/import mechanism.

Looking at #3730 it seems that a true export/import function was added very recently. But on another system (18.04 / lxd 3.0.1), I see no “lxc export” command :frowning:

Does this mean I’d have to go to 3.1/3.2 from backports to get this function?



(Stéphane Graber) #2

Your options are pretty much:

  • Do the lxc copy or lxc move trick, either with a separate system or if you can setup both btrfs and zfs on the same machine, then as a separate daemon on the same machine (a bit tricky to do).
  • Upgrade to LXD 3.2 and use import/export but then you can’t downgrade back to 3.0.
  • Publish your containers as images, then download the image, but then you loose your container config and any snapshots they may have.

(Brian Candler) #3


I should be able to have zfs and btrfs on the same machine; actually I may change to SSD at the same time, so I can have the new SSDs and the old HDs mounted. Obviously the old HDs would be at a different mountpoint though.

Can you point me to the steps required to run the second lxd with a different base directory and port?

(Stéphane Graber) #4

General idea is:

export LXD_DIR=/path/to/lxd (replacement of /var/lib/lxd effectively)
lxd --debug --group lxd

That will start a daemon using the alternate path.
To talk to that daemon, you can then do:

export LXD_DIR=/path/to/lxd
lxc list

(Brian Candler) #5

But how to do lxc copy using that daemon as source, and the normal daemon as destination? Wouldn’t I have to add it as a remote?

(Stéphane Graber) #6

Yes, you could do that with lxc remote add some-name unix:///path/to/daemon/unix.socket