assert not os.path.exists("./source_dir/test/huge")
assert not os.path.exists("./source_dir/big")
+ def test_create_filter_func(self):
+ '''
+ Tests create backup basic filtering.
+ '''
+ visited_paths = []
+ def filter_func(visited_paths, path):
+ if path not in visited_paths:
+ visited_paths.append(path)
+ return True
+
+ filter_func = partial(filter_func, visited_paths)
+ deltatar = DeltaTar(mode=self.MODE, password=self.PASSWORD,
+ logger=self.consoleLogger,
+ included_files=["/test", "/small"],
+ excluded_files=["/test/huge"],
+ filter_func=filter_func)
+
+ # create first backup
+ deltatar.create_full_backup(
+ source_path="source_dir",
+ backup_path="backup_dir")
+
+ assert os.path.exists("backup_dir")
+ shutil.rmtree("source_dir")
+
+ tar_filename = deltatar.volume_name_func('backup_dir', True, 0)
+ tar_path = os.path.join("backup_dir", tar_filename)
+
+ deltatar.restore_backup(target_path="source_dir",
+ backup_tar_path=tar_path)
+ assert visited_paths == [
+ '/small',
+ '/test',
+ '/test/huge2',
+ '/test/test2'
+ ]
+
+ def test_create_filter_out_func(self):
+ '''
+ Tests create backup basic filtering.
+ '''
+ visited_paths = []
+ def filter_func(visited_paths, path):
+ '''
+ Filter out everything
+ '''
+ if path not in visited_paths:
+ visited_paths.append(path)
+ return False
+
+ filter_func = partial(filter_func, visited_paths)
+ deltatar = DeltaTar(mode=self.MODE, password=self.PASSWORD,
+ logger=self.consoleLogger,
+ included_files=["/test", "/small"],
+ excluded_files=["/test/huge"],
+ filter_func=filter_func)
+
+ # create first backup
+ deltatar.create_full_backup(
+ source_path="source_dir",
+ backup_path="backup_dir")
+
+ assert os.path.exists("backup_dir")
+ shutil.rmtree("source_dir")
+
+ tar_filename = deltatar.volume_name_func('backup_dir', True, 0)
+ tar_path = os.path.join("backup_dir", tar_filename)
+
+ deltatar.restore_backup(target_path="source_dir",
+ backup_tar_path=tar_path)
+ assert visited_paths == [
+ '/small',
+ '/test'
+ ]
+
+ # check that effectively no file was backed up
+ assert not os.path.exists("./source_dir/small")
+ assert not os.path.exists("./source_dir/big")
+ assert not os.path.exists("./source_dir/test")
+
class DeltaTar2Test(DeltaTarTest):
'''
Same as DeltaTar but with specific ":" mode