add_backup_paths: extract and merge paths from includes/excludes

This commit is contained in:
Moritz 2024-09-17 13:44:26 +02:00
parent 6ac781c7e6
commit b8d61d01cd

View File

@ -153,8 +153,7 @@ def get_backup_details(app_settings):
# if SERVICE and SERVICE != app:
# continue
backup_apps.append(app)
paths = (settings['volume_paths'] - settings['excluded_volumes']).union(settings['included_paths'])
backup_paths = backup_paths.union(paths)
add_backup_paths(backup_paths, settings, app)
if hooks:= settings.get('pre_hooks'):
pre_hooks.update(hooks)
if hooks:= settings.get('post_hooks'):
@ -162,6 +161,27 @@ def get_backup_details(app_settings):
return pre_hooks, post_hooks, list(backup_paths), backup_apps
def add_backup_paths(backup_paths, settings, app):
if (volumes := settings.get('volumes')):
if includes:= settings.get('included_volume_paths'):
included_volumes = list(zip(*includes))[0]
for volume, rel_paths in includes:
if not (volume_path:= volumes.get(volume)):
logger.error(f'Can not find volume with the name {volume}')
continue
for p in rel_paths:
absolute_path = Path(f"{volume_path}/{p}")
backup_paths.add(absolute_path)
else:
included_volumes = []
excluded_volumes = settings.get('excluded_volumes') or []
for name, path in volumes.items():
if name not in excluded_volumes and name not in included_volumes:
backup_paths.add(path)
else:
logger.warning(f"{app} does not contain any volumes")
def parse_volumes(stack_name, mounts):
volumes = {}
for m in mounts: