Пример #1
0
 def close(self):
     """Process the remaining elements in the cache"""
     while self.cache_indices:
         self._shorten_cache()
     while self.dir_perms_list:
         dir_rp, perms = self.dir_perms_list.pop()
         dir_rp.chmod(perms)
     self.metawriter.close()
     meta_mgr.get_meta_manager().convert_meta_main_to_diff()
Пример #2
0
    def __init__(self, collated_iter, cache_size, dest_root_rp):
        """Initialize new CCWP."""
        self.iter = collated_iter  # generates (source_rorp, dest_rorp) pairs
        self.cache_size = cache_size
        self.dest_root_rp = dest_root_rp

        self.statfileobj = statistics.init_statfileobj()
        if Globals.file_statistics:
            statistics.FileStats.init()
        self.metawriter = meta_mgr.get_meta_manager().get_writer()

        # the following should map indices to lists
        # [source_rorp, dest_rorp, changed_flag, success_flag, increment]

        # changed_flag should be true if the rorps are different, and

        # success_flag should be 1 if dest_rorp has been successfully
        # updated to source_rorp, and 2 if the destination file is
        # deleted entirely.  They both default to false (0).

        # increment holds the RPath of the increment file if one
        # exists.  It is used to record file statistics.

        self.cache_dict = {}
        self.cache_indices = []

        # Contains a list of pairs (destination_rps, permissions) to
        # be used to reset the permissions of certain directories
        # after we're finished with them
        self.dir_perms_list = []

        # Contains list of (index, (source_rorp, diff_rorp)) pairs for
        # the parent directories of the last item in the cache.
        self.parent_list = []
Пример #3
0
    def get_mirror_rorp_iter(cls, rest_time=None, require_metadata=None):
        """Return iter of mirror rps at given restore time

        Usually we can use the metadata file, but if this is
        unavailable, we may have to build it from scratch.

        If the cls._select object is set, use it to filter out the
        unwanted files from the metadata_iter.

        """
        if rest_time is None:
            rest_time = cls._rest_time

        meta_manager = meta_mgr.get_meta_manager(True)
        rorp_iter = meta_manager.get_metas_at_time(rest_time,
                                                   cls.mirror_base.index)
        if not rorp_iter:
            if require_metadata:
                log.Log.FatalError("Mirror metadata not found")
            log.Log("Mirror metadata not found, reading from directory",
                    log.WARNING)
            rorp_iter = cls._get_rorp_iter_from_rf(cls.root_rf)

        if cls._select:
            rorp_iter = selection.FilterIter(cls._select, rorp_iter)
        return rorp_iter
Пример #4
0
def _yield_metadata():
    """Iterate rorps from metadata file, if any are available"""
    meta_manager = meta_mgr.get_meta_manager(True)
    metadata_iter = meta_manager.get_metas_at_time(regress_time)
    if metadata_iter:
        return metadata_iter
    log.Log.FatalError("No metadata for time {pt} ({rt}) found, "
                       "cannot regress".format(
                           pt=Time.timetopretty(regress_time), rt=regress_time))
Пример #5
0
def _set_regress_time():
    """Set global regress_time to previous successful backup

    If there are two current_mirror increments, then the last one
    corresponds to a backup session that failed.

    """
    global regress_time, unsuccessful_backup_time
    meta_manager = meta_mgr.get_meta_manager(True)
    curmir_incs = meta_manager.sorted_prefix_inclist(b'current_mirror')
    assert len(curmir_incs) == 2, (
        "Found {ilen} current_mirror flags, expected 2".format(
            ilen=len(curmir_incs)))
    mirror_rp_to_delete = curmir_incs[0]
    regress_time = curmir_incs[1].getinctime()
    unsuccessful_backup_time = mirror_rp_to_delete.getinctime()
    log.Log("Regressing to date/time {dt}".format(
        dt=Time.timetopretty(regress_time)), log.NOTE)
    return meta_manager, mirror_rp_to_delete
Пример #6
0
    def _get_dest_select(cls, rpath, use_metadata=1):
        """
        Return destination select rorpath iterator

        If metadata file doesn't exist, select all files on
        destination except rdiff-backup-data directory.
        """
        def get_iter_from_fs():
            """Get the combined iterator from the filesystem"""
            sel = selection.Select(rpath)
            sel.parse_rbdir_exclude()
            return sel.set_iter()

        meta_manager = meta_mgr.get_meta_manager(True)
        if use_metadata:
            rorp_iter = meta_manager.get_metas_at_time(Time.prevtime)
            if rorp_iter:
                return rorp_iter
        return get_iter_from_fs()