Forgetting all snapshots with a specific tags

I’ve not been able to figure out how to forget ALL snapshots with a specific tag. Is it possible? I can remove all except for the very last one …

restic forget --tag tmp -l 1 -g tags

and it’s quite involved

Yep, that’s the easiest way to remove all snapshots with a given tag. The idea of the forget command is to specify a retention policy, forgetting all snaphots which match some criteria is not its primary focus. So you have to bend it a little bit. Alternatively, you could use restic snapshots --json, filter the output e.g. with jq, and pass the IDs of the snapshots you’d like to forget to restic forget.

wouldn’t forget all given matching tags qualify as a retention policy ? retain none

Let me clarify my use case.

In stead of doing a huge backup at once spanning a long time, I broke it into smaller chunks that could finish when I wasn’t using my bandwidth for work.

I marked all such backups with the tmp tag with the idea of adding them to my monthly backup (monthly tag) that would be able to finish quickly later due to de-dup.

then I went back to delete all the backups with the tmp tag.

I understand what you’re trying to do. For safety reasons, a policy that retains no snapshots at all for a given list of snapshots is not considered valid, so restic refuses to do anything. For such a situation I think it’s not too much to ask from users to forget all but the last of the tagged snapshots, and remove that one by hand. :slight_smile:


Restic is designed for container use. And containers stand for a high degree of automation. In this context I find the suggestion to delete the snapshot manually somewhat inappropriate. I would also like to have the possibility to delete a shapshot with a specific tag.

I would like to use it to eliminate corrupt backups that can occur when using “–stdin”.

Interesting, where did you get that? While restic can be used with containers, first and foremost it was designed with my personal use case in mind. So your statement is incorrect :slight_smile:

For every command, feature, and flag that we offer we need to balance several competing things, among others: usability, maintainability, complexity, and safety. The forget command works in two ways:

  • Delete all snapshots passed as arguments
  • Apply a retention policy

I think it’s an appropriate safety feature to make sure a retention policy is valid, which also includes that at least one snapshot is kept. I also don’t think my comment outlining a solution is “inappropriate”, apparently we disagree here.

If you need more fine-grained control over what snapshots are kept, restic offers a machine-readable list of snapshots (restic snapshots --json) that you can parse with a script and decide for yourself which snapshots to remove (then forget is used in the former mode). This gives you absolute freedom to implement any retention policy and keeps restic’s code and complexity under control.

To my surprise, it turned out that the rules forget has were among the most complex things to implement in restic (together with file exclusion rules), and I like to keep this complexity under control by not adding new features if we can avoid it.


I have used this command to get all snapshots by a specific tag and extract the “id’s” and pass them as a string split by " " (a space).

restic forget $(restic snapshots --tag testing-backup-script --json | jq '.[] | .short_id' | jq -s | jq -r 'join(" ")')

As I didnt found anything similiar, I have wrote the command by my self at the end.
Maybe this can help someone else :slight_smile:
But I’m not sure if its a good idea, to revive this old topic…

1 Like

Thanks for this :wink:

Hmm, maybe I’m missing something, but to delete all snapshots with a given tag is rather straightforward as far as I know. It just requires two forget commands both of which can be automated, so no need for anything done manually.

First, delete all but the last snapshot with the given tag:

restic forget --group-by host --tag exampleTag --keep-last 1

and then forget the last one:

restic forget latest --group-by host --tag exampleTag

Now all snapshots which had the tag “exampleTag” will be forgotten, irrespective of their paths.

1 Like

You’re missing something but it’s not my use case anymore as the post was three years ago

Hi @foolsgold , I understand it may not be your use case anymore, but other people may come here in search of answers, even a long time after the initial question, so it would be rather helpful if you could share what I am missing or what is not correct with my proposed two forget statements…


While I wish restic did this natively, I didn’t put it together that latest could be used here, so, thanks for this post – While the json method might work fine, that isn’t something I can type from memory and so it ends up being less work to just do it manually (by ID), this will be quicker,.


I am relatively new to restic and began adding tags to my snapshots in the apparently mistaken belief that I could delete them by tag. When I hit problems I came here looking for help but found only disappointment. But now I reckon I have come up with a solution. The original poster’s problem to delete snapshots with the tag tmp can be dealt with like this :

restic forget --keep-tag=anytag --tag=tmp

which is much simpler than any suggestion I’ve seen. It specifies a retention policy and conveniently anytag doesn’t even need to exist.


Great trick !

I’ve now discovered that ‘anytag’ in my solution in post #14 isn’t actually necessary, so

restic forget --keep-tag= -tag=tmp

is sufficient to remove snapshots with tag ‘tmp’.

It is kind of funny that the official claim is that restic doesn’t support removing all snapshots of a given policy for safety reasons.
Yet users are still trying to find ways how to do it nevertheless, and, if you use restic forget --keep-tag=existing_tag_mistyped, restic will even remove all snapshots of the whole repository…

Not sure why you think that is funny. If restic is designed to protect against accidental removal of all snapshots and fails to do so for a small part of the policy specifications, this is clearly a bug or oversight.

This is also why forget --dry-run exists, so that one doesn’t accidentally remove all snapshots – one should always --dry-run policies before applying them for real.

1 Like

@rawtaz I personally think this is kind of funny, as it obviously falls in the “it’s a bug, not a feature” category :slight_smile:

In my quest to find an answer to the question of how to delete all snapshots with a given tag with a single command I have come up with a couple of variations on a theme for different circumstances. First:

restic forget --keep-tag=other --tag=other --tag=tmp

is appropriate if every snapshot is tagged (my situation) and there is at least one other tag; I can’t imagine why anyone would tag all snapshots with the same tag. And secondly:

restic forget --keep-tag=‘’ --tag=‘’ --tag=tmp

is appropriate in all other cases, where there will be a mixture of tagged and untagged, although the version above could also be used in some of them.

If these are legit - and I don’t understand why they wouldn’t be - they seem so obvious now. I had hoped there might be a better way than deleting all but one followed by deleting it by hand, and I hope I’ve now found it even though I had been using a single-command scripted solution built using Unix filters.