Suggestion: setting expiry time for individual snapshots

I just got caught by something. We have auto snapshots configured:

# incus profile show default
config:
  snapshots.expiry: 1d
  snapshots.pattern: autosnap-{{ creation_date|date:'2006-01-02_15-04-05' }}
  snapshots.schedule: 16 */1 * * *
...

I was doing a big upgrade on some containers, so I created a pre-upgrade snapshot on each. I was expecting to keep them around for some weeks, just in case. But they got deleted after a day :frowning:

Thanks to the forum, I’ve now found that I could have prevented this using:

incus snapshot create --no-expiry ...

But then I’d have to remember to come back in a few weeks to clean them up.

I believe that each snapshot already stores an explicit expires_at attribute (e.g. if I change snapshots.expiry in the profile, it doesn’t alter the expiry time of existing snapshots).

Therefore, here’s my feature suggestion:

  • At snapshot creation time, be able to specify an expiry time for that particular snapshot, either absolute or relative to now. e.g.

    incus snapshot create mycontainer pre-upgrade --expiry=4w
    

    (We’re running incus 6.0.4 in most places, but I do have one host with 6.12 and it doesn’t seem to have this feature)

  • Be able to modify the expiry time of an individual snapshot before it expires, e.g.

    incus snapshot edit mycontainer pre-upgrade --no-expiry
    # OR
    incus snapshot edit mycontainer pre-upgrade --expiry=6w
    

    (or some other syntax, e.g. incus snapshot set… or whatever is most consistent)

Finally, if snapshots.expiry could be split into two settings, one for automatic and one for manual snapshots. then I could set snapshots.expiry.manual to 4w or never and avoid the surprises. That would allow changing the current behaviour, whilst remaining backwards compatible with existing users.

Anyway, just a thought - thanks for reading!

There’s an API for snapshot update that allows to update individual settings of snapshots, such as the expiry. If you were to click in there, the example is about updating the expires_at field.

The first question is whether the existing API is good enough to cover the two cases that you describe above.

If the answer is yes, then the second question is how to expose the API functionality into 1) the incus client, and 2) the Web UI. At least for the incus client it should be relatively easy, just add an incus snapshot update sub-command.

1 Like

It’s great that the API supports this already.

For the first case, I checked what incus snapshot create does using the --debug flag:

# default
"\n\t{\n\t\t\"name\": \"s1\",\n\t\t\"stateful\": false,\n\t\t\"expires_at\": null\n\t}"

# with --no-expiry
"\n\t{\n\t\t\"name\": \"s2\",\n\t\t\"stateful\": false,\n\t\t\"expires_at\": \"0001-01-01T00:00:00Z\"\n\t}"

I presume null means "use the snapshots.expiry default, and the other is a sentinel value which means “do not expire”. But it should be able to calculate the desired expiry time.

I notice this post, Documentation of 'snapshots.expiry' semantics which was not answered. With a bit of trial and error it’s possible to answer the questions. Failing that, check the code.

I am not too familiar with the expiry functionality. From what has been discussed thus far, what’s missing is only the client-side support to update the snapshots.expiry field on a snapshot, after the snapshot has been created?

Also, to be able to select the expiry at snapshot creation time.

At the moment you only have two options when creating a snapshot: say nothing, in which case you get an expiry based on the global snapshots.expiry setting; or --no-expiry.

I think we are at the stage to file an issue for a Feature request on Github for this.
It should be easy even to implement (by us).

Do you have the necessary information to file the issue?

I think it requires

incus snapshot create mysnapshot --expiry "2w"
incus snapshot update mysnapshot --expiry "3w"

Done. I have split into two:

2 Likes

In fact, you can already pass an absolute expiry time in YAML to incus snapshot create, if you know how to do it (the documentation doesn’t include an example)

root@nuc3:~# echo "expires_at: 2025-06-30T01:00:00Z" | incus snapshot create sftp test1
root@nuc3:~# incus snapshot list sftp
+-------+----------------------+----------------------+----------+
| NAME  |       TAKEN AT       |      EXPIRES AT      | STATEFUL |
+-------+----------------------+----------------------+----------+
| test1 | 2025/06/05 13:55 UTC | 2025/06/30 01:00 UTC | NO       |
+-------+----------------------+----------------------+----------+
1 Like