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

restic forget --keep-* options will interpret -1 as "forever" #4234

Merged

Conversation

thndrbrrr
Copy link
Contributor

@thndrbrrr thndrbrrr commented Mar 5, 2023

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

restic forget will interpret -1 as "forever" when used with --keep-* options. Using a value less than -1 will result in an error.

Note: This PR does not change the existing behaviour of --keep-within* options until it's decided how durations containing negative values should be handled (see my comment in #2565).

--keep-within* options containing negative values are considered invalid.

Documentation has not been updated (waiting on confirmation for this PR to go ahead).

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

Closes #2565 (if --keep-within-* options could be considered a different issue)

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.

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this issue! The code looks solid except for the comments below. Regarding --keep-within-*, I think restic should just return an error if any of them contains a negative duration. I don't see a use case in which that would make sense.

cmd/restic/cmd_forget.go Outdated Show resolved Hide resolved
cmd/restic/cmd_forget_test.go Outdated Show resolved Hide resolved
internal/restic/snapshot_policy.go Outdated Show resolved Hide resolved
internal/restic/snapshot_policy_test.go Outdated Show resolved Hide resolved
cmd/restic/cmd_forget_test.go Outdated Show resolved Hide resolved
@thndrbrrr
Copy link
Contributor Author

Thanks for the feedback, @MichaelEischer! I'll update the PR with the recommended changes. 👍

Tests in cmd_forget_test.go need the same convenience function
that was implemented in snapshot_policy_test.go.

Function parseDuration(...) was moved to testing.go  and renamed to
ParseDurationOrPanic(...).
- Convert policy sum calculation to function and move to tests.
- Remove parseDuration(...) and use ParseDurationOrPanic(...) instead.
@thndrbrrr
Copy link
Contributor Author

@MichaelEischer Alrighty, made the changes. This resulted in minor refactoring: had to move (and slightly change) a helper function from cmd_snapshots_test.go into testing.go.

@thndrbrrr
Copy link
Contributor Author

thndrbrrr commented Mar 15, 2023

Actually, I'll update this PR further with changes to func (e ExpirePolicy) String() (s string) to make command line output clearer. Right now an option like --keep-daily -1 prints Applying Policy: keep ... which misses an important point ... 😉

@thndrbrrr
Copy link
Contributor Author

Ok, updated PR. Options such as --keep-daily 7 --keep-yearly -1 --keep-monthly -1 --keep-hourly 24 for example will now print:

Applying Policy: keep 24 hourly, 7 daily, all monthly, all yearly snapshots

@thndrbrrr
Copy link
Contributor Author

@MichaelEischer Any feedback on the updated PR? Happy to update the docs if that's all that's misisng at this point.

@MichaelEischer
Copy link
Member

@thndrbrrr Sorry for the late reply, I've been far too busy during the last few weeks. Thanks for the changes, the code now looks good to me. The only two remaining todos are a short changelog entry (see template ) and a similar note in the documentation.

@thndrbrrr
Copy link
Contributor Author

@MichaelEischer Docs and changelog updated.

I updated the usage text as well, let me know if you're not happy with the wording:

$ ./restic forget -h
[...]
Usage:
  restic forget [flags] [snapshot ID] [...]

Flags:
  -l, --keep-last n                    keep the last n snapshots (use "-1" for n to keep all snapshots)
  -H, --keep-hourly n                  keep the last n hourly snapshots (use "-1" for n to keep all hourly snapshots)
  -d, --keep-daily n                   keep the last n daily snapshots (use "-1" for n to keep all daily snapshots)
  -w, --keep-weekly n                  keep the last n weekly snapshots (use "-1" for n to keep all weekly snapshots)
  -m, --keep-monthly n                 keep the last n monthly snapshots (use "-1" for n to keep all monthly snapshots)
  -y, --keep-yearly n                  keep the last n yearly snapshots (use "-1" for n to keep all yearly snapshots)

@thndrbrrr
Copy link
Contributor Author

@thndrbrrr Sorry for the late reply, I've been far too busy during the last few weeks.

No worries, I know how that feels ... 😆

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only have one small remaining nitpick. Besides that LGTM.

cmd/restic/cmd_forget.go Outdated Show resolved Hide resolved
@MichaelEischer MichaelEischer merged commit 913eab3 into restic:master Apr 14, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

restic forget --keep-* options must interpret -1 as "forever".
2 participants