From 14174a46802e9fd7cdb0a9db7d7964b357597bb7 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Fri, 29 Nov 2019 01:25:00 +0100 Subject: [PATCH] expand restic commands --- restic_volume_backup/restic.py | 66 +++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/restic_volume_backup/restic.py b/restic_volume_backup/restic.py index 8f68171..1d3f6fa 100644 --- a/restic_volume_backup/restic.py +++ b/restic_volume_backup/restic.py @@ -4,9 +4,7 @@ from subprocess import Popen, PIPE logger = logging.getLogger(__name__) def test(): - run_command(['pwd']) - run_command(['ls', '-l']) - run_command(['ls', '/backup']) + return run_command(['ls', '/backup']) def init_repo(repository): @@ -14,28 +12,76 @@ def init_repo(repository): Attempt to initialize the repository. Doing this after the repository is initialized """ - run_command([ + return run_command([ "restic", + "--cache-dir", + "/restic_cache", "-r", repository, "init", ]) -def backup_volume(repository, volume): - run_command([ +def backup_files(repository, source='/backup'): + return run_command([ "restic", + "--cache-dir", + "/restic_cache", "-r", repository, "--verbose", "backup", - volume.destination, + source, ]) +def backup_mysql_all(repository, host, port, user, password, filename): + """Backup all mysql databases""" + # -h host, -p password + return run_command([ + 'mysqldump', + '--host', + host, + '--port', + port, + '--user', + user, + '--password', + password, + '|', + 'restic', + 'backup', + '--stdin', + '--stdin-filename', + 'dump.sql' + ]) + + +def backup_mysql_database(repository, host, port, user, password, filename, database): + """Backup a single database""" + pass + + +def mysql_ping(host, port, username, password): + """Check if the database is up and can be reached""" + return run_command([ + 'mysqladmin', + 'ping', + '--host', + host, + '--port', + port, + '-user', + username, + '--password', + password, + ]) + def snapshots(repository): - run_command([ + return run_command([ "restic", + "--cache-dir", + "/restic_cache", "-r", repository, "snapshots", @@ -43,8 +89,10 @@ def snapshots(repository): def check(repository): - run_command([ + return run_command([ "restic", + "--cache-dir", + "/restic_cache", "-r", repository, "check",