max_volume_size=max_volume_size,
new_volume_handler=new_volume_handler)
- for i in self._recursive_walk_dir(source_path):
+ cwd = os.getcwd()
+ os.chdir(source_path)
+ for i in self._recursive_walk_dir('.'):
tarobj.add(i)
+ os.chdir(cwd)
tarobj.close()
using any file index. If it's a multivol tarfile, volume_name_func
will be called.
'''
- pass
+ if not isinstance(target_path, basestring):
+ raise Exception('Target path must be a string')
+
+ if not isinstance(backup_tar_path, basestring):
+ raise Exception('Backup tar path must be a string')
+
+ if not os.path.exists(backup_tar_path) or not os.path.isfile(backup_tar_path):
+ raise Exception('Source path "%s" does not exist or is not a '\
+ 'directory' % backup_tar_path)
+
+ if not os.access(backup_tar_path, os.R_OK):
+ raise Exception('Source path "%s" is not readable' % backup_tar_path)
+
+ # try to create backup path if needed
+ if not os.path.exists(target_path):
+ os.makedirs(target_path)
+
+ def new_volume_handler(deltarobj, tarobj, base_name, volume_number):
+ '''
+ Handles the new volumes
+ '''
+ volume_path = deltarobj.volume_name_func(True, volume_number)
+ tarobj.open_volume(volume_path)
+ new_volume_handler = partial(new_volume_handler, self)
+
+ tarobj = tarfile.TarFile.open(backup_tar_path,
+ mode=self.mode,
+ format=tarfile.GNU_FORMAT,
+ concat_compression='#gz' in self.mode,
+ password=self.password,
+ new_volume_handler=new_volume_handler)
+ cwd = os.getcwd()
+ os.chdir(target_path)
+ tarobj.extractall()
+ os.chdir(cwd)
+ tarobj.close()
# Author: Eduardo Robles Elvira <edulix@wadobo.com>
import os
+import shutil
import logging
from deltatar.deltatar import DeltaTar
'''
os.makedirs('source_dir/test/test2')
self.hash = dict()
+ self.hash["source_dir/test/test2"] = ''
self.hash["source_dir/big"] = self.create_file("source_dir/big", 50000)
self.hash["source_dir/small"] = self.create_file("source_dir/small", 100)
self.hash["source_dir/test/huge"] = self.create_file("source_dir/test/huge", 700000)
source_path="source_dir",
backup_path="backup_dir")
- assert os.path.exists("backup_dir")
\ No newline at end of file
+ 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.mode = 'r'
+ deltatar.restore_backup(target_path="source_dir",
+ backup_tar_path=tar_path)
+
+ for key, value in self.hash.iteritems():
+ assert os.path.exists(key)
+ if value:
+ assert value == self.md5sum(key)
\ No newline at end of file