From 98a10bf9942a5bdbaec982abe8b6d799373c6bfd Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Mon, 16 Dec 2019 21:51:37 +0100 Subject: [PATCH] Mark backup process container with env variable --- src/restic_compose_backup/backup_runner.py | 2 +- src/restic_compose_backup/cli.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/restic_compose_backup/backup_runner.py b/src/restic_compose_backup/backup_runner.py index 1907bf7..3632017 100644 --- a/src/restic_compose_backup/backup_runner.py +++ b/src/restic_compose_backup/backup_runner.py @@ -17,7 +17,7 @@ def run(image: str = None, command: str = None, volumes: dict = None, labels=labels, # auto_remove=True, # We remove the container further down detach=True, - environment=environment, + environment=environment + ['BACKUP_PROCESS_CONTAINER=true'], volumes=volumes, network_mode=f'container:{source_container_id}', # Reuse original container's network stack. working_dir=os.getcwd(), diff --git a/src/restic_compose_backup/cli.py b/src/restic_compose_backup/cli.py index f6b32f0..82e4892 100644 --- a/src/restic_compose_backup/cli.py +++ b/src/restic_compose_backup/cli.py @@ -57,6 +57,9 @@ def status(config, containers): logger.info("Status for compose project '%s'", containers.project_name) logger.info("Repository: '%s'", config.repository) logger.info("Backup currently running?: %s", containers.backup_process_running) + logger.info("Checking docker availability") + + utils.list_containers() if containers.stale_backup_process_containers: utils.remove_containers(containers.stale_backup_process_containers) @@ -152,7 +155,7 @@ def backup(config, containers): def start_backup_process(config, containers): """The actual backup process running inside the spawned container""" - if containers.this_container != containers.backup_process_container: + if not utils.is_true(os.environ.get('BACKUP_PROCESS_CONTAINER')): logger.error( "Cannot run backup process in this container. Use backup command instead. " "This will spawn a new container with the necessary mounts."