How to delete multimple Snapshots with one command?

Hi, I was wondering if there is a way to delete multiple snapshots with one command, I’ve been benchmarking a new LXD node and I had set the snapshots to every minute for the default profile, now I have tons of snapshots for each container and I wanted to delete them.

I’ve tried this but doesn’t work:

lxc rm con01/snap*
and
lxc rm con01/*

but it doesn’t like the asterisc
Error: Failed to fetch snapshot “snap*” of instance “con01” in project “default”: No such object

Any way to do so without having to use ZFS commands?

Thank you!

There is no wildcard support in this command or really in much any LXD command.

Your best bet would be something like:

lxc query /1.0/instances/con01/snapshots?recursion=1 | jq -r ‘.[].name’ | while read line; do lxc delete con01/$line; done

So effectively retrieving the list of snapshots, filtering it whatever way you want and then calling lxc delete on those.

1 Like

OK, I guess it is time to learn how to work with the database!

Thanks @stgraber

Option 2 :slight_smile:

lxc info con01 | awk ‘{print $1}’ | grep snap | xargs -I SNAP lxc delete con01/SNAP

Regards
G

1 Like