Remove snapshots older then x from current date

Is there a way, just like --keep-within, but which isn’t relative to the last snapshot but to the current time?

I’m currently developing an integration with hosting software and removed users are now left in the backups forever. Every user has its own tag, and no new snapshots are being made for that user, so the --keep-within policy doesn’t apply to it.

Is there a way in restic to do this automatically? Otherwise I need to do this manually.

Lastly, thanks for this awesome peace of software. Has been a great pleasure using it thus far with implementing it. Thanks! :slight_smile:

1 Like

I’m not aware of any feature like this. On the off-chance that you don’t know about --json, you can run restic snapshots --json to get a JSON dump of the snapshots if you want to implement this feature as an external script.

Welcome to the forum!

As @cdhowie said, there’s not such feature built into restic, but you could do that yourself by parsing restic snapshots --json and then calling restic forget <id> <id2> [...].

The reason restic uses the timestamp for the last backup is safety: if no new backups are made, restic should not automatically remove backup after backup until none are available any more. That’s the safest thing to do.

If you want to remove all snapshots with a given tag, you can use restic forget --tag foo -keep-last 1 (which will remove all but the last one) and remove the last one manually. For safety reasons we don’t allow --keep-last 0 as well :wink:

1 Like

Thanks for the responses! Unfortunate to hear, but I understand why the feature isn’t there. I will build it in the integration itself for now :smiley: .

I found --json in the docs, yeah. A really useful feature which I’m already using in the application.

Thanks! :slight_smile: