Shorten all restic commands

This commit is contained in:
Einar Forselv 2019-12-03 05:06:28 +01:00
parent 570062f07f
commit 9dbb07d0c7
1 changed files with 14 additions and 36 deletions

View File

@ -14,27 +14,17 @@ def init_repo(repository: str):
Attempt to initialize the repository. Attempt to initialize the repository.
Doing this after the repository is initialized Doing this after the repository is initialized
""" """
return commands.run([ return commands.run(restic(repository, [
"restic",
"--cache-dir",
"/restic_cache",
"-r",
repository,
"init", "init",
]) ]))
def backup_files(repository: str, source='/backup'): def backup_files(repository: str, source='/backup'):
return commands.run([ return commands.run(restic(repository, [
"restic",
"--cache-dir",
"/restic_cache",
"-r",
repository,
"--verbose", "--verbose",
"backup", "backup",
source, source,
]) ]))
def backup_from_stdin(repository: str, filename: str, source_command: List[str]): def backup_from_stdin(repository: str, filename: str, source_command: List[str]):
@ -42,14 +32,12 @@ 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 = restic(repository, dest_command = restic(repository, [
[ '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)
@ -58,25 +46,15 @@ def backup_from_stdin(repository: str, filename: str, source_command: List[str])
def snapshots(repository: str): def snapshots(repository: str):
return commands.run([ return commands.run(restic(repository, [
"restic",
"--cache-dir",
"/restic_cache",
"-r",
repository,
"snapshots", "snapshots",
]) ]))
def check(repository: str): def check(repository: str):
return commands.run([ return commands.run(restic(repository, [
"restic",
"--cache-dir",
"/restic_cache",
"-r",
repository,
"check", "check",
]) ]))
def restic(repository: str, args: List[str]): def restic(repository: str, args: List[str]):