-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
forget: Add --max-age policy to set hard cutoff for removing snapshots #1735
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1735 +/- ##
==========================================
- Coverage 51.91% 46.91% -5.01%
==========================================
Files 148 148
Lines 11729 11733 +4
==========================================
- Hits 6089 5504 -585
- Misses 4693 5335 +642
+ Partials 947 894 -53
Continue to review full report at Codecov.
|
I'm okay with that in general, but I think we should consider a different name for the option. In the spirit of the other options, what about
I don't think this is possible yet. Can we please define what this option should do? It feels to me that this is an alternative to the other policy settings, instead of "keep 14 daily backups, delete everything else" you can then say "keep all snapshots newer than a year, delete everything else". So it would basically be incompatible to the other keep options... I'd expect at least to return an error to the user that this option is not compatible with the other ones. Or is it? Let's talk specifics: Let's say I have one snapshot for each day of the year 2017. At January 1st, 2018, I run For all combinations with the other
Tests need to be added here: https://github.com/restic/restic/blob/master/internal/restic/snapshot_policy_test.go#L176 |
I don't think it has to be. It can work alongside them and act as an extra filter; of the snapshots kept, do they fall within the timeframe specified? If not, forget; otherwise keep. It honestly sounds simple to me, but let me know if I'm missing something obvious.
Well,
Simple: it should keep all the weekly snapshots that remain (4 in this case) that are less than 1 year or 1 week old, respectively. It's just an extra filter, not incompatible with the existing ones. I like your idea to rename to |
There is now a test case! Thanks for the pointer. |
Ah, that's where this feature (as proposed) is incompatible with the current settings: The options we already have (like If I understood you correctly (please speak up if I got it wrong), then I think that's not a good behavior. I fear it will confuse users. If I understood you correctly, you'd like to use If so, I'd like to propose implementing this feature slightly different, in the same spirit as the other options (especially If you're only using There's another thing we need to take care of: By default, if there are no new snapshots (e.g. the With What about changing the behavior here again slightly, so that the use case I assume you're mainly interested in will work in the same way, but it's more conservative: Don't use the current timestamp for the age calculation, but the timestamp of the youngest snapshot restic can find. If you do daily snapshots, this won't make a difference, but if your backup isn't run, restic won't delete old snapshots. You see I spent some time thinking about this feature (during a walk), sorry for the long wall of text :) Getting What do you think? |
Ah, and I'm happy to help with the implementation, once we agree on how the new option should work ;) |
Oh... you know, you make some good points. I hadn't thought about unioning vs. intersecting, you're right, that's inconsistent. I am intrigued by the idea of using the most recent snapshot date as the basis for the age calculation. I think I like that more than using the current timestamp; if someone stopped making backups, there might be a serious reason/distress why, and they might not want to delete their older snapshots just because time rolled forward. Along these lines, a |
So, I went on a yak-shaving tour this morning, added a new type Sample, keep all snapshots within the last year, five months and 23 days of the latest snapshot:
If you agree this is a good change, we can merge it so it'll go into 0.9.0. |
Awesome. That looks like a great solution! I approve. One question to think about: will the "m" notation ever conflict with the "m" of the standard duration type which means minutes? I doubt it personally since I don't see minutes being particularly useful in this context. But the docs clarify what it means, so that looks good to me! |
forget: Add --max-age policy to set hard cutoff for removing snapshots
cool, merged! |
What is the purpose of this change? What does it change?
Adds a
--max-age
flag to theforget
command so that snapshots can be deleted simply if they are older than a certain duration.This is useful for keeping backup sizes under control and for a simple policy of "keeping deleted files for a certain time" i.e. a retention period.
It's possible that there is already a way to do it with existing policy flags and I am just not seeing it. If that's the case, feel free to teach me, and we can close this. :)
Still need to add docs... and tests.... not sure how to add a test for this though. But I did try it. :P Let me know if you have any ideas for that.
Was the change discussed in an issue or in the forum before?
I asked on the forum here: https://forum.restic.net/t/deleting-all-snapshots-older-than-a-certain-timestamp/611?u=matt
But then I tried implementing it which took only a few minutes, so here we are!
Checklist
changelog/unreleased/
that describes the changes for our users (template here)gofmt
on the code in all commits