From e8123922dfd6c6d2c230f62a6085b15fd83fcc1a Mon Sep 17 00:00:00 2001
From: Einar Forselv <eforselv@gmail.com>
Date: Sun, 8 Dec 2019 03:51:57 +0100
Subject: [PATCH] Backup process label is now unique for each project

---
 src/restic_compose_backup/cli.py        |  2 +-
 src/restic_compose_backup/containers.py | 12 +++++++++++-
 src/restic_compose_backup/enums.py      |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/restic_compose_backup/cli.py b/src/restic_compose_backup/cli.py
index 08dc3fc..f976b6a 100644
--- a/src/restic_compose_backup/cli.py
+++ b/src/restic_compose_backup/cli.py
@@ -113,7 +113,7 @@ def backup(config, containers):
             environment=containers.this_container.environment,
             source_container_id=containers.this_container.id,
             labels={
-                "restic-compose-backup.backup_process": 'True',
+                containers.backup_process_label: 'True',
                 "com.docker.compose.project": containers.project_name,
             },
         )
diff --git a/src/restic_compose_backup/containers.py b/src/restic_compose_backup/containers.py
index 9eabb90..549bf19 100644
--- a/src/restic_compose_backup/containers.py
+++ b/src/restic_compose_backup/containers.py
@@ -141,7 +141,7 @@ class Container:
     @property
     def is_backup_process_container(self) -> bool:
         """Is this container the running backup process?"""
-        return self.get_label(enums.LABEL_BACKUP_PROCESS) == 'True'
+        return self.get_label(self.backup_process_label) == 'True'
 
     @property
     def is_running(self) -> bool:
@@ -158,6 +158,11 @@ class Container:
         """Name of the container/service"""
         return self.get_label('com.docker.compose.service', default='')
 
+    @property
+    def backup_process_label(self) -> str:
+        """str: The unique backup process label for this project"""
+        return f"{enums.LABEL_BACKUP_PROCESS}-{self.project_name}"
+
     @property
     def project_name(self) -> str:
         """Name of the compose setup"""
@@ -358,6 +363,11 @@ class RunningContainers:
         """str: Name of the compose project"""
         return self.this_container.project_name
 
+    @property
+    def backup_process_label(self) -> str:
+        """str: The backup process label for this project"""
+        return self.this_container.backup_process_label
+
     @property
     def backup_process_running(self) -> bool:
         """Is the backup process container running?"""
diff --git a/src/restic_compose_backup/enums.py b/src/restic_compose_backup/enums.py
index e8261be..ac557d0 100644
--- a/src/restic_compose_backup/enums.py
+++ b/src/restic_compose_backup/enums.py
@@ -8,4 +8,4 @@ LABEL_MYSQL_ENABLED = 'restic-compose-backup.mysql'
 LABEL_POSTGRES_ENABLED = 'restic-compose-backup.postgres'
 LABEL_MARIADB_ENABLED = 'restic-compose-backup.mariadb'
 
-LABEL_BACKUP_PROCESS = 'restic-compose-backup.backup_process'
+LABEL_BACKUP_PROCESS = 'restic-compose-backup.process'