diff options
-rw-r--r-- | rdiff-backup/rdiff_backup/Main.py | 54 | ||||
-rw-r--r-- | rdiff-backup/rdiff_backup/highlevel.py | 45 | ||||
-rw-r--r-- | rdiff-backup/testing/commontest.py | 49 | ||||
-rw-r--r-- | rdiff-backup/testing/finaltest.py | 34 | ||||
-rw-r--r-- | rdiff-backup/testing/highleveltest.py | 11 | ||||
-rw-r--r-- | rdiff-backup/testing/regressiontest.py | 25 |
6 files changed, 64 insertions, 154 deletions
diff --git a/rdiff-backup/rdiff_backup/Main.py b/rdiff-backup/rdiff_backup/Main.py index 67141e1..2b3d497 100644 --- a/rdiff-backup/rdiff_backup/Main.py +++ b/rdiff-backup/rdiff_backup/Main.py @@ -48,23 +48,22 @@ def parse_cmdlineoptions(arglist): try: return open(filename, "r") except IOError: Log.FatalError("Error opening file %s" % filename) - try: optlist, args = getopt.getopt(arglist, "blmr:sv:V", - ["backup-mode", "calculate-average", - "change-source-perms", "chars-to-quote=", - "checkpoint-interval=", "current-time=", "exclude=", - "exclude-device-files", "exclude-filelist=", + try: optlist, args = getopt.getopt(arglist, "blr:sv:V", + ["backup-mode", "calculate-average", "change-source-perms", + "chars-to-quote=", "checkpoint-interval=", "current-time=", + "exclude=", "exclude-device-files", "exclude-filelist=", "exclude-filelist-stdin", "exclude-globbing-filelist=", "exclude-mirror=", "exclude-other-filesystems", "exclude-regexp=", "exclude-special-files", "force", "include=", "include-filelist=", "include-filelist-stdin", "include-globbing-filelist=", "include-regexp=", - "list-changed-since=", "list-increments", "mirror-only", - "no-compression", "no-compression-regexp=", "no-hard-links", - "no-resume", "null-separator", "parsable-output", - "print-statistics", "quoting-char=", "remote-cmd=", - "remote-schema=", "remove-older-than=", "restore-as-of=", - "restrict=", "restrict-read-only=", "restrict-update-only=", - "resume", "resume-window=", "server", "sleep-ratio=", + "list-changed-since=", "list-increments", "no-compression", + "no-compression-regexp=", "no-hard-links", "no-resume", + "null-separator", "parsable-output", "print-statistics", + "quoting-char=", "remote-cmd=", "remote-schema=", + "remove-older-than=", "restore-as-of=", "restrict=", + "restrict-read-only=", "restrict-update-only=", "resume", + "resume-window=", "server", "sleep-ratio=", "ssh-no-compression", "terminal-verbosity=", "test-server", "verbosity=", "version", "windows-mode", "windows-time-format"]) @@ -115,7 +114,6 @@ def parse_cmdlineoptions(arglist): restore_timestr, action = arg, "list-changed-since" elif opt == "-l" or opt == "--list-increments": action = "list-increments" - elif opt == "-m" or opt == "--mirror-only": action = "mirror" elif opt == "--no-compression": Globals.set("compression", None) elif opt == "--no-compression-regexp": Globals.set("no_compression_regexp_string", arg) @@ -185,8 +183,7 @@ def set_action(): commandline_error("No arguments given") if l > 0 and action == "server": commandline_error("Too many arguments given") - if l < 2 and (action == "backup" or action == "mirror" or - action == "restore-as-of"): + if l < 2 and (action == "backup" or action == "restore-as-of"): commandline_error("Two arguments are required (source, destination).") if l == 2 and (action == "list-increments" or action == "remove-older-than" or @@ -228,7 +225,6 @@ def take_action(rps): elif action == "backup": Backup(rps[0], rps[1]) elif action == "restore": restore(*rps) elif action == "restore-as-of": RestoreAsOf(rps[0], rps[1]) - elif action == "mirror": Mirror(rps[0], rps[1]) elif action == "test-server": SetConnections.TestConnections() elif action == "list-changed-since": ListChangedSince(rps[0]) elif action == "list-increments": ListIncrements(rps[0]) @@ -254,37 +250,15 @@ def Main(arglist): cleanup() -def Mirror(src_rp, dest_rp): - """Turn dest_path into a copy of src_path""" - Log("Mirroring %s to %s" % (src_rp.path, dest_rp.path), 5) - mirror_check_paths(src_rp, dest_rp) - # Since no "rdiff-backup-data" dir, use root of destination. - SetConnections.UpdateGlobal('rbdir', dest_rp) - SetConnections.BackupInitConnections(src_rp.conn, dest_rp.conn) - backup_init_select(src_rp, dest_rp) - HighLevel.Mirror(src_rp, dest_rp) - -def mirror_check_paths(rpin, rpout): - """Check paths and return rpin, rpout""" - if not rpin.lstat(): - Log.FatalError("Source directory %s does not exist" % rpin.path) - if rpout.lstat() and not force: Log.FatalError( -"""Destination %s exists so continuing could mess it up. Run -rdiff-backup with the --force option if you want to mirror anyway.""" % - rpout.path) - - def Backup(rpin, rpout): """Backup, possibly incrementally, src_path to dest_path.""" SetConnections.BackupInitConnections(rpin.conn, rpout.conn) backup_init_select(rpin, rpout) backup_init_dirs(rpin, rpout) - RSI = Globals.backup_writer.Resume.ResumeCheck() - SaveState.init_filenames() if prevtime: Time.setprevtime(prevtime) - HighLevel.Mirror_and_increment(rpin, rpout, incdir, RSI) - else: HighLevel.Mirror(rpin, rpout, incdir, RSI) + HighLevel.Mirror_and_increment(rpin, rpout, incdir) + else: HighLevel.Mirror(rpin, rpout, incdir) rpout.conn.Main.backup_touch_curmirror_local(rpin, rpout) def backup_init_select(rpin, rpout): diff --git a/rdiff-backup/rdiff_backup/highlevel.py b/rdiff-backup/rdiff_backup/highlevel.py index 48cb123..eb3628f 100644 --- a/rdiff-backup/rdiff_backup/highlevel.py +++ b/rdiff-backup/rdiff_backup/highlevel.py @@ -40,7 +40,7 @@ class HighLevel: accompanying diagram. """ - def Mirror(src_rpath, dest_rpath, inc_rpath = None, session_info = None): + def Mirror(src_rpath, dest_rpath, inc_rpath): """Turn dest_rpath into a copy of src_rpath If inc_rpath is true, then this is the initial mirroring of an @@ -51,14 +51,10 @@ class HighLevel: SourceS = src_rpath.conn.HLSourceStruct DestS = dest_rpath.conn.HLDestinationStruct - SourceS.set_session_info(session_info) - DestS.set_session_info(session_info) src_init_dsiter = SourceS.split_initial_dsiter() dest_sigiter = DestS.get_sigs(dest_rpath, src_init_dsiter) diffiter = SourceS.get_diffs_and_finalize(dest_sigiter) - if inc_rpath: - DestS.patch_w_datadir_writes(dest_rpath, diffiter, inc_rpath) - else: DestS.patch_and_finalize(dest_rpath, diffiter) + DestS.patch_w_datadir_writes(dest_rpath, diffiter, inc_rpath) dest_rpath.setdata() @@ -68,9 +64,6 @@ class HighLevel: SourceS = src_rpath.conn.HLSourceStruct DestS = dest_rpath.conn.HLDestinationStruct - SourceS.set_session_info(session_info) - DestS.set_session_info(session_info) - if not session_info: dest_rpath.conn.SaveState.touch_last_file() src_init_dsiter = SourceS.split_initial_dsiter() dest_sigiter = DestS.get_sigs(dest_rpath, src_init_dsiter) diffiter = SourceS.get_diffs_and_finalize(dest_sigiter) @@ -84,19 +77,9 @@ MakeStatic(HighLevel) class HLSourceStruct: """Hold info used by HL on the source side""" - _session_info = None # set to si if resuming - def set_session_info(cls, session_info): - cls._session_info = session_info - - def iterate_from(cls): - """Supply more aruments to DestructiveStepping.Iterate_from""" - if cls._session_info is None: Globals.select_source.set_iter() - else: Globals.select_source.set_iter(cls._session_info.last_index, 1) - return Globals.select_source - def split_initial_dsiter(cls): """Set iterators of all dsrps from rpath, returning one""" - dsiter = cls.iterate_from() + dsiter = Globals.select_source.set_iter() initial_dsiter1, cls.initial_dsiter2 = Iter.multiplex(dsiter, 2) return initial_dsiter1 @@ -133,18 +116,10 @@ MakeClass(HLSourceStruct) class HLDestinationStruct: """Hold info used by HL on the destination side""" _session_info = None # set to si if resuming - def set_session_info(cls, session_info): - cls._session_info = session_info - - def iterate_from(cls): - """Return selection iterator to iterate all the mirror files""" - if cls._session_info is None: Globals.select_mirror.set_iter() - else: Globals.select_mirror.set_iter(cls._session_info.last_index) - return Globals.select_mirror - def split_initial_dsiter(cls): """Set initial_dsiters (iteration of all dsrps from rpath)""" - result, cls.initial_dsiter2 = Iter.multiplex(cls.iterate_from(), 2) + result, cls.initial_dsiter2 = \ + Iter.multiplex(Globals.select_mirror.set_iter(), 2) return result def get_dissimilar(cls, baserp, src_init_iter, dest_init_iter): @@ -287,7 +262,6 @@ class HLDestinationStruct: if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None ITR(dsrp.index, diff_rorp, dsrp) finalizer(dsrp.index, dsrp) - SaveState.checkpoint(ITR, finalizer, dsrp) finished_dsrp = dsrp ITR.Finish() finalizer.Finish() @@ -296,7 +270,6 @@ class HLDestinationStruct: if Globals.preserve_hardlinks: Hardlink.final_writedata() MiscStats.close_dir_stats_file() MiscStats.write_session_statistics(ITR.root_branch) - SaveState.checkpoint_remove() def patch_increment_and_finalize(cls, dest_rpath, diffs, inc_rpath): """Apply diffs, write increment if necessary, and finalize""" @@ -314,7 +287,6 @@ class HLDestinationStruct: if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None ITR(index, diff_rorp, dsrp) finalizer(index, dsrp) - SaveState.checkpoint(ITR, finalizer, dsrp) finished_dsrp = dsrp ITR.Finish() finalizer.Finish() @@ -323,15 +295,14 @@ class HLDestinationStruct: if Globals.preserve_hardlinks: Hardlink.final_writedata() MiscStats.close_dir_stats_file() MiscStats.write_session_statistics(ITR.root_branch) - SaveState.checkpoint_remove() def handle_last_error(cls, dsrp, finalizer, ITR): """If catch fatal error, try to checkpoint before exiting""" Log.exception(1, 2) TracebackArchive.log() - SaveState.checkpoint(ITR, finalizer, dsrp, 1) - if Globals.preserve_hardlinks: Hardlink.final_checkpoint(Globals.rbdir) - SaveState.touch_last_file_definitive() + #SaveState.checkpoint(ITR, finalizer, dsrp, 1) + #if Globals.preserve_hardlinks: Hardlink.final_checkpoint(Globals.rbdir) + #SaveState.touch_last_file_definitive() raise MakeClass(HLDestinationStruct) diff --git a/rdiff-backup/testing/commontest.py b/rdiff-backup/testing/commontest.py index 3636d9f..769187a 100644 --- a/rdiff-backup/testing/commontest.py +++ b/rdiff-backup/testing/commontest.py @@ -88,35 +88,30 @@ def InternalBackup(source_local, dest_local, src_dir, dest_dir, Main.Backup(rpin, rpout) Main.cleanup() -def InternalMirror(source_local, dest_local, src_dir, dest_dir, - write_data = None): - """Mirror src to dest internally, like InternalBackup""" - remote_schema = '%s' +def InternalMirror(source_local, dest_local, src_dir, dest_dir): + """Mirror src to dest internally - if not source_local: - src_dir = "cd test1; python ../server.py ../%s::../%s" % \ - (SourceDir, src_dir) - if not dest_local: - dest_dir = "cd test2/tmp; python ../../server.py ../../%s::../../%s" \ - % (SourceDir, dest_dir) + like InternalBackup, but only mirror. Do this through + InternalBackup, but then delete rdiff-backup-data directory. - rpin, rpout = cmd_schemas2rps([src_dir, dest_dir], remote_schema) - Main.misc_setup([rpin, rpout]) - Main.backup_init_select(rpin, rpout) - if not rpout.lstat(): rpout.mkdir() - if write_data: # use rdiff-backup-data dir to checkpoint - data_dir = rpout.append("rdiff-backup-data") - if not data_dir.lstat(): data_dir.mkdir() - SetConnections.UpdateGlobal('rbdir', data_dir) - else: # just use root directory to hold checkpoints - SetConnections.UpdateGlobal('rbdir', rpout) - SetConnections.BackupInitConnections(rpin.conn, rpout.conn) - - if write_data: - SaveState.init_filenames() - HighLevel.Mirror(rpin, rpout, Globals.rbdir.append("increments")) - else: HighLevel.Mirror(rpin, rpout) - Main.cleanup() + """ + # Save attributes of root to restore later + src_root = RPath(Globals.local_connection, src_dir) + dest_root = RPath(Globals.local_connection, dest_dir) + dest_rbdir = dest_root.append("rdiff-backup-data") + dest_incdir = dest_rbdir.append("increments") + + # We need to create these directories or else failure because + # --force option not given. + if not dest_root.lstat(): dest_root.mkdir() + if not dest_rbdir.lstat(): dest_rbdir.mkdir() + if not dest_incdir.lstat(): dest_incdir.mkdir() + + InternalBackup(source_local, dest_local, src_dir, dest_dir) + dest_root.setdata() + dest_rbdir.delete() + # Restore old attributes + RPathStatic.copy_attribs(src_root, dest_root) def InternalRestore(mirror_local, dest_local, mirror_dir, dest_dir, time): """Restore mirror_dir to dest_dir at given time diff --git a/rdiff-backup/testing/finaltest.py b/rdiff-backup/testing/finaltest.py index 7e3c1df..9d1f9ae 100644 --- a/rdiff-backup/testing/finaltest.py +++ b/rdiff-backup/testing/finaltest.py @@ -198,23 +198,23 @@ class Final(PathSetter): self.set_connections(None, None, "test2/tmp", "../../") self.runtest() - def testMirroringLocal(self): - """Run mirroring only everything remote""" - self.delete_tmpdirs() - self.set_connections(None, None, None, None) - self.exec_rb_extra_args(10000, "-m", - "testfiles/various_file_types", - "testfiles/output") - assert CompareRecursive(Local.vftrp, Local.rpout, exclude_rbdir = None) - - def testMirroringRemote(self): - """Run mirroring only everything remote""" - self.delete_tmpdirs() - self.set_connections("test1/", "../", "test2/tmp/", "../../") - self.exec_rb_extra_args(10000, "-m", - "testfiles/various_file_types", - "testfiles/output") - assert CompareRecursive(Local.vftrp, Local.rpout, exclude_rbdir = None) +# def testMirroringLocal(self): +# """Run mirroring only everything remote""" +# self.delete_tmpdirs() +# self.set_connections(None, None, None, None) +# self.exec_rb_extra_args(10000, "-m", +# "testfiles/various_file_types", +# "testfiles/output") +# assert CompareRecursive(Local.vftrp, Local.rpout, exclude_rbdir = None) + +# def testMirroringRemote(self): +# """Run mirroring only everything remote""" +# self.delete_tmpdirs() +# self.set_connections("test1/", "../", "test2/tmp/", "../../") +# self.exec_rb_extra_args(10000, "-m", +# "testfiles/various_file_types", +# "testfiles/output") +# assert CompareRecursive(Local.vftrp, Local.rpout, exclude_rbdir = None) def testProcRemote(self): """Test mirroring proc""" diff --git a/rdiff-backup/testing/highleveltest.py b/rdiff-backup/testing/highleveltest.py index 1054f2b..92490a4 100644 --- a/rdiff-backup/testing/highleveltest.py +++ b/rdiff-backup/testing/highleveltest.py @@ -24,16 +24,5 @@ class RemoteMirrorTest(unittest.TestCase): MirrorTest(1, 1, ['testfiles/increment1', 'testfiles/increment2', 'testfiles/increment3', 'testfiles/increment4']) - def testMirrorWithCheckpointing(self): - """Like testMirror but this time checkpoint""" - MirrorTest(None, None, ["testfiles/increment1"], 1) - - def testMirrorWithCheckpointing2(self): - """Larger data set""" - MirrorTest(1, None, ['testfiles/increment1', 'testfiles/increment2', - 'testfiles/increment3', 'testfiles/increment4'], - 1) - - if __name__ == "__main__": unittest.main() diff --git a/rdiff-backup/testing/regressiontest.py b/rdiff-backup/testing/regressiontest.py index a132020..196d5ae 100644 --- a/rdiff-backup/testing/regressiontest.py +++ b/rdiff-backup/testing/regressiontest.py @@ -292,23 +292,6 @@ class MirrorTest(PathSetter): self.setPathnames('test1', '../', 'test2/tmp', '../../') self.run_partial_test() - def testNopermsLocal(self): - "Test mirroring a directory that has no permissions" - self.setPathnames(None, None, None, None) - Time.setcurtime() - SaveState.init_filenames() - self.Mirror(self.noperms, self.noperms_out, None) - # Can't compare because we don't have the permissions to do it right - #assert CompareRecursive(Local.noperms, Local.noperms_out) - - def testNopermsRemote(self): - "No permissions mirroring (remote)" - self.setPathnames('test1', '../', 'test2/tmp', '../../') - Time.setcurtime() - SaveState.init_filenames() - self.Mirror(self.noperms, self.noperms_out, None) - #assert CompareRecursive(Local.noperms, Local.noperms_out) - def testPermSkipLocal(self): """Test to see if rdiff-backup will skip unreadable files""" self.setPathnames(None, None, None, None) @@ -418,13 +401,11 @@ class MirrorTest(PathSetter): self.Mirror(self.inc2rp, self.rpout) assert CompareRecursive(Local.inc2rp, Local.rpout) - def Mirror(self, rpin, rpout, write_increments = 1): + def Mirror(self, rpin, rpout): """Like HighLevel.Mirror, but run misc_setup first""" Main.misc_setup([rpin, rpout]) Main.backup_init_select(rpin, rpout) - if write_increments: - HighLevel.Mirror(rpin, rpout, - rpout.append_path("rdiff-backup-data/increments")) - else: HighLevel.Mirror(rpin, rpout) + HighLevel.Mirror(rpin, rpout, + rpout.append_path("rdiff-backup-data/increments")) if __name__ == "__main__": unittest.main() |