From a72753921a55c4651ea8aba5fe5716907d1266bb Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 26 Dec 2023 20:20:26 +0100 Subject: [PATCH] Execute backup just once per volume and not once per volume container --- backup-docker-to-local.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backup-docker-to-local.py b/backup-docker-to-local.py index ca6c2d7..16b5441 100644 --- a/backup-docker-to-local.py +++ b/backup-docker-to-local.py @@ -161,22 +161,28 @@ def is_image_ignored(container, ignored_images): def backup_routine_for_volume(volume_name, containers, databases, version_dir, whitelisted_images, versions_dir): """Perform backup routine for a given volume.""" - ignored_images = ['redis', 'memcached'] - for container in containers: - if is_image_ignored(container, ignored_images): + + # Skip ignored images + if is_image_ignored(container, ['redis', 'memcached']): print(f"Ignoring volume '{volume_name}' linked to container '{container}' with ignored image.") - continue + continue + # Directory which contains files and sqls volume_dir = create_volume_directory(version_dir, volume_name) + + # Execute MariaDB procedure if has_image(container, 'mariadb'): backup_database(container, databases, volume_dir, 'mariadb') - continue - + return + + # Execute Postgres procedure if has_image(container, 'postgres'): backup_database(container, databases, volume_dir, 'postgres') - continue - + return + + # Execute backup if image is not ignored + if volume_dir: backup_volume(volume_name, volume_dir, versions_dir) if is_any_image_not_whitelisted(containers, whitelisted_images): stop_containers(containers)