From 228eab44bbc650c0fb681378c1e3fde52f186a7d Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 22 Feb 2023 10:07:05 +0000 Subject: [PATCH] feat(backups): throw an error on a failed backup --- selfprivacy_api/backup/restic_backuper.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/selfprivacy_api/backup/restic_backuper.py b/selfprivacy_api/backup/restic_backuper.py index 5cf99cd..99d6a81 100644 --- a/selfprivacy_api/backup/restic_backuper.py +++ b/selfprivacy_api/backup/restic_backuper.py @@ -65,21 +65,15 @@ class ResticBackuper(AbstractBackuper): "backup", folder, ) - subprocess.Popen( + with subprocess.Popen( backup_command, shell=False, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - ) - - # TODO: we might want to provide logging facilities - # that are reroutable for testing - # with open("/var/backup.log", "w", encoding="utf-8") as log_file: - # subprocess.Popen( - # backup_command, - # shell=False, - # stdout=log_file, - # stderr=subprocess.STDOUT, - # ) + ) as handle: + output = handle.communicate()[0].decode("utf-8") + if "saved" not in output: + raise ValueError("could not create a new snapshot: " + output) def init(self, repo_name): init_command = self.restic_command(