get_backup_details/add_backup_paths: filter by volumes
This commit is contained in:
parent
249772ec03
commit
eb7c35d4cd
22
backupbot.py
22
backupbot.py
@ -193,7 +193,7 @@ def parse_backup_labels(hook_type='backup', selected_container=[]):
|
|||||||
return app_settings
|
return app_settings
|
||||||
|
|
||||||
|
|
||||||
def get_backup_details(app_settings):
|
def get_backup_details(app_settings, volumes=[]):
|
||||||
backup_paths = set()
|
backup_paths = set()
|
||||||
backup_apps = []
|
backup_apps = []
|
||||||
pre_hooks= {}
|
pre_hooks= {}
|
||||||
@ -205,7 +205,7 @@ def get_backup_details(app_settings):
|
|||||||
# if SERVICE and SERVICE != app:
|
# if SERVICE and SERVICE != app:
|
||||||
# continue
|
# continue
|
||||||
backup_apps.append(app)
|
backup_apps.append(app)
|
||||||
add_backup_paths(backup_paths, settings, app)
|
add_backup_paths(backup_paths, settings, app, volumes)
|
||||||
if hooks:= settings.get('pre_hooks'):
|
if hooks:= settings.get('pre_hooks'):
|
||||||
pre_hooks.update(hooks)
|
pre_hooks.update(hooks)
|
||||||
if hooks:= settings.get('post_hooks'):
|
if hooks:= settings.get('post_hooks'):
|
||||||
@ -213,7 +213,7 @@ def get_backup_details(app_settings):
|
|||||||
return pre_hooks, post_hooks, list(backup_paths), backup_apps
|
return pre_hooks, post_hooks, list(backup_paths), backup_apps
|
||||||
|
|
||||||
|
|
||||||
def add_backup_paths(backup_paths, settings, app):
|
def add_backup_paths(backup_paths, settings, app, selected_volumes):
|
||||||
if (volumes := settings.get('volumes')):
|
if (volumes := settings.get('volumes')):
|
||||||
if includes:= settings.get('included_volume_paths'):
|
if includes:= settings.get('included_volume_paths'):
|
||||||
included_volumes = list(zip(*includes))[0]
|
included_volumes = list(zip(*includes))[0]
|
||||||
@ -221,6 +221,9 @@ def add_backup_paths(backup_paths, settings, app):
|
|||||||
if not (volume_path:= volumes.get(volume)):
|
if not (volume_path:= volumes.get(volume)):
|
||||||
logger.error(f'Can not find volume with the name {volume}')
|
logger.error(f'Can not find volume with the name {volume}')
|
||||||
continue
|
continue
|
||||||
|
if selected_volumes and volume not in selected_volumes:
|
||||||
|
logger.debug(f'Skipping {volume}:{rel_paths} because the volume is not selected')
|
||||||
|
continue
|
||||||
for p in rel_paths:
|
for p in rel_paths:
|
||||||
absolute_path = Path(f"{volume_path}/{p}")
|
absolute_path = Path(f"{volume_path}/{p}")
|
||||||
backup_paths.add(absolute_path)
|
backup_paths.add(absolute_path)
|
||||||
@ -228,8 +231,16 @@ def add_backup_paths(backup_paths, settings, app):
|
|||||||
included_volumes = []
|
included_volumes = []
|
||||||
excluded_volumes = settings.get('excluded_volumes') or []
|
excluded_volumes = settings.get('excluded_volumes') or []
|
||||||
for name, path in volumes.items():
|
for name, path in volumes.items():
|
||||||
if name not in excluded_volumes and name not in included_volumes:
|
if selected_volumes and name not in selected_volumes:
|
||||||
backup_paths.add(path)
|
logger.debug(f'Skipping volume: {name} because the volume is not selected')
|
||||||
|
continue
|
||||||
|
if name in excluded_volumes:
|
||||||
|
logger.debug(f'Skipping volume: {name} because the volume is excluded')
|
||||||
|
continue
|
||||||
|
if name in included_volumes:
|
||||||
|
logger.debug(f'Skipping volume: {name} because a path is selected')
|
||||||
|
continue
|
||||||
|
backup_paths.add(path)
|
||||||
else:
|
else:
|
||||||
logger.warning(f"{app} does not contain any volumes")
|
logger.warning(f"{app} does not contain any volumes")
|
||||||
|
|
||||||
@ -242,7 +253,6 @@ def parse_volumes(stack_name, mounts):
|
|||||||
relative_path = m['Source']
|
relative_path = m['Source']
|
||||||
name = relative_path.removeprefix(stack_name + '_')
|
name = relative_path.removeprefix(stack_name + '_')
|
||||||
absolute_path = Path(f"{VOLUME_PATH}{relative_path}/_data/")
|
absolute_path = Path(f"{VOLUME_PATH}{relative_path}/_data/")
|
||||||
#TODO: if absolute_path.exists():
|
|
||||||
volumes[name] = absolute_path
|
volumes[name] = absolute_path
|
||||||
return volumes
|
return volumes
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user