restic: generic backup_from_stdin

This commit is contained in:
Einar Forselv 2019-12-03 04:23:47 +01:00
parent e17ed8adf1
commit 364a821c55
1 changed files with 19 additions and 25 deletions

View File

@ -2,13 +2,14 @@
Restic commands Restic commands
""" """
import logging import logging
from typing import List
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from restic_volume_backup import commands from restic_volume_backup import commands
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def init_repo(repository): 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
@ -23,7 +24,7 @@ def init_repo(repository):
]) ])
def backup_files(repository, source='/backup'): def backup_files(repository: str, source='/backup'):
return commands.run([ return commands.run([
"restic", "restic",
"--cache-dir", "--cache-dir",
@ -36,34 +37,27 @@ def backup_files(repository, source='/backup'):
]) ])
def backup_mysql_all(repository, host, port, user, password, filename): def backup_from_stdin(filename: str, source_command: List[str]):
"""Backup all mysql databases""" """
# -h host, -p password Backs up from stdin running the source_command passed in.
return commands.run([ It will appear in restic with the filename (including path) passed in.
'mysqldump', """
'--host', dest_command = [
host,
'--port',
port,
'--user',
user,
'--password',
password,
'|',
'restic', 'restic',
"--cache-dir",
'backup', 'backup',
'--stdin', '--stdin',
'--stdin-filename', '--stdin-filename',
'dump.sql' filename,
]) ]
# pipe source command into dest command
source_process = Popen(source_command, stdout=PIPE)
dest_process = Popen(dest_command, stdin=source_process.stdout)
return dest_process.communicate()
def backup_mysql_database(repository, host, port, user, password, filename, database): def snapshots(repository: str):
"""Backup a single database"""
pass
def snapshots(repository):
return commands.run([ return commands.run([
"restic", "restic",
"--cache-dir", "--cache-dir",
@ -74,7 +68,7 @@ def snapshots(repository):
]) ])
def check(repository): def check(repository: str):
return commands.run([ return commands.run([
"restic", "restic",
"--cache-dir", "--cache-dir",