rsync-snapshot: fix clean_interval to actually clean up the oldest snapshots, not the newest ones..
authorTero Marttila <terom@paivola.fi>
Fri, 02 Mar 2012 15:58:45 +0200
changeset 31 e946c741c500
parent 30 29b60df79122
child 32 9d623185d3d7
rsync-snapshot: fix clean_interval to actually clean up the oldest snapshots, not the newest ones..
scripts/pvlbackup-rsync-snapshot
--- a/scripts/pvlbackup-rsync-snapshot	Fri Mar 02 15:52:25 2012 +0200
+++ b/scripts/pvlbackup-rsync-snapshot	Fri Mar 02 15:58:45 2012 +0200
@@ -470,15 +470,17 @@
         # configured
         keep = interval.keep
 
-        # clean?
+        # items to clean?
         items = os.listdir(dir_path)
-        items.sort()
+
+        # sort newest -> oldest
+        items.sort(reverse=True)
 
         log.info("%s: Have %d / %d items", interval, len(items), keep)
         log.debug("%s: items: %s", interval, ' '.join(items))
 
         if len(items) > keep :
-            # clean out
+            # select oldest ones
             clean = items[keep:]
 
             log.info("%s: Cleaning out %d items", interval, len(clean))
@@ -489,8 +491,11 @@
 
                 log.info("%s: Clean: %s", interval, path)
 
-                os.unlink(path)
-
+                if not options.dry_run :
+                    log.debug("rmtree: %s", path)
+                    os.unlink(path)
+                else :
+                    log.debug("dryrun: %s", path)
 
     def clean_snapshots (self, options) :
         """