-
Notifications
You must be signed in to change notification settings - Fork 219
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
fix: Smart Remove behavior to really "keep one snapshot per week for n weeks" #1819
Conversation
Okay, I see the failing unittest. I need to wrap my head around that :) |
Very cool. Also won't block this because of missing unit tests. I can take the refactoring and improving of the unit tests in a later step.
Must not be because of the Python version. To be sure please edit the |
I will also need to consider the impact of this change to existing archives with many snapshots. At first glance, no additional snapshots should be deleted as long as the duration considered by |
FYI: There is a new related issue #1874 . It is about smart remove with in leap years having a snapshot at 29th february. |
Hello, Can be found in draft PR #1944 |
It might be that the reported issue #1094 and your PR do focus on something on something else than I do report now. I was able to reproduce a problem. Based on that I tend to say that your PR won't fix that problem. Steps to reproduce:
Expected: Real/problematic behavior: I added your fix but the problematic behavior did not change. |
Short: This PR is ready merge by Michael. Long:
There is much more to discuss and decide in context of auto/smart remove. I will open a new meta issue for this. About the reproducible example I described myself:
What happens: Looking into the code that behavior seems to be intended by the original author. The algorithm starts in the current running (not yet complete) week, not the previous week. In my example there is no backup in the current week, so nothing to keep, but one iteration done. The next two iterations result in two backups to keep. That it. 3 iterations but only 2 backups to keep because in the first iteration (the current week) there was no backup available. Of course that behavior should be discussed. But not in this PR. Because all the other smart remove rules are affected. The entire system must be thoroughly researched, documented, and then rethought. If necessary, the behavior or wording in the GUI must be adjusted accordingly. |
@@ -1683,7 +1683,7 @@ def smartRemoveList(self, | |||
keep |= self.smartRemoveKeepFirst( | |||
snapshots, | |||
d, | |||
d + datetime.timedelta(days=8), | |||
d + datetime.timedelta(days=7), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing the original code (especially smartRemoveKeepFirst()
) and its behavior I am quit sure this wont work as intended. The two parameters in smartRemoveKeepFirst()
, min_date
and max_date
are used like this:
d >= min_date and d < max_date
Because of the latest operator <
a range of 8
is IMHO fine.
I will improve the test situation in near future. But I also have to do some refactoring first. So this topic won't be lost.
Closing this based on the comment above. |
Smart Remove doesn't actually "keep one snapshot per week for the last n weeks", as the setting indicates. Instead, it only works for n–1 weeks.
The deeper reason is that at one point, the Smart Remove code considers a "week" to span 8 days:
backintime/common/snapshots.py
Lines 1689 to 1697 in 22f468c
This leads to the loss of the oldest snapshot in the last of the weeks to be considered. For details, see the discussion in #1094.
Git blame shows that this code has been unchanged since the "keep one snapshot per week for the last n weeks" function was first introduced in 2010 (version 1.0.6). It has probably had this bug since the beginning.
While here, improve debug logging of some Smart Remove functions to print SIDs
.withoutTag
, because they represent date boundaries only (and the randomly assigned tags contain no information related to any real snapshots). Most of the Smart Remove code already does this.Fixes #1094.