Commits

Tino de Bruijn committed 48b4bd5

Cleanup tar.gz files after uploading

Comments (0)

Files changed (1)

s3backup/__init__.py

+import os
 import subprocess
 import datetime
 import tarfile
     def compress_dumps(self, dumps):
         """tar.gz compress the local dumps"""
         now = datetime.datetime.now()
-        name = self.backup_prefix + now.strftime("%Y-%m-%d_%H-%M-%S.tar.gz")
+        name = self.backup_prefix + now.strftime("%Y-%m-%d_%H:%M:%S.tar.gz")
         tar = tarfile.open(self.backup_dir / name, 'w:gz')
         for dump in dumps:
             tar.add(dump)
         last_backups_file.close()
         last_backups_remote.set_contents_from_filename(last_backups_file.name)
         
+        # Cleanup
+        self.cleanup(filename)
+        
         return new_key.name
+        
+    def cleanup(self, filename):
+        try:
+            os.remove(filename)
+        except OSError, e:
+            log.warning('Could not cleanup: %s' % e)
     
     def backup(self, prefix='daily'):
         dumps = self.dump_databases()