rdiff-backup-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Rdiff-backup-commits] rdiff-backup CHANGELOG rdiff_backup/Main.py rdi..


From: Andrew Ferguson
Subject: [Rdiff-backup-commits] rdiff-backup CHANGELOG rdiff_backup/Main.py rdi...
Date: Sun, 12 Oct 2008 02:21:30 +0000

CVSROOT:        /sources/rdiff-backup
Module name:    rdiff-backup
Changes by:     Andrew Ferguson <owsla> 08/10/12 02:21:30

Modified files:
        .              : CHANGELOG 
        rdiff_backup   : Main.py Security.py rpath.py 

Log message:
        Automatically resume after a failed initial backup. (Patch from Josh 
Nisly)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/CHANGELOG?cvsroot=rdiff-backup&r1=1.311&r2=1.312
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff_backup/Main.py?cvsroot=rdiff-backup&r1=1.120&r2=1.121
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff_backup/Security.py?cvsroot=rdiff-backup&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff_backup/rpath.py?cvsroot=rdiff-backup&r1=1.130&r2=1.131

Patches:
Index: CHANGELOG
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/CHANGELOG,v
retrieving revision 1.311
retrieving revision 1.312
diff -u -b -r1.311 -r1.312
--- CHANGELOG   12 Oct 2008 01:55:29 -0000      1.311
+++ CHANGELOG   12 Oct 2008 02:21:28 -0000      1.312
@@ -1,6 +1,8 @@
 New in v1.2.2 (????/??/??)
 ---------------------------
 
+Automatically resume after a failed initial backup. (Patch from Josh Nisly)
+
 Improve compatibility between Unix and remote native Windows client. It is now
 possible to use SSH daemons other than Putty on Windows. (Andrew Ferguson)
 

Index: rdiff_backup/Main.py
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/Main.py,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -b -r1.120 -r1.121
--- rdiff_backup/Main.py        7 Oct 2008 23:45:41 -0000       1.120
+++ rdiff_backup/Main.py        12 Oct 2008 02:21:29 -0000      1.121
@@ -380,6 +380,44 @@
                Log.FatalError("Source %s is not a directory" % rpin.path)
        Globals.rbdir = rpout.append_path("rdiff-backup-data")
 
+def check_failed_initial_backup():
+       """Returns true if it looks like initial backup failed."""
+       if Globals.rbdir.lstat():
+               rbdir_files = Globals.rbdir.listdir()
+               mirror_markers = filter(lambda x: 
x.startswith("current_mirror"),
+                                                               rbdir_files)
+               error_logs = filter(lambda x: x.startswith("error_log"),
+                                                       rbdir_files)
+               metadata_mirrors = filter(lambda x: 
x.startswith("mirror_metadata"),
+                                                               rbdir_files)
+               # If we have no current_mirror marker, and the increments 
directory
+               # is empty, we most likely have a failed backup.
+               return not mirror_markers and len(error_logs) <= 1 and \
+                               len(metadata_mirrors) <= 1
+       return False
+
+def fix_failed_initial_backup():
+       """Clear Globals.rbdir after a failed initial backup"""
+       Log("Found interrupted initial backup. Removing...",  2)
+       rbdir_files = Globals.rbdir.listdir()
+       # Try to delete the increments dir first
+       if 'increments' in rbdir_files:
+               rbdir_files.remove('increments')
+               rp = Globals.rbdir.append('increments')
+               try:
+                       rp.conn.rpath.delete_dir_no_files(rp)
+               except rpath.RPathException:
+                       Log("Increments dir contains files.", 4)
+                       return
+               except Security.Violation:
+                       Log("Server doesn't support resuming.", 2)
+                       return
+       
+       for file_name in rbdir_files:
+               rp = Globals.rbdir.append_path(file_name)
+               if not rp.isdir(): # Only remove files, not folders
+                       rp.delete()
+
 def backup_set_rbdir(rpin, rpout):
        """Initialize data dir and logging"""
        global incdir
@@ -400,6 +438,8 @@
 rdiff-backup like this could mess up what is currently in it.  If you
 want to update or overwrite it, run rdiff-backup with the --force
 option.""" % rpout.path)
+       elif check_failed_initial_backup():
+               fix_failed_initial_backup()
 
        if not Globals.rbdir.lstat(): Globals.rbdir.mkdir()
        SetConnections.UpdateGlobal('rbdir', Globals.rbdir)

Index: rdiff_backup/Security.py
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/Security.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- rdiff_backup/Security.py    20 Aug 2008 17:43:25 -0000      1.36
+++ rdiff_backup/Security.py    12 Oct 2008 02:21:30 -0000      1.37
@@ -45,7 +45,8 @@
                                 'os.chown':0, 'os.remove':0, 'os.removedirs':0,
                                 'os.rename':0, 'os.renames':0, 'os.rmdir':0, 
'os.unlink':0,
                                 'os.utime':0, 'os.lchown':0, 'os.link':1, 
'os.symlink':1,
-                                'os.mkdir':0, 'os.makedirs':0}
+                                'os.mkdir':0, 'os.makedirs':0,
+                                'rpath.delete_dir_no_files':0}
                                 
 def initialize(action, cmdpairs):
        """Initialize allowable request list and chroot"""
@@ -180,6 +181,7 @@
        if sec_level == "all":
                l.extend(["os.mkdir", "os.chown", "os.lchown", "os.rename",
                                  "os.unlink", "os.remove", "os.chmod", 
"os.makedirs",
+                                 "rpath.delete_dir_no_files",
                                  "backup.DestinationStruct.patch",
                                  "restore.TargetStruct.get_initial_iter",
                                  "restore.TargetStruct.patch",

Index: rdiff_backup/rpath.py
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/rpath.py,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -b -r1.130 -r1.131
--- rdiff_backup/rpath.py       12 Oct 2008 01:55:29 -0000      1.130
+++ rdiff_backup/rpath.py       12 Oct 2008 02:21:30 -0000      1.131
@@ -372,6 +372,14 @@
        else: basestr = ".".join(dotsplit[:-2])
        return (compressed, timestring, ext, basestr)
 
+def delete_dir_no_files(rp):
+       """Deletes the directory at rp.path if empty. Raises if the
+       directory contains files."""
+       assert rp.isdir()
+       if rp.contains_files():
+               raise RPathException("Directory contains files.")
+       rp.delete()
+
 
 class RORPath:
        """Read Only RPath - carry information about a path
@@ -1047,6 +1055,21 @@
                else: self.conn.os.unlink(self.path)
                self.setdata()
 
+       def contains_files(self):
+               """Returns true if self (or subdir) contains any regular 
files."""
+               log.Log("Determining if directory contains files: %s" % 
self.path, 7)
+               if not self.isdir():
+                       return False
+               dir_entries = self.listdir()
+               for entry in dir_entries:
+                       child_rp = self.append(entry)
+                       if not child_rp.isdir():
+                               return True
+                       else:
+                               if child_rp.contains_files():
+                                       return True
+               return False
+
        def quote(self):
                """Return quoted self.path for use with os.system()"""
                return '"%s"' % self.regex_chars_to_quote.sub(




reply via email to

[Prev in Thread] Current Thread [Next in Thread]