def run(self): # do regress the target directory if necessary if self._operate_regress(): # regress was necessary and failed return 1 previous_time = self.repo.get_mirror_time(refresh=True) if previous_time < 0 or previous_time >= Time.getcurtime(): log.Log( "Either there is more than one current_mirror or " "the last backup is not in the past. Aborting.", log.ERROR) return 1 if Globals.get_api_version() < 201: # compat200 if previous_time: Time.setprevtime_compat200(previous_time) self.repo.base_dir.conn.Main.backup_touch_curmirror_local( self.dir.base_dir, self.repo.base_dir) backup.mirror_and_increment_compat200(self.dir.base_dir, self.repo.base_dir, self.repo.incs_dir) self.repo.base_dir.conn.Main.backup_remove_curmirror_local() else: backup.mirror_compat200(self.dir.base_dir, self.repo.base_dir) self.repo.base_dir.conn.Main.backup_touch_curmirror_local( self.dir.base_dir, self.repo.base_dir) self.repo.base_dir.conn.Main.backup_close_statistics(time.time()) else: # API 201 and higher self._operate_backup(previous_time) return 0
def write_active_statfileobj(end_time=None): """Write active StatFileObj object to session statistics file""" global _active_statfileobj assert _active_statfileobj, "Stats object must be set before writing." rp_base = Globals.rbdir.append(b"session_statistics") session_stats_rp = increment.get_inc(rp_base, 'data', Time.getcurtime()) _active_statfileobj.finish(end_time) _active_statfileobj.write_stats_to_rp(session_stats_rp) _active_statfileobj = None
def __init__(self, start_time=None): """StatFileObj initializer - zero out file attributes""" StatsObj.__init__(self) for attr in self._stat_file_attrs: self.set_stat(attr, 0) if start_time is None: start_time = Time.getcurtime() self.StartTime = start_time self.Errors = 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
def init(cls): """Open file stats object and prepare to write""" assert not (cls._fileobj or cls._rp), ( "FileStats has already been initialized.") rpbase = Globals.rbdir.append(b"file_statistics") suffix = Globals.compression and 'data.gz' or 'data' cls._rp = increment.get_inc(rpbase, suffix, Time.getcurtime()) assert not cls._rp.lstat(), ( "Path '{rp}' shouldn't be existing.".format(rp=cls._rp)) cls._fileobj = cls._rp.open("wb", compress=Globals.compression) cls._line_sep = Globals.null_separator and b'\0' or b'\n' cls._write_docstring() cls._line_buffer = []
def set_compatible_timestamps(self): if Globals.chars_to_quote.find(b":") > -1: Globals.set_all('use_compatible_timestamps', 1) # Update the current time string to new timestamp format Time.set_current_time(Time.getcurtime()) log.Log("Enabled use_compatible_timestamps", log.INFO)