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:
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",

View file

@ -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]: