From cf780c1f41a15b527429b7b2b0a32bf000c4a95f Mon Sep 17 00:00:00 2001 From: Ciro Scognamiglio Date: Wed, 11 Jul 2012 17:40:17 +0200 Subject: [PATCH] added option to move file --- scripts/clean-backupdb.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/clean-backupdb.py b/scripts/clean-backupdb.py index 3aeae15..4fcbb06 100755 --- a/scripts/clean-backupdb.py +++ b/scripts/clean-backupdb.py @@ -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 instead of removing the file") parser.add_option ("-o","--offset",dest='offset',action='store',type='int',default=0, help="pretend we run 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) -- 2.43.0