From c5b7f11db7e1f6964ebecc18fcbd4762791e47b1 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Tue, 10 Dec 2019 07:57:37 +0100 Subject: [PATCH] Attempt to partly fix #18 --- docker-compose.yaml | 3 +++ src/restic_compose_backup/cli.py | 11 +++++++++-- src/restic_compose_backup/containers.py | 4 +++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index f98f6fc..1308815 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,6 +5,9 @@ services: env_file: - restic_compose_backup.env - alerts.env + labels: + restic-compose-backup.volumes: true + restic-compose-backup.volumes.include: 'src' volumes: # Map in docker socket - /var/run/docker.sock:/tmp/docker.sock:ro diff --git a/src/restic_compose_backup/cli.py b/src/restic_compose_backup/cli.py index ec7af3d..f6b32f0 100644 --- a/src/restic_compose_backup/cli.py +++ b/src/restic_compose_backup/cli.py @@ -117,6 +117,7 @@ def backup(config, containers): mounts = containers.generate_backup_mounts('/volumes') volumes.update(mounts) + logger.debug('Starting backup container with image %s', containers.this_container.image) try: result = backup_runner.run( image=containers.this_container.image, @@ -151,12 +152,18 @@ def backup(config, containers): def start_backup_process(config, containers): """The actual backup process running inside the spawned container""" - if (not containers.backup_process_container - or containers.this_container == containers.backup_process_container is False): + if containers.this_container != containers.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." ) + alerts.send( + subject="Cannot run backup process in this container", + body=( + "Cannot run backup process in this container. Use backup command instead. " + "This will spawn a new container with the necessary mounts." + ) + ) exit(1) status(config, containers) diff --git a/src/restic_compose_backup/containers.py b/src/restic_compose_backup/containers.py index 7cbf1d7..92200fe 100644 --- a/src/restic_compose_backup/containers.py +++ b/src/restic_compose_backup/containers.py @@ -1,9 +1,11 @@ import os +import logging from pathlib import Path from typing import List from restic_compose_backup import enums, utils +logger = logging.getLogger(__name__) VOLUME_TYPE_BIND = "bind" VOLUME_TYPE_VOLUME = "volume" @@ -355,7 +357,7 @@ class RunningContainers: # Detect containers belonging to the current compose setup if (container.project_name == self.this_container.project_name and not container.is_oneoff): - if container.id != self.this_container.id: + if container != self.backup_process_container: self.containers.append(container) @property