From 570062f07f9c61c32a7cb0778e967ce6ce5a4e57 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Tue, 3 Dec 2019 05:00:47 +0100 Subject: [PATCH] Make generating restic command easier --- restic_volume_backup/containers_db.py | 3 +++ restic_volume_backup/restic.py | 29 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/restic_volume_backup/containers_db.py b/restic_volume_backup/containers_db.py index cb1a816..7a7e683 100644 --- a/restic_volume_backup/containers_db.py +++ b/restic_volume_backup/containers_db.py @@ -1,4 +1,5 @@ from restic_volume_backup.containers import Container +from restic_volume_backup.config import Config from restic_volume_backup import ( commands, restic, @@ -40,7 +41,9 @@ class MariadbContainer(Container): ] def backup(self): + config = Config() return restic.backup_from_stdin( + config.repository, f'/backup/{self.service_name}', self.dump_command(), ) diff --git a/restic_volume_backup/restic.py b/restic_volume_backup/restic.py index 51878a5..398f591 100644 --- a/restic_volume_backup/restic.py +++ b/restic_volume_backup/restic.py @@ -37,19 +37,19 @@ def backup_files(repository: str, source='/backup'): ]) -def backup_from_stdin(filename: str, source_command: List[str]): +def backup_from_stdin(repository: str, filename: str, source_command: List[str]): """ Backs up from stdin running the source_command passed in. It will appear in restic with the filename (including path) passed in. """ - dest_command = [ - 'restic', - "--cache-dir", - 'backup', - '--stdin', - '--stdin-filename', - filename, - ] + dest_command = restic(repository, + [ + 'backup', + '--stdin', + '--stdin-filename', + filename, + ], + ) # pipe source command into dest command source_process = Popen(source_command, stdout=PIPE) @@ -77,3 +77,14 @@ def check(repository: str): repository, "check", ]) + + +def restic(repository: str, args: List[str]): + """Generate restic command""" + return [ + "restic", + "--cache-dir", + "/restic_cache", + "-r", + repository, + ] + args