Lxd recover docs/guidance to restore from backup

I’m trying to recover my containers/migrate to a new machine.

My old machine was 18.04 and used lxc storage with a loopback file managed by lxc. It no longer boots, but I have a backup of the data from the disk.

The new machine is 20.04 and has zfs storage backend on a dataset (named tank0/lxc and created outside of lxc, and this time on it’s own disk partition).

I’m trying to understand how to import the containers from the old disk onto the new machine, but am struggling – partly I think because I’ve followed a mix of instructions and they’re no longer current.

So far I tried
bringing the old loopback based pool online:
sudo zpool import -o readonly=on -d /mnt/backup/var/lib/lxd/disks default -R /mnt/mnt0

This seems to be suggest the data is available:
sudo zfs list

NAME                                                                                      USED  AVAIL     REFER  MOUNTPOINT
default                                                                                  18.5G  4.29G       24K  none
default/containers                                                                       15.7G  4.29G       24K  none
default/containers/ansible                                                               1.41G  4.29G     1.00G  /mnt/mnt0/var/lib/lxd/storage-pools/default/containers/ansible
default/containers/ansible-target-test                                                   1.14G  4.29G     1.50G  /mnt/mnt0/var/lib/lxd/storage-pools/default/containers/ansible-target-test

I then tried using lxd import but got
Error: Command has been replaced with "lxd recover"

I’ve tried various incantations of lxd recover but I’m not sure I’m entering things correctly (to be honest I initially tried entering ‘dataset’ or ‘path’ in answer to Source of the storage pool as the previous question required an answer provided from the set in brackets!)

This LXD server currently has the following storage pools:
 - default (backend="zfs", source="tank0/lxc")
Would you like to recover another storage pool? (yes/no) [default=no]: yes
Name of the storage pool: default
Name of the storage backend (btrfs, cephfs, dir, lvm, zfs, ceph): zfs
Source of the storage pool (block device, volume group, dataset, path, ... as applicable): /mnt/backup/var/lib/lxd/disks/default.img
Additional storage pool configuration property (KEY=VALUE, empty when done): 
Would you like to recover another storage pool? (yes/no) [default=no]: 
The recovery process will be scanning the following storage pools:
 - EXISTING: "default" (backend="zfs", source="tank0/lxc")
 - NEW: "default" (backend="zfs", source="/mnt/backup/var/lib/lxd/disks/default.img")
Would you like to continue with scanning for lost volumes? (yes/no) [default=yes]: 
Scanning for unknown volumes...
No unknown volumes found. Nothing to do.

Other debugging info that may help:

sudo zfs list -r -o name,mounted,canmount,mountpoint default

NAME                                                                                     MOUNTED  CANMOUNT  MOUNTPOINT
default                                                                                       no        on  none
default/containers                                                                            no        on  none
default/containers/ansible                                                                    no    noauto  /mnt/mnt0/var/lib/lxd/storage-pools/default/containers/ansible
default/containers/ansible-target-test                                                        no    noauto  /mnt/mnt0/var/lib/lxd/storage-pools/default/containers/ansible-target-test

I’ve tried to read the documentation but get the impression this is a newly developing area of lxc.

I saw this alternative that rsyncs the data: Recovering containers from crashed HD - #22 by stgraber but I’m not entirely sure how lxd recover behaves – I want the old containers to run from the new zfs pool, not a dir backend.

I’d much appreciate it if someone could point me in the right direction, or some good documentation/examples for using lxd recover, thanks.

So I think your best bet here is to run the zpool import.

Once you see default in zpool status then use lxd recover and use default as the source. This should have LXD properly locate it and start scanning it.

Once everything is back in the DB, you can move your .img over to /var/snap/lxd/common/lxd/disks/default.img so that LXD auto-imports it on boot.

1 Like

Thanks, I think my problem was I didn’t realise how smart lxd recover was!

1 Like