List snapshots only

Hello LXDers,

I need to list all the snapshots in all my containers. I am about to write a script (awk, golang or else) to extract out and parse the snapshots table that is displayed at the end of 'lxc info '.

However, I am wondering if there is something that me and my googling missed.

Ideally a command that would give out a snapshot list in a parsable format (json or similar), or an API that I could use in a go program.

Many thanks.

I found this:

Time for me to start understanding how to use LXD’s API, unless someone has a simpler way of getting a snapshot list.

Using this: lxd package - -

It turns out that it’s super easy to get a snapshot list for each containers:

package main

import (
  lxd ""

func main() {
  c, err := lxd.ConnectLXDUnix("", nil)
  names, err := c.GetContainerNames()
  for _, name := range names {
        fmt.Printf("Container %s:\n", name)
        snaps, err := c.GetContainerSnapshots(name)
        for _, snap := range snaps {
                fmt.Printf(" - %s\n", snap.Name)

func E(err error) {
  if err != nil {

Hi lyderic,
It is not an elegant method, it is a little bit old school way.
for k in $(lxc ls -c"n" -fcsv) ; do curl -s --unix-socket /var/snap/lxd/common/lxd/unix.socket a/1.0/instances/$k/snapshots? | jq .metadata[]; done
Thanks for the source code by the way.

Very good indeed. To use in a shell script if golang is not an option.

lxc query /1.0/instances/NAME/snapshots would be even shorter :slight_smile:

1 Like

Ah ah, excellent Stéphane! I completely missed ‘lxc query’. I will use it a lot in the future.

Mille mercis.

lxc query [<remote>:]<API path> [flags]
Global Flags:
–project Override the source project

Doenst work:

lxc query /1.0/instances/NAME/snapshots --project x
Error: --project cannot be used with the query command


lxc query /1.0/instances/NAME/snapshots?project=x