From 729a2a7c1fda5c5cb8555f264d34371583c7e55e Mon Sep 17 00:00:00 2001 From: deajan Date: Tue, 11 Jun 2024 21:47:22 +0200 Subject: [PATCH] CLI: Added --no-cache option --- CHANGELOG | 1 + npbackup/__main__.py | 6 ++++++ npbackup/__version__.py | 4 ++-- npbackup/core/runner.py | 15 ++++++++++++++- npbackup/restic_wrapper/__init__.py | 20 +++++++++++++++++--- npbackup/runner_interface.py | 1 + 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1dd32df..8fe87da 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -40,6 +40,7 @@ - Metrics have npbackup execution state - Dry mode now works for all operations where restic supports dry-mode - Implemented scheduled task creator for Windows & Unix + - Added --no-cache option to disable cache for restic operations ## Fixes - Default exit code is now worst log level called unless specific errors are triggered diff --git a/npbackup/__main__.py b/npbackup/__main__.py index 6894800..009a386 100644 --- a/npbackup/__main__.py +++ b/npbackup/__main__.py @@ -226,6 +226,11 @@ This is free software, and you are welcome to redistribute it under certain cond action="store_true", help="Run operations in test mode, no actual modifications", ) + parser.add_argument( + "--no-cache", + action="store_true", + help="Run operations without cache", + ) parser.add_argument("--license", action="store_true", help="Show license") parser.add_argument( @@ -444,6 +449,7 @@ This is free software, and you are welcome to redistribute it under certain cond "dry_run": args.dry_run, "json_output": args.json, "backend_binary": backend_binary, + "no_cache": args.no_cache, "operation": None, "op_args": {}, } diff --git a/npbackup/__version__.py b/npbackup/__version__.py index 75b96ee..53ffc47 100644 --- a/npbackup/__version__.py +++ b/npbackup/__version__.py @@ -9,8 +9,8 @@ __site__ = "https://www.netperfect.fr/npbackup" __description__ = "NetPerfect Backup Client" __copyright__ = "Copyright (C) 2022-2024 NetInvent" __license__ = "GPL-3.0-only" -__build__ = "2024060501" -__version__ = "3.0.0-rc1-4" +__build__ = "2024061101" +__version__ = "3.0.0-rc1+dev" import sys diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index 8627215..165773b 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -7,7 +7,7 @@ __intname__ = "npbackup.gui.core.runner" __author__ = "Orsiris de Jong" __copyright__ = "Copyright (C) 2022-2024 NetInvent" __license__ = "GPL-3.0-only" -__build__ = "2024050901" +__build__ = "2024061101" from typing import Optional, Callable, Union, List @@ -203,6 +203,7 @@ class NPBackupRunner: self._live_output = False self._json_output = False self._binary = None + self._no_cache = False self.restic_runner = None self.minimum_backup_age = None self._exec_time = None @@ -237,6 +238,17 @@ class NPBackupRunner: self.write_logs(msg, level="critical", raise_error="ValueError") self._dry_run = value + @property + def no_cache(self): + return self._no_cache + + @no_cache.setter + def no_cache(self, value): + if not isinstance(value, bool): + msg = f"Bogus no_cache parameter given: {value}" + self.write_logs(msg, level="critical", raise_error="ValueError") + self._no_cache = value + @property def verbose(self): return self._verbose @@ -786,6 +798,7 @@ class NPBackupRunner: self.restic_runner.verbose = self.verbose self.restic_runner.dry_run = self.dry_run + self.restic_runner.no_cache = self.no_cache self.restic_runner.live_output = self.live_output self.restic_runner.json_output = self.json_output self.restic_runner.stdout = self.stdout diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 76376ac..d730db3 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-2024 NetInvent" __license__ = "GPL-3.0-only" -__build__ = "2024052501" -__version__ = "2.1.0" +__build__ = "2024060101" +__version__ = "2.2.0" from typing import Tuple, List, Optional, Callable, Union @@ -45,6 +45,7 @@ class ResticRunner: self._verbose = False self._live_output = False self._dry_run = False + self._no_cache = False self._json_output = False self.backup_result_content = None @@ -194,7 +195,18 @@ class ResticRunner: if isinstance(value, bool): self._dry_run = value else: - raise ValueError("Bogus dry run value given") + raise ValueError("Bogus dry_run value given") + + @property + def no_cache(self) -> bool: + return self._no_cache + + @no_cache.setter + def no_cache(self, value: bool): + if isinstance(value, bool): + self._no_cache = value + else: + raise ValueError("Bogus no_cache value given") @property def json_output(self) -> bool: @@ -508,6 +520,8 @@ class ResticRunner: args += " --dry-run" if self.json_output: args += " --json" + if self.no_cache: + args += " --no-cache" return args def init( diff --git a/npbackup/runner_interface.py b/npbackup/runner_interface.py index d2fe843..0a4f7cc 100644 --- a/npbackup/runner_interface.py +++ b/npbackup/runner_interface.py @@ -45,6 +45,7 @@ def entrypoint(*args, **kwargs): npbackup_runner.verbose = kwargs.pop("verbose") npbackup_runner.live_output = not json_output npbackup_runner.json_output = json_output + npbackup_runner.no_cache = kwargs.pop("no_cache", False) if backend_binary: npbackup_runner.binary = backend_binary result = npbackup_runner.__getattribute__(operation)(