if value:
assert value == self.md5sum(key)
+ def test_restore_multivol2(self):
+ '''
+ Creates a full backup without any filtering with multiple volumes and
+ restore it.
+ '''
+ deltatar = DeltaTar(mode=self.MODE, password=self.PASSWORD,
+ logger=self.consoleLogger)
+
+ shutil.copytree(".git", "source_dir2")
+
+ # create first backup
+ deltatar.create_full_backup(
+ source_path="source_dir2",
+ backup_path="backup_dir",
+ max_volume_size=1)
+
+ assert os.path.exists("backup_dir")
+ assert os.path.exists(os.path.join("backup_dir",
+ deltatar.volume_name_func("backup_dir", True, 0)))
+ assert os.path.exists(os.path.join("backup_dir",
+ deltatar.volume_name_func("backup_dir", True, 1)))
+
+ shutil.rmtree("source_dir2")
+
+ tar_filename = deltatar.volume_name_func('backup_dir', True, 0)
+ tar_path = os.path.join("backup_dir", tar_filename)
+
+ # this should automatically restore all volumes
+ deltatar.restore_backup(target_path="source_dir2",
+ backup_tar_path=tar_path)
+
+ self.check_equal_dirs('.git', 'source_dir2', deltatar)
+
def test_restore_multivol_manual_from_index(self):
'''
Creates a full backup without any filtering with multiple volumes and
# altered ".git" directory)
self.check_equal_dirs('source_dir_diff', 'target_dir', deltatar)
+ def test_restore_from_index_diff_backup3_multivol(self):
+ '''
+ Creates a full backup of .git, modifies some random files, creates a
+ diff backup, then restores the diff backup with the full backup as a
+ starting point.
+ '''
+ # this test only works for uncompressed or concat compressed modes
+ if self.MODE.startswith(':') or self.MODE.startswith('|'):
+ return
+
+ deltatar = DeltaTar(mode=self.MODE, password=self.PASSWORD,
+ logger=self.consoleLogger)
+
+ shutil.rmtree("source_dir")
+ shutil.copytree(".git", "source_dir")
+ shutil.copytree(".git", "source_dir_diff")
+
+ # create first backup
+ deltatar.create_full_backup(
+ source_path="source_dir",
+ backup_path="backup_dir",
+ max_volume_size=1)
+
+ prev_index_filename = deltatar.index_name_func(is_full=True)
+ prev_index_path = os.path.join("backup_dir", prev_index_filename)
+
+ # alter the source_dir randomly
+ source_it = deltatar._recursive_walk_dir('source_dir_diff')
+
+ for path in source_it:
+ # if path doesn't exist (might have previously removed) ignore it.
+ # also ignore it (i.e. do not change it) 70% of the time
+ if not os.path.exists(path) or random.random() < 0.7:
+ continue
+
+ # remove the file
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ else:
+ os.unlink(path)
+
+ deltatar.create_diff_backup("source_dir_diff", "backup_dir2",
+ prev_index_path, max_volume_size=1)
+
+ # first restore initial backup in target_dir
+ tar_filename = deltatar.volume_name_func('backup_dir', True, 0)
+ tar_path = os.path.join("backup_dir", tar_filename)
+ deltatar.restore_backup("target_dir", backup_tar_path=tar_path)
+
+ # and check that target_dir equals to source_dir (which is the same as
+ # ".git" initially)
+ self.check_equal_dirs('source_dir', 'target_dir', deltatar)
+
+ # then apply diff backup in target_dir
+ index_filename = deltatar.index_name_func(is_full=True)
+ index_path = os.path.join("backup_dir2", index_filename)
+ deltatar.restore_backup("target_dir",
+ backup_indexes_paths=[index_path, prev_index_path])
+
+ # and check that target_dir equals to source_dir_diff (the randomly
+ # altered ".git" directory)
+ self.check_equal_dirs('source_dir_diff', 'target_dir', deltatar)
+
+ # then delete target_dir and apply diff backup from zero and check again
+ shutil.rmtree("target_dir")
+ deltatar.restore_backup("target_dir",
+ backup_indexes_paths=[index_path, prev_index_path])
+
+ # and check that target_dir equals to source_dir_diff (the randomly
+ # altered ".git" directory)
+ self.check_equal_dirs('source_dir_diff', 'target_dir', deltatar)
+
def check_equal_dirs(self, path1, path2, deltatar):
'''
compare the two directories source_dir and target_dir and check