From 12789e285ef805896f780e672de52abf08b1a349 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Wed, 29 Mar 2023 19:11:52 +0200 Subject: [PATCH] Add backend binary to log file --- npbackup/__main__.py | 1 + npbackup/core/runner.py | 5 +++++ npbackup/restic_wrapper/__init__.py | 24 ++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/npbackup/__main__.py b/npbackup/__main__.py index c77378a..b06b3f2 100644 --- a/npbackup/__main__.py +++ b/npbackup/__main__.py @@ -404,6 +404,7 @@ This is free software, and you are welcome to redistribute it under certain cond npbackup_runner = NPBackupRunner(config_dict=config_dict) npbackup_runner.dry_run = dry_run npbackup_runner.verbose = _VERBOSE + logger.info("Backend: {}".format(npbackup_runner.backend_version)) if args.check: if npbackup_runner.check_recent_backups(): diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index 3c5d780..3d265ba 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -128,6 +128,11 @@ class NPBackupRunner: # Configure that instance self.apply_config_to_restic_runner() + @property + def backend_version(self): + if self.restic_runner: + return self.restic_runner.binary_version + @property def dry_run(self): return self._dry_run diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 6e05fbe..7fb48d0 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -7,8 +7,8 @@ __intname__ = "npbackup.restic_wrapper" __author__ = "Orsiris de Jong" __copyright__ = "Copyright (C) 2022-2023 NetInvent" __license__ = "GPL-3.0-only" -__build__ = "2023030701" -__version__ = "1.5.1" +__build__ = "2023032901" +__version__ = "1.6.0" from typing import Tuple, List, Optional, Callable, Union @@ -361,6 +361,26 @@ class ResticRunner: raise ValueError("Non existent binary given: {}".format(value)) self._binary = value + @property + def binary_version(self) -> Optional[str]: + if self._binary: + _cmd = "{} version".format(self._binary) + exit_code, output = command_runner( + _cmd, + timeout=60, + split_streams=False, + encoding="utf-8", + priority=self._priority, + io_priority=self._priority, + ) + if exit_code == 0: + return output + else: + logger.error("Cannot get backend version: {}".format(output)) + else: + logger.error("Cannot get backend version: No binary defined.") + return None + @property def generic_arguments(self): """