Clarification about forget --keep-tag?

I want to remove all snapshots in my repo which have no tags.

Running restic forget --help I see this:

–keep-tag taglist — keep snapshots with this taglist (can be specified multiple times) (default )

I’m just wondering whether this “taglist” is “OR-ed” or “AND-ed”… ? If I specify multiple tags here, does this mean

A) that only snapshots with ALL these tags will be kept?
Or
B) does it mean that any snapshot with at least ONE of these tags will be kept?

PS maybe I’m not very clever but can you explain what “can be specified multiple times” here means? If the answer to the above question is A), does this then mean that you can have multiple “–keep-tag” switches in the same command line? This (multiple identical switches in the same command line) would be quite unusual …

… which is why I’m asking for this clarification.

Both OR and AND are possible.
--keep-tag foo,bar keeps snapshots with both tags (AND), whereas --keep-tag foo --keep-tag bar keeps snapshots with any of these tags (OR).

If you’re experimenting with flags for the forget command, make sure to pass the --dry-run flag until you are sure that the flags do what you intended.

Is this correct? I tested this, but can not confirm that. It seems to be OR only.

$ restic snapshots                     
repository a14e5863 opened (version 2, compression level auto)
ID        Time                 Host        Tags        Paths
----------------------------------------------------------------------------------------------
37c409dc  2023-04-07 12:14:17  host        foo         /restic/test/tmp
fb0a73f9  2023-04-07 12:14:21  host        foo,bar     /restic/test/tmp
0808898d  2023-04-07 12:14:24  host        bar         /restic/test/tmp
abb3f329  2023-04-07 12:14:26  host                    /restic/test/tmp
----------------------------------------------------------------------------------------------
4 snapshots
$ restic forget --dry-run --keep-tag foo,bar           
repository a14e5863 opened (version 2, compression level auto)
Applying Policy: keep all snapshots with tags [[foo, bar]]
keep 1 snapshots:
ID        Time                 Host        Tags        Reasons              Paths
------------------------------------------------------------------------------------------------------------------
fb0a73f9  2023-04-07 12:14:21  host        foo,bar     has tags [foo, bar]  /restic/test/tmp
------------------------------------------------------------------------------------------------------------------
1 snapshots

remove 3 snapshots:
ID        Time                 Host        Tags        Paths
---------------------------------------------------------------------------------------------
37c409dc  2023-04-07 12:14:17  host        foo         /restic/test/tmp
0808898d  2023-04-07 12:14:24  host        bar         /restic/test/tmp
abb3f329  2023-04-07 12:14:26  host                    /restic/test/tmp
---------------------------------------------------------------------------------------------
3 snapshots

Would have removed the following snapshots:
{0808898d 37c409dc abb3f329}
$ restic forget --dry-run --keep-tag foo --keep-tag bar
repository a14e5863 opened (version 2, compression level auto)
Applying Policy: keep all snapshots with tags [[foo] [bar]]
keep 3 snapshots:
ID        Time                 Host        Tags        Reasons         Paths
-------------------------------------------------------------------------------------------------------------
37c409dc  2023-04-07 12:14:17  host        foo         has tags [foo]  /restic/test/tmp
fb0a73f9  2023-04-07 12:14:21  host        foo,bar     has tags [foo]  /restic/test/tmp
                                                       has tags [bar]
0808898d  2023-04-07 12:14:24  host        bar         has tags [bar]  /restic/test/tmp
-------------------------------------------------------------------------------------------------------------
3 snapshots

remove 1 snapshots:
ID        Time                 Host        Tags        Paths
---------------------------------------------------------------------------------------------
abb3f329  2023-04-07 12:14:26  host                    /restic/test/tmp
---------------------------------------------------------------------------------------------
1 snapshots

Would have removed the following snapshots:
{abb3f329}
1 Like

@MichaelEischer You are right. I made a mistake. Sorry for wasting your time! Appreciate your patience with a newbie!

cc @creativeprojects because this seems to be an issue in resticprofile.

Fred, it seems that it is not possible to specify the OR behavior in the config file. In order to get OR you would have to set the parameter keep-tag multiple times. But when I tried I got this error message.

cannot load configuration file:
cannot parse yaml configuration:
While parsing config: yaml: unmarshal errors:
line 23: mapping key "keep-tag" already defined at line 22

Is there another way? Or is it simply a bug in resticprofile. Using an array for the keep-tag parameter would lead to AND behavior (single --keep-tag parameter with multiple tags) . I suspect that most people would prefer OR.

Well spotted, this is actually a bug that was introduced in the latest version.

Before 0.21.0 it was simply copying the configuration flags to the command line as-is, but now it’s trying to check that these flags are valid :stuck_out_tongue:

Great. Will be waiting for the next version then. Thanks.