diff --git a/excludes/linux_excludes b/excludes/linux_excludes index ee316a7..67403dd 100644 --- a/excludes/linux_excludes +++ b/excludes/linux_excludes @@ -9,6 +9,7 @@ lost+found /media /mnt /proc +/sys /run /selinux /var/cache @@ -89,4 +90,4 @@ $HOME/SkyDrive* **/Network Trash Folder **/.fseventsd* **/.Spotlight-* -**/*Mobile*Backups \ No newline at end of file +**/*Mobile*Backups diff --git a/npbackup/__main__.py b/npbackup/__main__.py index 3290429..ef530b3 100644 --- a/npbackup/__main__.py +++ b/npbackup/__main__.py @@ -92,7 +92,11 @@ def execution_logs(start_time: datetime) -> None: 10 = debug, 20 = info, 30 = warning, 40 = error, 50 = critical so "if 30 in logger._cache" checks if warning has been triggered ATTENTION: logger._cache does only contain cache of current main, not modules, deprecated in favor of - ofunctions.ContextFilterWorstLevel + ofunctions.logger_utils.ContextFilterWorstLevel + + ATTENTION: For ofunctions.logger_utils.ContextFilterWorstLevel will only check current logger instance + So using logger = getLogger("anotherinstance") will create a separate instance from the one we can inspect + Makes sense ;) """ end_time = datetime.utcnow() diff --git a/npbackup/configuration.py b/npbackup/configuration.py index c9a43d1..8f52aa7 100644 --- a/npbackup/configuration.py +++ b/npbackup/configuration.py @@ -55,7 +55,7 @@ except ImportError: sys.exit(1) -logger = getLogger(__name__) +logger = getLogger() # Monkeypatching ruamel.yaml ordreddict so we get to use pseudo dot notations diff --git a/npbackup/core/i18n_helper.py b/npbackup/core/i18n_helper.py index e73585c..e56b3aa 100644 --- a/npbackup/core/i18n_helper.py +++ b/npbackup/core/i18n_helper.py @@ -17,7 +17,7 @@ import i18n from npbackup.path_helper import BASEDIR -logger = getLogger(__intname__) +logger = getLogger() TRANSLATIONS_DIR = os.path.join(BASEDIR, "translations") diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index 680e479..6e8ccbf 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -26,7 +26,7 @@ from npbackup.__version__ import __intname__ as NAME, __version__ as VERSION from npbackup import configuration -logger = logging.getLogger(__intname__) +logger = logging.getLogger() def metric_writer( @@ -350,6 +350,15 @@ class NPBackupRunner: except ValueError: logger.warning("Bogus ignore_cloud_files value given") + try: + if self.config_dict["backup"]["additional_parameters"]: + self.restic_runner.additional_parameters = self.config_dict["backup"][ + "additional_parameters" + ] + except KeyError: + pass + except ValueError: + logger.warning("Bogus additional parameters given") self.restic_runner.stdout = self.stdout try: @@ -570,14 +579,18 @@ class NPBackupRunner: tags = None try: - additional_parameters = self.config_dict["backup"]["additional_parameters"] + additional_backup_only_parameters = self.config_dict["backup"][ + "additional_backup_only_parameters" + ] except KeyError: - additional_parameters = None + additional_backup_only_parameters = None # Check if backup is required self.restic_runner.verbose = False if not self.restic_runner.is_init: - self.restic_runner.init() + if not self.restic_runner.init(): + logger.error("Cannot continue.") + return False if self.check_recent_backups() and not force: logger.info("No backup necessary.") return True @@ -602,8 +615,8 @@ class NPBackupRunner: if pre_exec_failure_is_fatal: return False else: - logger.debug( - "Pre-execution of command {} success with\n{}.".format( + logger.info( + "Pre-execution of command {} success with:\n{}.".format( pre_exec_command, output ) ) @@ -619,7 +632,7 @@ class NPBackupRunner: one_file_system=one_file_system, use_fs_snapshot=use_fs_snapshot, tags=tags, - additional_parameters=additional_parameters, + additional_backup_only_parameters=additional_backup_only_parameters, ) logger.debug("Restic output:\n{}".format(result_string)) metric_writer( @@ -639,8 +652,8 @@ class NPBackupRunner: if post_exec_failure_is_fatal: return False else: - logger.debug( - "Post-execution of command {} success with\n{}.".format( + logger.info( + "Post-execution of command {} success with:\n{}.".format( post_exec_command, output ) ) diff --git a/npbackup/core/upgrade_runner.py b/npbackup/core/upgrade_runner.py index acf757b..6d13c7d 100644 --- a/npbackup/core/upgrade_runner.py +++ b/npbackup/core/upgrade_runner.py @@ -16,7 +16,7 @@ from npbackup.upgrade_client.upgrader import auto_upgrader, _check_new_version from npbackup.__version__ import __version__ as npbackup_version -logger = getLogger(__intname__) +logger = getLogger() def check_new_version(config_dict: dict) -> bool: diff --git a/npbackup/gui/config.py b/npbackup/gui/config.py index cf0dd2e..0e43726 100644 --- a/npbackup/gui/config.py +++ b/npbackup/gui/config.py @@ -22,7 +22,7 @@ from npbackup.core.nuitka_helper import IS_COMPILED if os.name == "nt": from npbackup.windows.task import create_scheduled_task -logger = getLogger(__intname__) +logger = getLogger() def ask_backup_admin_password(config_dict) -> bool: @@ -283,6 +283,10 @@ def config_gui(config_dict: dict, config_file: str): sg.Text(_t("config_gui.additional_parameters"), size=(40, 1)), sg.Input(key="backup---additional_parameters", size=(50, 1)), ], + [ + sg.Text(_t("config_gui.additional_backup_only_parameters"), size=(40, 1)), + sg.Input(key="backup---additional_backup_only_parameters", size=(50, 1)), + ], ] repo_col = [ diff --git a/npbackup/gui/main.py b/npbackup/gui/main.py index 3018299..cb06911 100644 --- a/npbackup/gui/main.py +++ b/npbackup/gui/main.py @@ -45,7 +45,7 @@ from npbackup.core.i18n_helper import _t from npbackup.core.upgrade_runner import run_upgrade, check_new_version -logger = getLogger(__intname__) +logger = getLogger() # Let's use mutable to get a cheap way of transfering data from thread to main program # There are no possible race conditions since we don't modifiy the data from anywhere outside the thread diff --git a/npbackup/path_helper.py b/npbackup/path_helper.py index be27f54..2ef0ec1 100644 --- a/npbackup/path_helper.py +++ b/npbackup/path_helper.py @@ -3,7 +3,7 @@ # # This file is part of npbackup -__intname__ = "npbackup.paths" +__intname__ = "npbackup.path_helper" __author__ = "Orsiris de Jong" __copyright__ = "Copyright (C) 2023 NetInvent" __license__ = "GPL-3.0-only" diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 6b3227d..d311fc2 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -22,7 +22,7 @@ import queue from command_runner import command_runner -logger = getLogger(__intname__) +logger = getLogger() # Arbitrary timeout for init / init checks. # If init takes more than a minute, we really have a problem @@ -70,7 +70,7 @@ class ResticRunner: except AttributeError: self._backend_type = None self._ignore_cloud_files = True - self._addition_parameters = None + self._additional_parameters = None self._environment_variables = {} self._stop_on = ( @@ -201,7 +201,12 @@ class ResticRunner: """ start_time = datetime.utcnow() self._executor_finished = False - _cmd = '"{}" {}{}'.format(self._binary, cmd, self.generic_arguments) + additional_parameters = ( + f" {self.additional_parameters.strip()} " + if self.additional_parameters + else "" + ) + _cmd = f'"{self._binary}" {additional_parameters}{cmd}{self.generic_arguments}' if self.dry_run: _cmd += " --dry-run" logger.debug("Running command: [{}]".format(_cmd)) @@ -352,11 +357,11 @@ class ResticRunner: @property def additional_parameters(self): - return self._addition_parameters + return self._additional_parameters @additional_parameters.setter def additional_parameters(self, value: str): - self._addition_parameters = value + self._additional_parameters = value @property def priority(self): @@ -442,11 +447,17 @@ class ResticRunner: if re.search( r"created restic repository ([a-z0-9]+) at .+", output, re.IGNORECASE ): + self.is_init = True return True else: if re.search(".*already exists", output, re.IGNORECASE): logger.info("Repo already initialized.") self.is_init = True + return True + logger.error(f"Cannot contact repo: {output}") + self.is_init = False + return False + self.is_init = False return False @property @@ -536,7 +547,7 @@ class ResticRunner: use_fs_snapshot: bool = False, tags: List[str] = [], one_file_system: bool = False, - additional_parameters: str = None, + additional_backup_only_parameters: str = None, ) -> Tuple[bool, str]: """ Executes restic backup after interpreting all arguments @@ -560,10 +571,15 @@ class ResticRunner: for path in paths: cmd += ' {} "{}"'.format(source_parameter, path) else: - # make sure path is a list and does not have trailing slashes + # make sure path is a list and does not have trailing slashes, unless we're backing up root # We don't need to scan files for ETA, so let's add --no-scan cmd = "backup --no-scan {}".format( - " ".join(['"{}"'.format(path.rstrip("/\\")) for path in paths]) + " ".join( + [ + '"{}"'.format(path.rstrip("/\\")) if path != "/" else path + for path in paths + ] + ) ) case_ignore_param = "" @@ -598,8 +614,8 @@ class ResticRunner: if tag: tag = tag.strip() cmd += " --tag {}".format(tag) - if additional_parameters: - cmd += " {}".format(additional_parameters) + if additional_backup_only_parameters: + cmd += " {}".format(additional_backup_only_parameters) result, output = self.executor(cmd, live_stream=True) if ( diff --git a/npbackup/translations/config_gui.en.yml b/npbackup/translations/config_gui.en.yml index 98773da..644a1eb 100644 --- a/npbackup/translations/config_gui.en.yml +++ b/npbackup/translations/config_gui.en.yml @@ -20,6 +20,7 @@ en: one_per_line: one per line backup_priority: Backup priority additional_parameters: Additional parameters + additional_backup_only_parameters: Additional backup only parmas backup_destination: Backup destination minimum_backup_age: Minimum delay between two backups diff --git a/npbackup/translations/config_gui.fr.yml b/npbackup/translations/config_gui.fr.yml index 80245d9..d79f632 100644 --- a/npbackup/translations/config_gui.fr.yml +++ b/npbackup/translations/config_gui.fr.yml @@ -20,6 +20,7 @@ fr: one_per_line: un par ligne backup_priority: Priorité de sauvegarde additional_parameters: Paramètres supplémentaires + additional_backup_only_parameters: Paramètres supp. sauvegarde backup_destination: Destination de sauvegarde minimum_backup_age: Délai minimal entre deux sauvegardes diff --git a/npbackup/upgrade_client/requestor.py b/npbackup/upgrade_client/requestor.py index 8b5d7e3..dcdfb6a 100644 --- a/npbackup/upgrade_client/requestor.py +++ b/npbackup/upgrade_client/requestor.py @@ -16,7 +16,7 @@ import json import requests -logger = getLogger(__intname__) +logger = getLogger() class Requestor: diff --git a/npbackup/upgrade_client/upgrader.py b/npbackup/upgrade_client/upgrader.py index 4fea555..c178e7d 100644 --- a/npbackup/upgrade_client/upgrader.py +++ b/npbackup/upgrade_client/upgrader.py @@ -25,7 +25,7 @@ from npbackup.path_helper import CURRENT_DIR, CURRENT_EXECUTABLE from npbackup.core.nuitka_helper import IS_COMPILED from npbackup.__version__ import __version__ as npbackup_version -logger = getLogger(__intname__) +logger = getLogger() UPGRADE_DEFER_TIME = 60 # Wait x seconds before we actually do the upgrade so current program could quit before being erased diff --git a/npbackup/windows/task.py b/npbackup/windows/task.py index 4d4808e..758ae3c 100644 --- a/npbackup/windows/task.py +++ b/npbackup/windows/task.py @@ -17,7 +17,7 @@ import tempfile from command_runner import command_runner from npbackup.customization import PROGRAM_NAME -logger = getLogger(__intname__) +logger = getLogger() # This is the path to a onefile executable binary diff --git a/upgrade_server/upgrade_server/configuration.py b/upgrade_server/upgrade_server/configuration.py index 42d7858..a2bb7fc 100644 --- a/upgrade_server/upgrade_server/configuration.py +++ b/upgrade_server/upgrade_server/configuration.py @@ -18,7 +18,7 @@ from logging import getLogger ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) config_file = os.path.join(ROOT_DIR, "upgrade_server.conf") -logger = getLogger(__intname__) +logger = getLogger() def load_config(config_file: str = config_file): diff --git a/upgrade_server/upgrade_server/crud.py b/upgrade_server/upgrade_server/crud.py index f6730b2..14ab95d 100644 --- a/upgrade_server/upgrade_server/crud.py +++ b/upgrade_server/upgrade_server/crud.py @@ -39,7 +39,7 @@ else: config_dict = configuration.load_config() -logger = getLogger(__intname__) +logger = getLogger() def sha256sum_data(data):