Allow any repository path/backend

This commit is contained in:
Einar Forselv 2019-04-13 20:12:25 +02:00
parent 10a1dea271
commit 600b1a4392
3 changed files with 18 additions and 19 deletions

View File

@ -12,4 +12,7 @@ Backs up all docker volumes. This includes both host mapped volumes and actual d
## Configuration ## Configuration
TODO ```bash
RESTIC_REPOSITORY
RESTIC_PASSWORD
```

View File

@ -7,12 +7,12 @@ cmds = ['volumes', 'backup', 'snapshots', 'check']
class Config: class Config:
container_name = os.environ['CONTAINER_NAME'] repository = os.environ['RESTIC_REPOSITORY']
password = os.environ['RESTIC_PASSWORD'] password = os.environ['RESTIC_PASSWORD']
@classmethod @classmethod
def check(cls): def check(cls):
if not cls.container_name: if not cls.repository:
raise ValueError("CONTAINER env var not set") raise ValueError("CONTAINER env var not set")
if not cls.password: if not cls.password:
@ -34,7 +34,7 @@ def main():
if mode == 'volumes': if mode == 'volumes':
volumes = containers.volume_mounts() volumes = containers.volume_mounts()
for vol in volumes: for vol in volumes:
print(vol) # print(vol)
print(vol.mount_string()) print(vol.mount_string())
binds = containers.bind_mounts() binds = containers.bind_mounts()
@ -42,13 +42,13 @@ def main():
print(vol.mount_string()) print(vol.mount_string())
if mode == 'backup': if mode == 'backup':
restic.init_repo(Config.container_name) restic.init_repo(Config.repository)
for vol in containers.backup_volumes(): for vol in containers.backup_volumes():
restic.backup_volume(Config.container_name, vol) restic.backup_volume(Config.repository, vol)
if mode == 'snapshots': if mode == 'snapshots':
restic.snapshots(Config.container_name) restic.snapshots(Config.repository)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -2,44 +2,40 @@ import os
from subprocess import Popen, PIPE, check_call from subprocess import Popen, PIPE, check_call
def repo_path(container_name): def init_repo(repository):
return "swift:{}:/".format(container_name)
def init_repo(container_name):
run_command([ run_command([
"restic", "restic",
"-r", "-r",
repo_path(container_name), repository,
"init", "init",
]) ])
def backup_volume(container_name, volume): def backup_volume(repository, volume):
run_command([ run_command([
"restic", "restic",
"-r", "-r",
repo_path(container_name), repository,
"--verbose", "--verbose",
"backup", "backup",
volume.destination, volume.destination,
]) ])
def snapshots(container_name): def snapshots(repository):
run_command([ run_command([
"restic", "restic",
"-r", "-r",
repo_path(container_name), repository,
"snapshots", "snapshots",
]) ])
def check(container_name): def check(repository):
run_command([ run_command([
"restic", "restic",
"-r", "-r",
repo_path(container_name), repository,
"check", "check",
]) ])