Merge branch 'master' of git.onelab.eu:/git/infrastructure
authorCiro Scognamiglio <c.scognamiglio@cslash.net>
Wed, 11 Jul 2012 15:50:18 +0000 (17:50 +0200)
committerCiro Scognamiglio <c.scognamiglio@cslash.net>
Wed, 11 Jul 2012 15:50:18 +0000 (17:50 +0200)
scripts/clean-backupdb.py

index 3aeae15..4fcbb06 100755 (executable)
@@ -151,12 +151,19 @@ class File:
     def cleanup (self, preserved):
         global counter
         counter+=1
-        if self.options.dry_run:
-            print "Would cleanup %s"%(self.path())
-            print "    (keeping %s)"%preserved.path()
+        if self.options.destination:
+            dst = os.path.abspath(self.options.destination) + '/' + os.path.basename(self.path())
+            if self.options.verbose:
+                print "moving %s\n\tto %s"%(self.path(), dst)
+            if not self.options.dry_run:
+                os.rename (self.path(), dst)
         else:
-            if self.options.verbose: print "unlink",self.path()
-            os.unlink (self.path())
+            if self.options.dry_run:
+               print "Would cleanup %s"%(self.path())
+               print "    (keeping %s)"%preserved.path()
+            else:
+                if self.options.verbose: print "unlink",self.path()
+                os.unlink (self.path())
 
 # all files in a given timeslot (either month or week)
 class Group:
@@ -295,6 +302,8 @@ def main ():
                        help="run in extra verbose mode")
     parser.add_option ("-n","--dry-run",dest='dry_run',action='store_true',default=False,
                        help="dry run")
+    parser.add_option ("-m","--move-to",dest='destination',action='store',type='string',default=False,
+                       help="move to <destination> instead of removing the file")
     parser.add_option ("-o","--offset",dest='offset',action='store',type='int',default=0,
                        help="pretend we run <offset> days in the future")
     (options, args) = parser.parse_args()
@@ -308,6 +317,10 @@ def main ():
         print "Offset not understood %s - expect an int. number of days"%options.offset
         sys.exit(1)
     
+    if options.destination and not os.path.isdir(options.destination):
+        print "Destination should be a directory"
+        sys.exit(1)
+
     if len(args) ==0:
         parser.print_help()
         sys.exit(1)