From 42566815c4dd74a94546a9cda58044be81bd5b17 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 14 Jan 2024 01:25:54 +0100 Subject: [PATCH] solved start bug --- backup-docker-to-local.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/backup-docker-to-local.py b/backup-docker-to-local.py index a553ac1..601fc1c 100644 --- a/backup-docker-to-local.py +++ b/backup-docker-to-local.py @@ -170,18 +170,15 @@ def has_image(container,image): """Check if the container is using the image""" image_info = get_image_info(container) return image in image_info[0] - -def stop_containers(containers): + +def change_containers_status(containers,status): """Stop a list of containers.""" - container_list = ' '.join(containers) - print(f"Stopping containers {container_list}...") - execute_shell_command(f"docker stop {container_list}") - -def start_containers(containers): - """Start a list of containers.""" - container_list = ' '.join(containers) - print(f"Start containers {container_list}...") - execute_shell_command(f"docker start {container_list}") + if containers: + container_list = ' '.join(containers) + print(f"{status} containers {container_list}...") + execute_shell_command(f"docker {status} {container_list}") + else: + print(f"No containers to {status}.") def get_container_with_image(containers,image): for container in containers: @@ -217,15 +214,12 @@ def is_image_ignored(container): return False def backup_with_containers_paused(volume_name, volume_dir, containers, shutdown): - if containers: - stop_containers(containers) - else: - print(f"{volume_name} has no containers to stop. Skipped.") + change_containers_status(containers,'stop') backup_volume(volume_name, volume_dir) # Just restart containers if shutdown is false if not shutdown: - start_containers(containers) + change_containers_status(containers,'start') def backup_mariadb_or_postgres(container, volume_dir): '''Performs database image specific backup procedures'''