self.hash = dict ()
os.makedirs (src_path)
for i in range (5):
- f = "source_dir2/dummy_%rd" % i
- self.hash [f] = self.create_file (f, 5 + i)
+ f = "dummy_%rd" % i
+ self.hash [f] = self.create_file ("%s/%s" % (src_path, f), 5 + i)
dtar.create_full_backup \
(source_path=src_path, backup_path=bak_path)
dtar.restore_backup(target_path=dst_path,
backup_tar_path=backup_full)
for key, value in self.hash.items ():
- assert os.path.exists (key)
- assert value == self.md5sum (key)
+ f = "%s/%s" % (dst_path, key)
+ assert os.path.exists (f)
+ assert value == self.md5sum (f)
+ shutil.rmtree (dst_path)
shutil.rmtree (src_path)
flip_bits (backup_full, gz_header_size (backup_full) + 1)
# normal restore must fail
curdir = os.getcwd () # not restored after below failure
- with self.assertRaises (tarfile.ReadError):
+ with self.assertRaises (Exception) as cm:
dtar.restore_backup(target_path=dst_path,
backup_tar_path=backup_full)
+ assert type (cm.exception) in [ tarfile.CompressionError
+ , tarfile.ReadError
+ ]
os.chdir (curdir)
# but recover will succeed
- dtar.recover_backup(target_path=dst_path,
- backup_indexes_paths=[
- "%s/%s" % (bak_path, index_file)
- ])
+ failed = dtar.recover_backup(target_path=dst_path,
+ backup_indexes_paths=[
+ "%s/%s" % (bak_path, index_file)
+ ])
+ assert len (failed) == 1
# with one file missing
missing = []
for key, value in self.hash.items ():
- if os.path.exists (key):
- assert value == self.md5sum (key)
+ kkey = "%s/%s" % (dst_path, key)
+ if os.path.exists (kkey):
+ assert value == self.md5sum (kkey)
else:
missing.append (key)
assert len (missing) == 1
- shutil.rmtree (src_path)
+ shutil.rmtree (dst_path)