From 1fea10bc03d8e5c6fcba1506c9771a04827141de Mon Sep 17 00:00:00 2001 From: Ryan Tucker Date: Thu, 18 Feb 2010 15:34:58 -0500 Subject: [PATCH] more accurate backup age handling; also nuking the .COMPLETE file on a delete --- backup-manager.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backup-manager.py b/backup-manager.py index a8048e8..952b1db 100755 --- a/backup-manager.py +++ b/backup-manager.py @@ -71,12 +71,15 @@ def list_backups(bucket): if hostname in backups.keys(): if not backupnum in backups[hostname].keys(): - backups[hostname][backupnum] = {'date': lastmod, 'hostname': hostname, 'backupnum': backupnum, 'finalized': 0, 'keys': []} + backups[hostname][backupnum] = {'date': lastmod, 'hostname': hostname, 'backupnum': backupnum, 'finalized': 0, 'keys': [], 'finalkey': None} else: - backups[hostname] = {backupnum: {'date': lastmod, 'hostname': hostname, 'backupnum': backupnum, 'finalized': 0, 'keys': []}} + backups[hostname] = {backupnum: {'date': lastmod, 'hostname': hostname, 'backupnum': backupnum, 'finalized': 0, 'keys': [], 'finalkey': None}} if final: backups[hostname][backupnum]['finalized'] = lastmod + backups[hostname][backupnum]['finalkey'] = key else: + if lastmod < backups[hostname][backupnum]['date']: + backups[hostname][backupnum]['date'] = lastmod backups[hostname][backupnum]['keys'].append(key) return backups @@ -234,11 +237,10 @@ def main(): backups = hostnames[hostname] for backupnum in backups.keys(): filecount = len(backups[backupnum]['keys']) + datestruct = backups[backupnum]['date'] if backups[backupnum]['finalized'] > 0: - datestruct = backups[backupnum]['finalized'] inprogress = '' else: - datestruct = backups[backupnum]['date'] inprogress = '*' timestamp = time.mktime(datestruct) delta = int(time.time() - timestamp + time.timezone) @@ -282,6 +284,9 @@ def main(): else: key.delete() sys.stdout.write('.') + if backups[backupnum]['finalkey']: + backups[backupnum]['finalkey'].delete() + sys.stdout.write('!') sys.stdout.write('\n') elif options.host and options.backupnum: for bucket in buckets: @@ -310,6 +315,9 @@ def main(): else: key.delete() sys.stdout.write('.') + if backups[backupnum]['finalkey']: + backups[backupnum]['finalkey'].delete() + sys.stdout.write('!') sys.stdout.write('\n') else: parser.error('Host %s not found' % options.host)