Esempio n. 1
0
    def setup(self):
        # in setup we return as soon as we detect an issue to avoid changing
        # too much
        return_code = super().setup()
        if return_code != 0:
            return return_code

        return_code = self.source.setup()
        if return_code != 0:
            return return_code

        return_code = self.target.setup()
        if return_code != 0:
            return return_code

        # TODO validate how much of the following lines and methods
        # should go into the directory/repository modules
        try:
            self.target.base_dir.conn.fs_abilities.restore_set_globals(
                self.target.base_dir)
        except OSError as exc:
            log.Log(
                "Could not begin restore due to exception '{ex}'".format(
                    ex=exc), log.ERROR)
            return 1
        self.source.init_quoting(self.values.chars_to_quote)
        self._init_user_group_mapping(self.target.base_dir.conn)
        if log.Log.verbosity > 0:
            try:  # the source repository could be read-only
                log.Log.open_logfile(
                    self.source.data_dir.append("restore.log"))
            except (log.LoggerError, Security.Violation) as exc:
                log.Log(
                    "Unable to open logfile due to exception '{ex}'".format(
                        ex=exc), log.WARNING)

        # we need now to identify the actual time of restore
        self.inc_rpath = self.source.data_dir.append_path(
            b'increments', self.source.restore_index)
        if self.values.at:
            self.action_time = self._get_parsed_time(self.values.at,
                                                     ref_rp=self.inc_rpath)
            if self.action_time is None:
                return 1
        elif self.values.increment:
            self.action_time = self.source.orig_path.getinctime()
        else:  # this should have been catched in the check method
            log.Log(
                "This shouldn't happen but neither restore time nor "
                "an increment have been identified so far", log.ERROR)
            return 1
        (select_opts, select_data) = selection.get_prepared_selections(
            self.values.selections)
        # We must set both sides because restore filtering is different from
        # select filtering.  For instance, if a file is excluded it should
        # not be deleted from the target directory.
        self.source.set_select(select_opts, select_data, self.target.base_dir)
        self.target.set_select(select_opts, select_data)

        return 0  # all is good
Esempio n. 2
0
    def setup(self):
        # in setup we return as soon as we detect an issue to avoid changing
        # too much
        return_code = super().setup()
        if return_code != 0:
            return return_code

        return_code = self.source.setup()
        if return_code != 0:
            return return_code

        return_code = self.target.setup()
        if return_code != 0:
            return return_code

        # set the filesystem properties of the repository
        self.target.base_dir.conn.fs_abilities.single_set_globals(
            self.target.base_dir, 1)  # read_only=True
        self.target.init_quoting(self.values.chars_to_quote)

        (select_opts, select_data) = selection.get_prepared_selections(
            self.values.selections)
        self.source.set_select(select_opts, select_data)

        self.mirror_rpath = self.target.base_dir.new_index(
            self.target.restore_index)
        self.inc_rpath = self.target.data_dir.append_path(
            b'increments', self.target.restore_index)

        self.action_time = self._get_parsed_time(self.values.at,
                                                 ref_rp=self.inc_rpath)
        if self.action_time is None:
            return 1

        return 0  # all is good
Esempio n. 3
0
    def setup(self):
        # in setup we return as soon as we detect an issue to avoid changing
        # too much
        return_code = super().setup()
        if return_code & Globals.RET_CODE_ERR:
            return return_code

        return_code = self.dir.setup()
        if return_code & Globals.RET_CODE_ERR:
            return return_code

        return_code = self.repo.setup(self.dir)
        if return_code & Globals.RET_CODE_ERR:
            return return_code

        # set the filesystem properties of the repository
        if Globals.get_api_version() < 201:  # compat200
            self.repo.base_dir.conn.fs_abilities.single_set_globals(
                self.repo.base_dir, 1)  # read_only=True
            self.repo.setup_quoting()

        (select_opts, select_data) = selection.get_prepared_selections(
            self.values.selections)
        self.dir.set_select(select_opts, select_data)

        # FIXME move method _get_parsed_time to Repo?
        self.action_time = self._get_parsed_time(self.values.at,
                                                 ref_rp=self.repo.ref_inc)
        if self.action_time is None:
            return Globals.RET_CODE_ERR

        return Globals.RET_CODE_OK
Esempio n. 4
0
    def setup(self):
        # in setup we return as soon as we detect an issue to avoid changing
        # too much
        return_code = super().setup()
        if return_code != 0:
            return return_code

        return_code = self._set_no_compression_regexp()
        if return_code != 0:
            return return_code

        return_code = self.dir.setup()
        if return_code != 0:
            return return_code

        owners_map = {
            "users_map": self.values.user_mapping_file,
            "groups_map": self.values.group_mapping_file,
            "preserve_num_ids": self.values.preserve_numerical_ids
        }
        return_code = self.repo.setup(self.dir, owners_map=owners_map)
        if return_code != 0:
            return return_code

        # TODO validate how much of the following lines and methods
        # should go into the directory/repository modules
        if Globals.get_api_version() < 201:  # compat200
            SetConnections.BackupInitConnections(self.dir.base_dir.conn,
                                                 self.repo.base_dir.conn)
            self.repo.base_dir.conn.fs_abilities.backup_set_globals(
                self.dir.base_dir, self.values.force)
            self.repo.setup_quoting()

        previous_time = self.repo.get_mirror_time()
        if previous_time >= Time.getcurtime():
            log.Log("The last backup is not in the past. Aborting.", log.ERROR)
            return 1
        if log.Log.verbosity > 0:
            try:  # the target repository must be writable
                log.Log.open_logfile(self.repo.data_dir.append("backup.log"))
            except (log.LoggerError, Security.Violation) as exc:
                log.Log("Unable to open logfile due to '{ex}'".format(ex=exc),
                        log.ERROR)
                return 1
        log.ErrorLog.open(Time.getcurtimestr(),
                          compress=self.values.compression)

        (select_opts, select_data) = selection.get_prepared_selections(
            self.values.selections)
        self.dir.set_select(select_opts, select_data)
        self._warn_if_infinite_recursion(self.dir.base_dir, self.repo.base_dir)

        return 0
Esempio n. 5
0
    def setup(self):
        # in setup we return as soon as we detect an issue to avoid changing
        # too much
        return_code = super().setup()
        if return_code != 0:
            return return_code

        return_code = self.source.setup()
        if return_code != 0:
            return return_code

        return_code = self.target.setup()
        if return_code != 0:
            return return_code

        # TODO validate how much of the following lines and methods
        # should go into the directory/repository modules
        SetConnections.BackupInitConnections(self.source.base_dir.conn,
                                             self.target.base_dir.conn)
        self.target.base_dir.conn.fs_abilities.backup_set_globals(
            self.source.base_dir, self.values.force)
        self.target.init_quoting(self.values.chars_to_quote)
        self._init_user_group_mapping(self.target.base_dir.conn)
        previous_time = self.target.get_mirror_time()
        if previous_time >= Time.curtime:
            self.log("The last backup is not in the past. Aborting.",
                     self.log.ERROR)
            return 1
        if self.log.verbosity > 0:
            try:  # the target repository must be writable
                self.log.open_logfile(
                    self.target.data_dir.append("backup.log"))
            except (log.LoggerError, Security.Violation) as exc:
                self.log(
                    "Unable to open logfile due to '{exc}'".format(exc=exc),
                    self.log.ERROR)
                return 1
        # TODO could we get rid of the error log?
        self.errlog.open(Time.curtimestr, compress=self.values.compression)

        (select_opts, select_data) = selection.get_prepared_selections(
            self.values.selections)
        self.source.set_select(select_opts, select_data)
        self._warn_if_infinite_recursion(self.source.base_dir,
                                         self.target.base_dir)

        return 0
Esempio n. 6
0
    def setup(self):
        # in setup we return as soon as we detect an issue to avoid changing
        # too much
        return_code = super().setup()
        if return_code != 0:
            return return_code

        return_code = self.dir.setup()
        if return_code != 0:
            return return_code

        return_code = self.repo.setup()
        if return_code != 0:
            return return_code

        # set the filesystem properties of the repository
        if Globals.get_api_version() < 201:  # compat200
            self.repo.base_dir.conn.fs_abilities.single_set_globals(
                self.repo.base_dir, 1)  # read_only=True
            self.repo.init_quoting()

        (select_opts, select_data) = selection.get_prepared_selections(
            self.values.selections)
        self.dir.set_select(select_opts, select_data)

        if Globals.get_api_version() < 201:  # compat200
            self.mirror_rpath = self.repo.base_dir.new_index(
                self.repo.restore_index)
        self.inc_rpath = self.repo.data_dir.append_path(
            b'increments', self.repo.restore_index)

        # FIXME move method _get_parsed_time to Repo and remove inc_rpath?
        self.action_time = self._get_parsed_time(self.values.at,
                                                 ref_rp=self.inc_rpath)
        if self.action_time is None:
            return 1

        return 0  # all is good
Esempio n. 7
0
    def setup(self):
        # in setup we return as soon as we detect an issue to avoid changing
        # too much
        return_code = super().setup()
        if return_code & Globals.RET_CODE_ERR:
            return return_code

        return_code = self._set_no_compression_regexp()
        if return_code & Globals.RET_CODE_ERR:
            return return_code

        return_code = self.repo.setup()
        if return_code & Globals.RET_CODE_ERR:
            return return_code

        owners_map = {
            "users_map": self.values.user_mapping_file,
            "groups_map": self.values.group_mapping_file,
            "preserve_num_ids": self.values.preserve_numerical_ids
        }
        return_code = self.dir.setup(self.repo, owners_map=owners_map)
        if return_code & Globals.RET_CODE_ERR:
            return return_code

        # TODO validate how much of the following lines and methods
        # should go into the directory/repository modules

        # set the filesystem properties of the repository
        if Globals.get_api_version() < 201:  # compat200
            self.dir.base_dir.conn.fs_abilities.restore_set_globals(
                self.dir.base_dir)
            self.repo.setup_quoting()

        if log.Log.verbosity > 0:
            try:  # the source repository could be read-only
                log.Log.open_logfile(
                    self.repo.data_dir.append("restore.log"))
            except (log.LoggerError, Security.Violation) as exc:
                log.Log(
                    "Unable to open logfile due to exception '{ex}'".format(
                        ex=exc), log.WARNING)

        if self.values.at:
            self.action_time = self._get_parsed_time(self.values.at,
                                                     ref_rp=self.repo.ref_inc)
            if self.action_time is None:
                return Globals.RET_CODE_ERR
        elif self.values.increment:
            self.action_time = self.repo.orig_path.getinctime()
        else:  # this should have been catched in the check method
            log.Log("This shouldn't happen but neither restore time nor "
                    "an increment have been identified so far", log.ERROR)
            return Globals.RET_CODE_ERR
        (select_opts, select_data) = selection.get_prepared_selections(
            self.values.selections)
        # We must set both sides because restore filtering is different from
        # select filtering.  For instance, if a file is excluded it should
        # not be deleted from the target directory.
        self.repo.set_select(select_opts, select_data, self.dir.base_dir)
        self.dir.set_select(select_opts, select_data)

        return Globals.RET_CODE_OK