From e53e92ad0c482dd51afef6322221723b8057ea0a Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Tue, 9 Jan 2024 21:50:42 +0100 Subject: [PATCH] WIP: Change restic backup output to json compat format --- npbackup/core/runner.py | 22 +++++++--------------- npbackup/restic_wrapper/__init__.py | 5 ++--- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index 6abf76c..fd1da2c 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -829,11 +829,8 @@ class NPBackupRunner: if not read_from_stdin: paths = self.repo_config.g("backup_opts.paths") if not paths: - self.write_logs( - f"No paths to backup defined for repo {self.repo_config.g('name')}.", - level="error", - ) - return False + output = f"No paths to backup defined for repo {self.repo_config.g('name')}" + return self.convert_to_json_output(False, output) # Make sure we convert paths to list if only one path is give # Also make sure we remove trailing and ending spaces @@ -843,17 +840,11 @@ class NPBackupRunner: paths = [path.strip() for path in paths] for path in paths: if path == self.repo_config.g("repo_uri"): - self.write_logs( - f"You cannot backup source into it's own path in repo {self.repo_config.g('name')}. No inception allowed !", - level="critical", - ) - return False + output = f"You cannot backup source into it's own path in repo {self.repo_config.g('name')}. No inception allowed !" + return self.convert_to_json_output(False, output) except KeyError: - self.write_logs( - f"No backup source given for repo {self.repo_config.g('name')}.", - level="error", - ) - return False + output = f"No backup source given for repo {self.repo_config.g('name')}" + return self.convert_to_json_output(False, output) source_type = self.repo_config.g("backup_opts.source_type") @@ -883,6 +874,7 @@ class NPBackupRunner: "t", "T", ): + # TODO: we need to bring this message to json self.write_logs( f"Bogus suffix for exclude_files_larger_than value given: {exclude_files_larger_than}", level="warning", diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 7045128..8e23459 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -794,9 +794,8 @@ class ResticRunner: msg = "Backend finished backup with success" else: msg = f"Backup failed backup operation:\n{output}" - # For backups, we need to return the result string restic too, for metrics analysis - result = self.convert_to_json_output(result, output, msg=msg, **kwargs) - return result, output + + return self.convert_to_json_output(result, output, msg=msg, **kwargs) @check_if_init def find(self, path: str) -> Union[bool, str, dict]: