diff --git a/restic_volume_backup/backup_runner.py b/restic_volume_backup/backup_runner.py index a5299ee..ded3f02 100644 --- a/restic_volume_backup/backup_runner.py +++ b/restic_volume_backup/backup_runner.py @@ -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(), ) diff --git a/restic_volume_backup/cli.py b/restic_volume_backup/cli.py index 3c9ed30..31d79d2 100644 --- a/restic_volume_backup/cli.py +++ b/restic_volume_backup/cli.py @@ -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()