Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent unsafe uses of forget --keep-tag #4764

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MichaelEischer
Copy link
Member

@MichaelEischer MichaelEischer commented Apr 15, 2024

What does this PR change? What problem does it solve?

Currently it is possible to accidentally remove all snapshots using e.g. forget --keep-tag invalid where invalid is a not existing tag. This is particularly problematic when making typos in the tag name.

This PR changes the behavior as follows:

  • If --keep-tag x were to cause all snapshots in a snapshot group to be removed, then forget will fail with an error
  • forget fails with an error if no keep policy was specified instead of just printing a warning
  • Add a new --unsafe-allow-remove-all option. To use the --unsafe-allow-remove-all option a snapshot filter (host, path or tag) must be specified. forget --tag x --unsafe-allow-remove-all can for example be used to remove all snapshots with a specific tag.

This is slightly more restrictive than my suggestion in #4568 (review) . That also allowed forget --keep-tag invalid --unsafe-allow-remove-all (deletes the whole repository as is currently the case) which won't be allowed in the current version of the PR. It also blocks forget --keep-tag some --unsafe-allow-remove-all where some is a tag only used by some snapshot groups. The latter might be relevant for some use cases, although I'm not sure what those would look like.

I'll likely also split this PR into two parts, one to fix the --keep-tag bug and one to add the --unsafe-allow-remove-all option.

Was the change previously discussed in an issue or on the forum?

Replaces #4568
Fixes #4569
See also https://forum.restic.net/t/delete-all-snapshots-in-one-command-is-this-feature-intentional/6923/3

Checklist

  • I have read the contribution guidelines.
  • I have enabled maintainer edits.
  • I have added tests for all code changes.
  • I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I have run gofmt on the code in all commits.
  • All commit messages are formatted in the same style as the other commits in the repo.
  • I'm done! This pull request is ready for review.

`--keep-tag invalid-tag` was previously able to wipe all snapshots in a
repository. As a user specified a `--keep-*` option this is likely
unintentional. This forbid deleting all snapshot if a `--keep-*` option
was specified to prevent data loss. (Not specifying such an option
currently also causes the command to abort)
To prevent accidentally wiping all snapshots from a repository, that
option can only be used if either a snapshot filter or a keep policy is
specified.

Essentially, the option allows `forget --tag something
--unsafe-allow-remove-all` calls to remove all snapshots with a specific
tag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

restic forget --keep-tag NonExistingTag drops all snapshots
1 participant