WIP: Change restic backup output to json compat format

This commit is contained in:
Orsiris de Jong 2024-01-09 21:50:42 +01:00
parent fca5343f52
commit e53e92ad0c
2 changed files with 9 additions and 18 deletions

View file

@ -829,11 +829,8 @@ class NPBackupRunner:
if not read_from_stdin: if not read_from_stdin:
paths = self.repo_config.g("backup_opts.paths") paths = self.repo_config.g("backup_opts.paths")
if not paths: if not paths:
self.write_logs( output = f"No paths to backup defined for repo {self.repo_config.g('name')}"
f"No paths to backup defined for repo {self.repo_config.g('name')}.", return self.convert_to_json_output(False, output)
level="error",
)
return False
# Make sure we convert paths to list if only one path is give # Make sure we convert paths to list if only one path is give
# Also make sure we remove trailing and ending spaces # Also make sure we remove trailing and ending spaces
@ -843,17 +840,11 @@ class NPBackupRunner:
paths = [path.strip() for path in paths] paths = [path.strip() for path in paths]
for path in paths: for path in paths:
if path == self.repo_config.g("repo_uri"): if path == self.repo_config.g("repo_uri"):
self.write_logs( output = f"You cannot backup source into it's own path in repo {self.repo_config.g('name')}. No inception allowed !"
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)
level="critical",
)
return False
except KeyError: except KeyError:
self.write_logs( output = f"No backup source given for repo {self.repo_config.g('name')}"
f"No backup source given for repo {self.repo_config.g('name')}.", return self.convert_to_json_output(False, output)
level="error",
)
return False
source_type = self.repo_config.g("backup_opts.source_type") source_type = self.repo_config.g("backup_opts.source_type")
@ -883,6 +874,7 @@ class NPBackupRunner:
"t", "t",
"T", "T",
): ):
# TODO: we need to bring this message to json
self.write_logs( self.write_logs(
f"Bogus suffix for exclude_files_larger_than value given: {exclude_files_larger_than}", f"Bogus suffix for exclude_files_larger_than value given: {exclude_files_larger_than}",
level="warning", level="warning",

View file

@ -794,9 +794,8 @@ class ResticRunner:
msg = "Backend finished backup with success" msg = "Backend finished backup with success"
else: else:
msg = f"Backup failed backup operation:\n{output}" 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 self.convert_to_json_output(result, output, msg=msg, **kwargs)
return result, output
@check_if_init @check_if_init
def find(self, path: str) -> Union[bool, str, dict]: def find(self, path: str) -> Union[bool, str, dict]: