From 86c99c0be8a46dc91feb33e2477c0163e59935d9 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 3 Feb 2023 20:28:55 +0000 Subject: [PATCH] feat(backup): add backuping to restic backuper --- selfprivacy_api/backup/restic_backuper.py | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/selfprivacy_api/backup/restic_backuper.py b/selfprivacy_api/backup/restic_backuper.py index fd42791..dbfa0a9 100644 --- a/selfprivacy_api/backup/restic_backuper.py +++ b/selfprivacy_api/backup/restic_backuper.py @@ -1,3 +1,5 @@ +import subprocess + from selfprivacy_api.backup import AbstractBackuper @@ -6,6 +8,12 @@ class ResticBackuper(AbstractBackuper): self.login_flag = login_flag self.key_flag = key_flag self.type = type + self.account = "" + self.key = "" + + def set_creds(self, account: str, key: str): + self.account = account + self.key = key def restic_repo(self, repository_name: str) -> str: # https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html#other-services-via-rclone @@ -33,3 +41,21 @@ class ResticBackuper(AbstractBackuper): "-r", self.restic_repo(account, key), ].extend(args) + + def start_backup(self, folder: str): + """ + Start backup with restic + """ + backup_command = self.restic_command( + self.account, + self.key, + "backup", + folder, + ) + with open("/var/backup.log", "w", encoding="utf-8") as log_file: + subprocess.Popen( + backup_command, + shell=False, + stdout=log_file, + stderr=subprocess.STDOUT, + )