]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
consolidate: create multiple numbered backups of the original Archives directory...
authorBrian Warner <warner@allmydata.com>
Thu, 12 Mar 2009 23:04:27 +0000 (16:04 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 12 Mar 2009 23:04:27 +0000 (16:04 -0700)
src/allmydata/scripts/consolidate.py
src/allmydata/test/test_consolidate.py

index 5fccff3dc1bc7a85c24e9ef7bb8a911ac355c7bd..eea872c79f11e86b12d372bc91232cc31249c092 100644 (file)
@@ -89,10 +89,14 @@ class Consolidator:
         if not systems:
             self.msg("No systems under /Backups, nothing to consolidate")
             return 0
-        if not os.path.exists(self.backupfile):
-            f = open(self.backupfile, "wb")
-            pickle.dump(backup_data, f)
-            f.close()
+        backupfile = self.backupfile
+        counter = 0
+        while os.path.exists(backupfile):
+            backupfile = self.backupfile + "." + str(counter)
+            counter += 1
+        f = open(backupfile, "wb")
+        pickle.dump(backup_data, f)
+        f.close()
 
         for name, archives_dircap in sorted(systems.items()):
             self.do_system(name, archives_dircap)
index acc0f49f53af69697bde452687b81dc7bd764c56..6d7b6919be74211e0b9caff48321690f2c53b117 100644 (file)
@@ -179,7 +179,7 @@ class Consolidate(GridTestMixin, CLITestMixin, unittest.TestCase):
                                  "7 dirs created, 2 used as-is, 13 reused")
             self.failUnless(os.path.exists(dbfile))
             self.failUnless(os.path.exists(backupfile))
-            backup = pickle.load(open(backupfile, "rb"))
+            self.first_backup = backup = pickle.load(open(backupfile, "rb"))
             self.failUnless(u"fluxx" in backup["systems"])
             self.failUnless(u"fluxx" in backup["archives"])
             adata = backup["archives"]["fluxx"]
@@ -198,6 +198,9 @@ class Consolidate(GridTestMixin, CLITestMixin, unittest.TestCase):
             self.failUnlessEqual(last.strip(),
                                  "system done, "
                                  "0 dirs created, 0 used as-is, 0 reused")
+            backup = pickle.load(open(backupfile, "rb"))
+            self.failUnlessEqual(backup, self.first_backup)
+            self.failUnless(os.path.exists(backupfile + ".0"))
         d.addCallback(_check_consolidate_output2)
 
         d.addCallback(lambda ignored: self.build_manifest(self.nodes["Archives"]))