From cecc647a10e90608bec392a0f16df99dd3b5fdb6 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sat, 7 Mar 2020 02:56:36 +0100 Subject: [PATCH] Include swarm containers when SWARM_MODE is set --- src/restic_compose_backup/containers.py | 26 +++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/restic_compose_backup/containers.py b/src/restic_compose_backup/containers.py index fb68e47..a05e638 100644 --- a/src/restic_compose_backup/containers.py +++ b/src/restic_compose_backup/containers.py @@ -4,6 +4,7 @@ from pathlib import Path from typing import List from restic_compose_backup import enums, utils +from restic_compose_backup.config import config logger = logging.getLogger(__name__) @@ -71,7 +72,9 @@ class Container: @property def service_name(self) -> str: """Name of the container/service""" - return self.get_label('com.docker.compose.service', default='') + name = self.get_label('com.docker.compose.service', default='') + if not name: + return self.get_label('com.docker.swarm.service.name', default='') @property def backup_process_label(self) -> str: @@ -359,11 +362,22 @@ class RunningContainers: if container.is_backup_process_container: self.backup_process_container = container - # Detect containers belonging to the current compose setup - if (container.project_name == self.this_container.project_name - and not container.is_oneoff): - if container != self.backup_process_container: - self.containers.append(container) + # --- Determine what containers should be evaludated + + # If not swarm mode we need to filter in compose project + if not config.swarm_mode: + if container.project_name != self.this_container.project_name: + continue + + # Containers started manually are not included + if container.is_oneoff: + continue + + # Do not include the backup process container + if container == self.backup_process_container: + continue + + self.containers.append(container) @property def project_name(self) -> str: