Lxc 3.0.3 - some container snapshots lost on recovery

Ubuntu 18.04, lxc/lxd apt install. Moved the system to a new disk by unrolling root fs via dump| restore and restoring ZFS storage via a zfs send | zfs recv from backups.

However, lxd did not find its storage, so I had to trick it making a dummy one (as described here), and then substituting the old one for the dummy with a subsequent lxd import.

It all went well, except for one thing – some container snapshots are present as zfs snapshots but do not appear in lxc list output.

Therefore – I wonder if some kind soul can point me in the direction of where lxc/lxd stores the snapshot info, and whether there’s a way to recreate them by hand – for lxd 3.0.3 and those poor souls who don’t yet have the restoration tool available for them )

To add, I wonder if there is a way to un-import a container, so that I can edit backup.xml and attempt to import it again ?

( This is a first post, my apologies if it should have been better )

The snapshot information is stored in the database (containers table in this case).
Manually adding them back through there is doable but likely quite annoying.

If you want to re-do the import, you can delete the database entry with lxd sql global "DELETE FROM instances WHERE name LIKE 'foo%'"

This will delete anything which starts with foo, so including foo/snap0.
Just note that it would also remove an instance called foobar so be careful :slight_smile:

1 Like

IMHO, lxd sql should be in some sort of advanced FAQ ( happy to maintain one if needed ).

( Btw, I did try systemctl stop lxd; sqlite3 /var/lib/lxd/database/global/db.bin, … ; systemctl start lxd – and it did not work for me. But lxd sql is just the solution. )

So, in 3.0.3 it would be containers ( not instances ), and for those who will stumble upon the same problem:

  • say, your zfs storage sits on pool/fs ;
  • then zfs list -r -t all pool/fs/containers | grep @snapshot would give you the snapshot names, in the form snapshot-$lxcsnap, where $lxcsnap would be the lxc internal name ;
  • now suppose you have a snapshot arch-prototype@snapshot-2021-05-01-initial, which is missing from lxc info arch-prototype output, and you want to add it there – then the spell ( in the short version ) may look as follows:
lxd sql global "
INSERT INTO containers( node_id
                      , name
                      , architecture
                      , type
                      , last_use_date
                      , description
       , 'arch-prototype/2021-05-01-initial'
       , 2
       , 1
       , '2021-05-01 00:00:00.000000000+00:00'
       , 'restored'

( One may want to do an lxd sql '.schema' and lxd sql 'SELECT * FROM containers' to get a better idea of what’s going to happen before starting to write in the database. )


1 Like