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*
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.


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


1 Like

I’ve made this little python script that print all delete snapshot commands that can be made on all running containers:

import os
stream = os.popen("lxc list --format=json | jq -r '.[] | select(.state.status == \"Running\") | .name '")
output =
for cont in output.split("\n"):
    if cont:
        lss=os.popen("lxc query /1.0/instances/{}/snapshots?recursion=1 | jq -r '.[].name' ".format(cont))
        for lss in lssn:
            if lss:
                print("lxc delete {}/{}".format(cont,lss))