diff --git a/backupbot.py b/backupbot.py index 077cd6b..3df0562 100755 --- a/backupbot.py +++ b/backupbot.py @@ -85,6 +85,7 @@ def get_backup_cmds(): services = client.services.list() for s in services: labels = s.attrs['Spec']['Labels'] + mounts = s.attrs['Spec']['Mounts'] if (backup := labels.get('backupbot.backup')) and bool(backup): stack_name = labels['com.docker.stack.namespace'] # Remove this lines to backup only a specific service @@ -92,9 +93,15 @@ def get_backup_cmds(): # if SERVICE and SERVICE != stack_name: # continue backup_apps.add(stack_name) - backup_paths = backup_paths.union( - Path(VOLUME_PATH).glob(f"{stack_name}_*")) - if not (container:= container_by_service.get(s.name)): + for mount in mounts: + if path := labels.get('backupbot.backup.path'): + path_ = Path(VOLUME_PATH).glob(f"{stack_name}_{mount['Source']}/_data/{path}") + else: + path_ = Path(VOLUME_PATH).glob(f"{stack_name}_{mount['Source']}") + logging.debug( + f"Added backup path {path_}") + backup_paths = backup_paths.union(path_) + if not (container := container_by_service.get(s.name)): logging.error( f"Container {s.name} is not running, hooks can not be executed") continue