except StopIteration:
break
+ def iterate_disaster_index (self, index):
+ """
+ Mimick the behavior of the other object iterators, just with the inputs
+ supplied directly as *index*.
+ """
+
+ class RawIndexIterator(object):
+ def __init__(self, delta_tar, tar_path, index):
+ self.delta_tar = delta_tar
+ self.index = index
+ self.__enter__()
+
+ def __iter__(self):
+ return self
+
+ def release(self):
+ if self.tar_obj:
+ self.tar_obj.close()
+
+ def __enter__(self):
+ '''
+ Allows this iterator to be used with the "with" statement
+ '''
+ self.iter = self.index.__iter__ ()
+ return self
+
+ def __exit__(self, type, value, tb):
+ '''
+ Allows this iterator to be used with the "with" statement
+ '''
+
+ def __next__(self):
+ idxent = self.iter.__next__ ()
+ return idxent
+
+ return RawIndexIterator(self, index)
+
def collate_iterators(self, it1, it2):
'''
Collate two iterators, so that it returns pairs of the items of each
def restore_backup(self, target_path, backup_indexes_paths=[],
backup_tar_path=None, restore_callback=None,
- disaster=tarfile.TOLERANCE_STRICT):
+ disaster=tarfile.TOLERANCE_STRICT, backup_index=None):
'''
Restores a backup.
if backup_indexes_paths is None and backup_tar_path == []:
raise Exception("You have to either provide index paths or a tar path")
- if len(backup_indexes_paths) == 0:
+ if isinstance (backup_index, list) is True:
+ mode = "disaster"
+ elif len(backup_indexes_paths) == 0:
mode = "tar"
else:
mode = "diff"
self.logger.error("failed to read file [%s]: %s; is this an "
"actual index file?" % (index1, str (exn)))
return [(index1, exn)]
+ elif mode == "disaster":
+ index_it = self.iterate_disaster_index (backup_index)
+ helper = RestoreHelper (self, cwd, disaster=disaster)
+
dir_it = self._recursive_walk_dir('.')
dir_path_it = self.jsonize_path_iterator(dir_it)
files may be corrupt; skim files for header-like information and
attempt to retrieve the data.
"""
- faux_index = tarfile.gen_rescue_index(backup_tar_path,
- password=self.password,
- key=self.crypto_key)
+ backup_index = tarfile.gen_rescue_index(backup_tar_path,
+ self.mode,
+ password=self.password,
+ key=self.crypto_key)
return self.restore_backup(target_path,
- backup_index=faux_index,
+ backup_index=backup_index,
disaster=tarfile.TOLERANCE_RESCUE)