$ lxc storage list
+-------+-------------+--------+---------+---------+
| NAME | DESCRIPTION | DRIVER | STATE | USED BY |
+-------+-------------+--------+---------+---------+
| local | | btrfs | CREATED | 12 |
+-------+-------------+--------+---------+---------+
It’s happened after upgrade cluster from 3.22 to 4.0.0
Seems this is happening after remove pre-upgraded snapshot, then it’s creating without issues, then after remove it again and create - I see this issue
Steps to reproduce:
Check “storage_volumes_snapshots”
Yes, this is snap rev=14503.
But I also checked on non-cluster version (arm64, revision), no issue… hm… now I not sure that this is after 3.22 upgrade, maybe happened earlier…
Oh, on 2nd cluster I see the same issue, also upgraded from 3.22 version.
I see the the same issue after updating from 3.0/stable via snap refresh lxd --channel=4.0/stable some days ago. I do not use the cluster setup.
It seems to me that database table “storage_volumes_snapshots” was introduced in 4.0 and a migration of snapshots from table “storage_volumes” did not happen properly.
There is a nightly script that removes an old container snapshot named “backup” and creates a new one with the same name; this script now fails with
Error: Failed to fetch snapshot "backup" of instance "iobroker" in project "default": No such object
Error: Failed creating instance snapshot record "iobroker/backup": Failed initialising instance: Failed creating storage record for snapshot: Insert volume snapshot: UNIQUE constraint failed: storage_volumes_snapshots.storage_volume_id, storage_volumes_snapshots.name
In the following tables I see
snapshots that were not migrated to storage_volumes_snapshots, e.g. iobroker/after-zwave-usb
snapshots with the same name in old/new persistence, see 570=iobroker/backup and 7=iobroker/575=backup
First you’d need to check what snapshots actually exist on disk to get an idea of jsut how wrong those tables are.
The NAME/SNAPSHOT entries in storage_volumes will need to go away but you should also check that there’s nothing missing in the storage_volume_snapshots table.
Thanks for your advice, I migrated the database records accordingly and snapshots can be used again now.
Just for the record:
With a zfs storage backend, use
# zfs list -t snapshot
to take a look at existing snapshots.
Use
# lxd sql global "SELECT * FROM storage_volumes;"
# lxd sql global "SELECT * FROM storage_volumes_snapshots;"
to see existing snapshots that may need to be migrated from storage_volumes to storage_volumes_snapshots.
Use e.g.
# lxd sql global "INSERT INTO storage_volumes_snapshots VALUES(596, 7, 'after-zwave-usb', '', '0001-01-01T00:53:28+00:53');"
# lxd sql global "DELETE FROM storage_volumes WHERE id IN (...);"
# lxd sql global "DELETE FROM storage_volumes_snapshots WHERE id IN (...);"
to cleanup the tables.
Use
# lxd sql global "UPDATE SQLITE_SEQUENCE SET SEQ=599 WHERE NAME='storage_volumes';"
to set the auto increment key sequence to a new value.
The following command creates a list of SQL statements for the database migration of snapshots from LXD v3.x to v4.x:
lxd sql global "SELECT 'DELETE FROM storage_volumes WHERE id IN (' || id || ')' as delstat, 'INSERT INTO storage_volumes_snapshots VALUES(' || id || ',' || (SELECT id FROM storage_volumes WHERE name=contname) || ',''' || contsnapshot || ''', '''', ''0001-01-01T00:53:28+00:53'')' as insstat FROM (SELECT id, substr(name, 0, instr(name, '/')) as contname, substr(name, instr(name, '/')+1) as contsnapshot FROM storage_volumes where contname!='');"
The printed statements need to be executed after an lxd update via e.g. snap refresh lxd --channel=4.0/stable, sample:
lxd sql global "DELETE FROM storage_volumes WHERE id IN (836); INSERT INTO storage_volumes_snapshots VALUES(836,65,'backup', '', '0001-01-01T00:53:28+00:53');"