mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-10-31 23:33:11 +01:00
Ignored images
This commit is contained in:
parent
3fedf49f4e
commit
407eddc2c3
@ -152,22 +152,39 @@ def create_volume_directory(version_dir,volume_name):
|
|||||||
pathlib.Path(volume_dir).mkdir(parents=True, exist_ok=True)
|
pathlib.Path(volume_dir).mkdir(parents=True, exist_ok=True)
|
||||||
return volume_dir
|
return volume_dir
|
||||||
|
|
||||||
|
def is_image_ignored(container, ignored_images):
|
||||||
|
"""Check if the container's image is one of the ignored images."""
|
||||||
|
for image in ignored_images:
|
||||||
|
if has_image(container, image):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def backup_routine_for_volume(volume_name, containers, databases, version_dir, whitelisted_images, versions_dir):
|
def backup_routine_for_volume(volume_name, containers, databases, version_dir, whitelisted_images, versions_dir):
|
||||||
"""Perform backup routine for a given volume."""
|
"""Perform backup routine for a given volume."""
|
||||||
|
ignored_images = ['redis', 'memcached']
|
||||||
|
|
||||||
for container in containers:
|
for container in containers:
|
||||||
|
if is_image_ignored(container, ignored_images):
|
||||||
|
print(f"Ignoring volume '{volume_name}' linked to container '{container}' with ignored image.")
|
||||||
|
continue
|
||||||
|
|
||||||
volume_dir = create_volume_directory(version_dir, volume_name)
|
volume_dir = create_volume_directory(version_dir, volume_name)
|
||||||
if has_image(container, 'mariadb'):
|
if has_image(container, 'mariadb'):
|
||||||
backup_database(container, databases, volume_dir, 'mariadb')
|
backup_database(container, databases, volume_dir, 'mariadb')
|
||||||
elif has_image(container, 'postgres'):
|
continue
|
||||||
|
|
||||||
|
if has_image(container, 'postgres'):
|
||||||
backup_database(container, databases, volume_dir, 'postgres')
|
backup_database(container, databases, volume_dir, 'postgres')
|
||||||
else:
|
continue
|
||||||
# Backup without start, stop to keep downtime low
|
|
||||||
backup_volume(volume_name, volume_dir, versions_dir)
|
backup_volume(volume_name, volume_dir, versions_dir)
|
||||||
if is_any_image_not_whitelisted(containers, whitelisted_images):
|
if is_any_image_not_whitelisted(containers, whitelisted_images):
|
||||||
stop_containers(containers)
|
stop_containers(containers)
|
||||||
backup_volume(volume_name, volume_dir, versions_dir)
|
backup_volume(volume_name, volume_dir, versions_dir)
|
||||||
start_containers(containers)
|
start_containers(containers)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print('Start backup routine...')
|
print('Start backup routine...')
|
||||||
dirname = os.path.dirname(__file__)
|
dirname = os.path.dirname(__file__)
|
||||||
|
Loading…
Reference in New Issue
Block a user