Extend backup_runner with additonal parameters

This commit is contained in:
Einar Forselv 2019-04-17 20:20:52 +02:00
parent 2913398564
commit dd091041b8
2 changed files with 14 additions and 16 deletions

View File

@ -5,7 +5,7 @@ import docker
from restic_volume_backup.config import Config
def run(image: str, command: str):
def run(image: str = None, command: str = None, volumes: dict = None, enviroment: dict = None):
config = Config()
client = docker.DockerClient(base_url=config.docker_base_url)
@ -15,14 +15,8 @@ def run(image: str, command: str):
labels={"restic-volume-backup.backup_process": 'True'},
auto_remove=True,
detach=True,
environment={
'test1': 'value1',
'test2': 'value2',
},
volumes={
'/home/user1/': {'bind': '/mnt/vol2', 'mode': 'rw'},
'/var/www': {'bind': '/mnt/vol1', 'mode': 'ro'},
},
environment={},
volumes=volumes,
working_dir=os.getcwd(),
)

View File

@ -25,8 +25,9 @@ def main():
print()
elif args.action == 'backup':
# Make sure we don't spawn multiple backup processes
if containers.backup_process_running:
raise ValueError("Backup process alredy running")
raise ValueError("Backup process already running")
print("Initializing repository")
@ -35,19 +36,22 @@ def main():
print("Starting backup container..")
backup_runner.run(
containers.this_container.image,
# "sleep 10",
'./test.sh',
image=containers.this_container.image,
command='restic-volume-backup start-backup-process',
volumes={},
enviroment={},
)
# for vol in containers.backup_volumes():
# restic.backup_volume(Config.repository, vol)
# Separate command to avoid spawning infinite containers :)
elif args.action == 'start-backup-process':
print("start-backup-process")
def parse_args():
parser = argparse.ArgumentParser(prog='restic_volume_backup')
parser.add_argument(
'action',
choices=['status', 'backup'],
choices=['status', 'backup', 'start-backup-process'],
)
return parser.parse_args()