From ba642eeb4b27e970ac746e65f6c022e3a392da06 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Fri, 19 Apr 2019 00:00:28 +0200 Subject: [PATCH] Only obtain containers with backup enabled --- restic_volume_backup/cli.py | 13 +++++++++---- restic_volume_backup/containers.py | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/restic_volume_backup/cli.py b/restic_volume_backup/cli.py index 5c0673a..a45aca9 100644 --- a/restic_volume_backup/cli.py +++ b/restic_volume_backup/cli.py @@ -34,10 +34,15 @@ def status(config, containers): print() - for container in containers.containers: - print('service: {}'.format(container.service_name)) - for mount in container.filter_mounts(): - print(' - {}'.format(mount.source)) + backup_containers = containers.containers_for_backup() + for container in backup_containers: + if container.backup_enabled: + print('service: {}'.format(container.service_name)) + for mount in container.filter_mounts(): + print(' - {}'.format(mount.source)) + + if len(backup_containers) == 0: + print("No containers in the project has 'restic-volume-backup.enabled' label") print() diff --git a/restic_volume_backup/containers.py b/restic_volume_backup/containers.py index 21d4c84..d2f2fc9 100644 --- a/restic_volume_backup/containers.py +++ b/restic_volume_backup/containers.py @@ -58,7 +58,7 @@ class Container: @property def backup_enabled(self) -> bool: """Is backup enabled for this container?""" - return self.get_label('restic-volume-backup.enabled') == 'True' + return self.get_label('restic-volume-backup.enabled') is not None @property def is_backup_process_container(self) -> bool: @@ -225,6 +225,10 @@ class RunningContainers: """Is the backup process container running?""" return self.backup_process_container is not None + def containers_for_backup(self): + """Obtain all containers with backup enabled""" + return [container for container in self.containers if container.backup_enabled] + def get_service(self, name) -> Container: for container in self.containers: if container.service_name == name: