tarobj.close()
def restore_backup(self, target_path, backup_indexes_paths=[],
- backup_tar_path=None):
+ backup_tar_path=None, restore_callback=None):
'''
Restores a backup.
to backup_indexes_paths to restore directly from a tar file without
using any file index. If it's a multivol tarfile, volume_name_func
will be called.
+ - restore_callback: callback function to be called during restore.
+ This is passed to the helper and gets called for every file
NOTE: If you want to use an index to restore a backup, this function
only supports to do so when the tarfile mode is either uncompressed or
continue
try:
self.logger.debug("restore %s" % ipath['path'])
- helper.restore(ipath, l_no)
+ helper.restore(ipath, l_no, restore_callback)
except Exception as e:
self.logger.error("FAILED to restore: " + ipath.get('path', ''))
continue
if ipath['type'] != 'directory' or ipath['path'].startswith('delete://'):
helper.delete(upath)
self.logger.debug("restore %s" % ipath['path'])
- helper.restore(ipath, l_no)
+ helper.restore(ipath, l_no, restore_callback)
# if the file is not in the index (so it comes from the target
# directory) then we have to delete it
# now we restore parent_directory mtime
os.utime(parent_dir, (parent_dir_mtime, parent_dir_mtime))
- def restore(self, itpath, l_no):
+ def restore(self, itpath, l_no, callback=None):
'''
Restore the path from the appropiate backup. Receives the current path
from the first index iterator. itpath must be not null.
+ callback is a custom function that gets called for every file
'''
path = itpath['path']
+ # Calls the callback function
+ if callback:
+ callback()
+
if path.startswith('delete://'):
# the file has previously been deleted already in restore_backup in
# all cases so we just need to finish