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.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(),
)

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.
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