]> arthur.barton.de Git - bup.git/commitdiff
prune-older: keep most recent save in each period group
authorBen Kelly <bk@ancilla.ca>
Tue, 14 Mar 2017 16:29:04 +0000 (12:29 -0400)
committerRob Browning <rlb@defaultvalue.org>
Sun, 23 Apr 2017 20:19:29 +0000 (15:19 -0500)
Keep the most recent save in each period group (day, week, month, ...)
rather than the oldest.

Signed-off-by: Ben Kelly <btk@google.com>
[rlb@defaultvalue.org: adjust commit message]
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/prune-older-cmd.py
t/test-prune-older

index b340e017be1e27ff2cb78d6718f04e993427f5c2..fe45b95c4bef564b31429e5cf101ccc8aa7a3946 100755 (executable)
@@ -32,14 +32,11 @@ def classify_saves(saves, period_start):
     The ids are binary hashes.
     """
 
-    def retain_oldest_in_region(region):
-        prev = None
-        for save in region:
-            if prev:
-                yield False, prev
-            prev = save
-        if prev:
-            yield True, prev
+    def retain_newest_in_region(region):
+        for save in region[0:1]:
+            yield True, save
+        for save in region[1:]:
+            yield False, save
 
     matches, rest = partition(lambda s: s[0] >= period_start['all'], saves)
     for save in matches:
@@ -49,10 +46,12 @@ def classify_saves(saves, period_start):
                  (period_start['monthlies'], lambda s: localtime(s[0]).tm_mon),
                  (period_start['yearlies'], lambda s: localtime(s[0]).tm_year))
 
+    # Foreach period, seek back from now to the period's starting time, and
+    # collect the most recent saves
     for pstart, time_region_id in tm_ranges:
         matches, rest = partition(lambda s: s[0] >= pstart, rest)
         for region_id, region_saves in groupby(matches, time_region_id):
-            for action in retain_oldest_in_region(region_saves):
+            for action in retain_newest_in_region(list(region_saves)):
                 yield action
 
     for save in rest:
@@ -63,9 +62,9 @@ optspec = """
 bup prune-older [options...] [BRANCH...]
 --
 keep-all-for=       retain all saves within the PERIOD
-keep-dailies-for=   retain the oldest save per day within the PERIOD
-keep-monthlies-for= retain the oldest save per month within the PERIOD
-keep-yearlies-for=  retain the oldest save per year within the PERIOD
+keep-dailies-for=   retain the newest save per day within the PERIOD
+keep-monthlies-for= retain the newest save per month within the PERIOD
+keep-yearlies-for=  retain the newest save per year within the PERIOD
 wrt=                end all periods at this number of seconds since the epoch
 pretend       don't prune, just report intended actions to standard output
 gc            collect garbage after removals [1]
index 717e4ce8579aa307d30de44e12d040cc17fdbe62..c54865c95bd4ea7b80ca540981508ca170a4597f 100755 (executable)
@@ -101,17 +101,17 @@ def expected_retentions(utcs, utc_start, spec):
     utcs = list(dropwhile(lambda x: x >= period_start['all'], utcs))
 
     matches = takewhile(lambda x: x >= period_start['dailies'], utcs)
-    dailies = [min(day_utcs) for yday, day_utcs
+    dailies = [max(day_utcs) for yday, day_utcs
                in groupby(matches, lambda x: localtime(x).tm_yday)]
     utcs = list(dropwhile(lambda x: x >= period_start['dailies'], utcs))
 
     matches = takewhile(lambda x: x >= period_start['monthlies'], utcs)
-    monthlies = [min(month_utcs) for month, month_utcs
+    monthlies = [max(month_utcs) for month, month_utcs
                  in groupby(matches, lambda x: localtime(x).tm_mon)]
     utcs = dropwhile(lambda x: x >= period_start['monthlies'], utcs)
 
     matches = takewhile(lambda x: x >= period_start['yearlies'], utcs)
-    yearlies = [min(year_utcs) for year, year_utcs
+    yearlies = [max(year_utcs) for year, year_utcs
                 in groupby(matches, lambda x: localtime(x).tm_year)]
 
     return chain(all, dailies, monthlies, yearlies)