Hello,

I've found it useful to verify my backups using 'svnadmin verify' and
thought it would make a good addition to hot-backup.py.

[[[
* tools/backup/hot-backup.py.in
    Added command line option "--verify".  If flag is present, the
hotcopy will be verified.
    Added a new pass between the existing steps 3 and 4 (hotcopy and
compress) that
    invokes 'svnadmin verify' on the hotcopy. If verification fails, the
script exits with an error.
]]]

Cheers,
Leo

Index: tools/backup/hot-backup.py.in
===================================================================
--- tools/backup/hot-backup.py.in       (revision 987343)
+++ tools/backup/hot-backup.py.in       (working copy)
@@ -106,6 +106,7 @@
                        zip  : Creates a compressed zip file.
                        zip64: Creates a zip64 file (can be > 2GB).
   --num-backups=N    Number of prior backups to keep around (0 to keep all).
+  --verify           Verify the hotcopy
   --help      -h     Print this help message and exit.
 
 """ % (scriptname,))
@@ -114,6 +115,7 @@
 try:
   opts, args = getopt.gnu_getopt(sys.argv[1:], "h?", ["archive-type=",
                                                       "num-backups=",
+                                                      "verify",
                                                       "help"])
 except getopt.GetoptError, e:
   sys.stderr.write("ERROR: %s\n\n" % e)
@@ -122,12 +124,15 @@
   sys.exit(2)
 
 archive_type = None
+verify_copy = False
 
 for o, a in opts:
   if o == "--archive-type":
     archive_type = a
   elif o == "--num-backups":
     num_backups = int(a)
+  elif o == "--verify":
+    verify_copy = True
   elif o in ("-h", "--help", "-?"):
     usage()
     sys.exit()
@@ -266,8 +271,19 @@
 else:
   print("Done.")
 
+### Step 4: Verify the hotcopy
+if verify_copy:
+  print("Verifying hotcopy...")
+  err_code = subprocess.call([svnadmin, "verify", "-q",
+                              backup_subdir])
+  if err_code != 0:
+    sys.stderr.write("Verifying the hotcopy `%s' failed.\n" % backup_subdir)
+    sys.stderr.flush()
+    sys.exit(err_code)
+  else:
+    print("Done.")
 
-### Step 4: Make an archive of the backup if required.
+### Step 5: Make an archive of the backup if required.
 if archive_type:
   archive_path = backup_subdir + archive_map[archive_type]
   err_msg = ""
@@ -321,7 +337,7 @@
     print("Archive created, removing backup '" + backup_subdir + "'...")
     safe_rmtree(backup_subdir, 1)
 
-### Step 5: finally, remove all repository backups other than the last
+### Step 6: finally, remove all repository backups other than the last
 ###         NUM_BACKUPS.
 
 if num_backups > 0:

Reply via email to