From 600b1a43921862bfd2cf1775b8eeb5749b0126ad Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sat, 13 Apr 2019 20:12:25 +0200 Subject: [PATCH] Allow any repository path/backend --- README.md | 5 ++++- restic-backup/backup.py | 12 ++++++------ restic-backup/restic.py | 20 ++++++++------------ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d47c293..f411d59 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,7 @@ Backs up all docker volumes. This includes both host mapped volumes and actual d ## Configuration -TODO +```bash +RESTIC_REPOSITORY +RESTIC_PASSWORD +``` diff --git a/restic-backup/backup.py b/restic-backup/backup.py index 1f5e6f5..725bb38 100644 --- a/restic-backup/backup.py +++ b/restic-backup/backup.py @@ -7,12 +7,12 @@ cmds = ['volumes', 'backup', 'snapshots', 'check'] class Config: - container_name = os.environ['CONTAINER_NAME'] + repository = os.environ['RESTIC_REPOSITORY'] password = os.environ['RESTIC_PASSWORD'] @classmethod def check(cls): - if not cls.container_name: + if not cls.repository: raise ValueError("CONTAINER env var not set") if not cls.password: @@ -34,7 +34,7 @@ def main(): if mode == 'volumes': volumes = containers.volume_mounts() for vol in volumes: - print(vol) + # print(vol) print(vol.mount_string()) binds = containers.bind_mounts() @@ -42,13 +42,13 @@ def main(): print(vol.mount_string()) if mode == 'backup': - restic.init_repo(Config.container_name) + restic.init_repo(Config.repository) for vol in containers.backup_volumes(): - restic.backup_volume(Config.container_name, vol) + restic.backup_volume(Config.repository, vol) if mode == 'snapshots': - restic.snapshots(Config.container_name) + restic.snapshots(Config.repository) if __name__ == '__main__': main() diff --git a/restic-backup/restic.py b/restic-backup/restic.py index bf73b0f..c74b081 100644 --- a/restic-backup/restic.py +++ b/restic-backup/restic.py @@ -2,44 +2,40 @@ import os from subprocess import Popen, PIPE, check_call -def repo_path(container_name): - return "swift:{}:/".format(container_name) - - -def init_repo(container_name): +def init_repo(repository): run_command([ "restic", "-r", - repo_path(container_name), + repository, "init", ]) -def backup_volume(container_name, volume): +def backup_volume(repository, volume): run_command([ "restic", "-r", - repo_path(container_name), + repository, "--verbose", "backup", volume.destination, ]) -def snapshots(container_name): +def snapshots(repository): run_command([ "restic", "-r", - repo_path(container_name), + repository, "snapshots", ]) -def check(container_name): +def check(repository): run_command([ "restic", "-r", - repo_path(container_name), + repository, "check", ])