How to delete snaphots older than 1 month

Hey, I’m new to restic. From what I see so far it looks amazing.

I’m confused on how to remove snapshots. What I’d like to do is to delete any snapshots older than 1 month, and keep all snapshots within 1 month from the current calendar date.

Thank you!

There’s currently no option doing exactly that. You can achieve something similar using --keep-within x which keeps snapshot not older than x relative to the latest snapshot in a group of snapshots.

And there’s a feature request which sounds similar to what you’re looking for:

1 Like

Thanks Michael.

Any idea on when this feature would be implemented?

@timsimon What problem are you trying to solve by wanting to “delete any snapshots older than 1 month, and keep all snapshots within 1 month from the current calendar date”?

Imagine what will happen when you for some reason have had failed backup runs for a month - you will end up with almost no snapshots at all (only the very last one, since restic keeps it as a precaution - you have to explicitly delete it if you want to get rid of it).

The --keep-within option @MichaelEischer mentioned is designed the way he mentioned for a good reason. If you use it, you will make sure that you always have at least one month worth of snapshots (as most recent as possible).

2 Likes

Hi, maybe I’m confused then :confused:

I have a script that runs restic every 3 days to backup all my folders.

Every 2 months or so, I wish to remove older snapshots and just keep the most current ones (say for the past 4 weeks) - so stop my disk space from being over-filled.

In that case, I suggest that you follow the previous suggestions, and run

restic forget --dry-run --keep-within 2m

2m refers to within 2 months of your most recent snapshot, and as @rawtaz mentioned, there are good reasons for using the time of most recent snapshot rather than the time at which you run restic forget. The reason is that if there are no recent snapshots this ensures that you will never be able to delete all of your snapshots using this command.

If you run this immediately after doing a backup, however, this is pretty identical to removing all snapshots older than 2 months, because the most recent snapshot is only minutes old.

If you like the output of the above command, run it again without the --dry-run parameter, to actually remove the snapshots from the repository.

3 Likes

OK thanks for the help. I will do that with a --dry-run first

2 Likes

Sorry about resurrecting old thread, but problem with current options still is that if the set of paths change on hosts (that are being backed up, e.g. month is included in path selector), the result is that old snapshots hang around forever.

I have sort of migrated away from that (to using excludes instead of explicitly selecting paths), but it is still bit awkward and I don’t know why I have backups from 2024 still lingering despite keep monthly 3 / keep last 5 (as of June 2025). In practice I know that either hostname or paths have changed, but this leads to manual work pruning snapshots which I do not want to do.

I guess I could write a tool which does this, but it feels unnecessary.

In such case do not rely on default path/host snapshots grouping but use tags. Then you can have full control on which snapshots are included in your forget command.

See docs for details.

That was just one example. There is also e.g. hostname deltas due to reinstallations or misconfiguration (host.fqdn versus host.lan versus host.local versus host), and so on.

When dealing with secondary online backup storage, I’d rather just ‘delete everything older than 3 months’ as by that time I most definitely have backed any device I care about to my primary storage (which is then replicated to N other places).

Both use restic, and I don’t really care about primary storage bloating up, but secondary one I have hard size limit for and the current behaviour makes it bit frustrating to maintain.

(I backup handful of machines there, so all sort of oddities do crop up, and dealing with them manually feels excessive.)

I guess plan B would be just to ensure that when everything is backed to primary storage, and secondary storage is too big, nuke the secondary and start from scratch /but that’s lots of upload I’d rather not do.

@fingon Does restic forget -n --group-by '' --keep-within 3m not work for you (to forget snapshots older than one month regardless of host/tag/path)?