mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2025-12-27 11:06:35 +00:00
- Replace legacy standalone scripts with a proper src-layout Python package (baudolo backup/restore/configure entrypoints via pyproject.toml) - Remove old scripts/files (backup-docker-to-local.py, recover-docker-from-local.sh, databases.csv.tpl, Todo.md) - Add Dockerfile to build the project image for local/E2E usage - Update Makefile: build image and run E2E via external runner script - Add scripts/test-e2e.sh: - start DinD + dedicated network - recreate DinD data volume (and shared /tmp volume) - pre-pull helper images (alpine-rsync, alpine) - load local baudolo:local image into DinD - run unittest E2E suite inside DinD and abort on first failure - on failure: dump host+DinD diagnostics and archive shared /tmp into artifacts/ - Add artifacts/ debug outputs produced by failing E2E runs (logs, events, tmp archive) https://chatgpt.com/share/694ec23f-0794-800f-9a59-8365bc80f435
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from .shell import execute_shell_command
|
|
|
|
|
|
def get_image_info(container: str) -> str:
|
|
return execute_shell_command(
|
|
f"docker inspect --format '{{{{.Config.Image}}}}' {container}"
|
|
)[0]
|
|
|
|
|
|
def has_image(container: str, pattern: str) -> bool:
|
|
"""Return True if container's image contains the pattern."""
|
|
return pattern in get_image_info(container)
|
|
|
|
|
|
def docker_volume_names() -> list[str]:
|
|
return execute_shell_command("docker volume ls --format '{{.Name}}'")
|
|
|
|
|
|
def containers_using_volume(volume_name: str) -> list[str]:
|
|
return execute_shell_command(
|
|
f"docker ps --filter volume=\"{volume_name}\" --format '{{{{.Names}}}}'"
|
|
)
|
|
|
|
|
|
def change_containers_status(containers: list[str], status: str) -> None:
|
|
"""Stop or start a list of containers."""
|
|
if not containers:
|
|
print(f"No containers to {status}.", flush=True)
|
|
return
|
|
names = " ".join(containers)
|
|
print(f"{status.capitalize()} containers: {names}...", flush=True)
|
|
execute_shell_command(f"docker {status} {names}")
|
|
|
|
|
|
def docker_volume_exists(volume: str) -> bool:
|
|
# Avoid throwing exceptions for exists checks.
|
|
try:
|
|
execute_shell_command(f"docker volume inspect {volume} >/dev/null 2>&1 && echo OK")
|
|
return True
|
|
except Exception:
|
|
return False
|