incus bulk delete snapshots
Incus in an excellent system container, application container, and virtual machine manager (see https://linuxcontainers.org/incus/) which allows you to schedule regular snapshots of instances.
If, like me, you like to test these systems. I created a snapshot schedule to snapshot instances every minutes (yes, extreme) but you can imagne scnerarios where this is useful (students, learners for example). When you do this, however, after a few weeks of course you can end up with tens of thousands of snapshots (especially if you don't set an expiry on the snapshots). incus snapshot list
becomes painfully slow, because an incus api get snapshot
is called for every single snapshot (esssentially a O(n)
operation proportional to the number of snapshots).
With excessive amounts of snapshots , `incus snapshot list <instance-name>` will eventually timeout:
```
incus snapshot list instance-name
^B^[[BError: Get "http://unix.socket/1.0/instances/instance-name/snapshots?recursion=1": net/http: timeout awaiting response headers
```
Even if you delete your snapshots as the zfs level directly ( zfs destroy
...) incus state still has a database entry to those non existant snapshots.
the best bet is to use zfs destroy to directly delete all those snapshots. That should then make ZFS performance go back to normal at which point you can issue the incus snapshot delete commands to get rid of the Incus snapshots.
Src: https://github.com/lxc/incus/issues/2036#issuecomment-2842758126
Since snapshots are deleted serially, even using tools like gnu parallel won't give you speed boost so a simple bash for loop will eventually clear out Incus's database for that particular instance (rince & repeat for other instances):
#!/bin/bash
set -x
# whatever your range to delete
for i in {7000..16053}; do
incus snapshot delete instance-name snap$i;
done
See also