Make generating restic command easier

This commit is contained in:
Einar Forselv 2019-12-03 05:00:47 +01:00
parent 364a821c55
commit 570062f07f
2 changed files with 23 additions and 9 deletions

View File

@ -1,4 +1,5 @@
from restic_volume_backup.containers import Container from restic_volume_backup.containers import Container
from restic_volume_backup.config import Config
from restic_volume_backup import ( from restic_volume_backup import (
commands, commands,
restic, restic,
@ -40,7 +41,9 @@ class MariadbContainer(Container):
] ]
def backup(self): def backup(self):
config = Config()
return restic.backup_from_stdin( return restic.backup_from_stdin(
config.repository,
f'/backup/{self.service_name}', f'/backup/{self.service_name}',
self.dump_command(), self.dump_command(),
) )

View File

@ -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. Backs up from stdin running the source_command passed in.
It will appear in restic with the filename (including path) passed in. It will appear in restic with the filename (including path) passed in.
""" """
dest_command = [ dest_command = restic(repository,
'restic', [
"--cache-dir", 'backup',
'backup', '--stdin',
'--stdin', '--stdin-filename',
'--stdin-filename', filename,
filename, ],
] )
# pipe source command into dest command # pipe source command into dest command
source_process = Popen(source_command, stdout=PIPE) source_process = Popen(source_command, stdout=PIPE)
@ -77,3 +77,14 @@ def check(repository: str):
repository, repository,
"check", "check",
]) ])
def restic(repository: str, args: List[str]):
"""Generate restic command"""
return [
"restic",
"--cache-dir",
"/restic_cache",
"-r",
repository,
] + args