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