fix(backup): isolate a failed volume and fail the run at the end
CI (make tests, stable, publish) / make test (push) Waiting to run

f783f2f made has_tool() re-raise every probe failure but a missing
executable, and nothing above it caught the BackupError: one paused or
crash-looping container (docker exec exit 1) aborted the whole host
backup, so every later volume, the manifest and the stamp were lost.

main() now catches BackupError around a volume's probe and dump only:
the volume's directory is removed from the generation, so the stamp
never vouches for a partial dump and a later --link-dest never takes
it for the last good copy; the error and the volume go to stderr and
the run continues. Manifest and stamp cover the volumes that
succeeded, and main() returns 1 when any volume failed. Other exception
types still abort. The existing message for an already claimed
generation is reworded (MEDUSA SQL wording rule).

test_app_volume_failure.py runs main() over a real generation in a
temp dir: non-zero exit, the later volume still copied, no directory
for the failed volume at stamp time, the manifest listing only the good
volume, stderr naming volume and error, and a RuntimeError still
aborting. Against f783f2f five of the six tests fail. Operator decision
310c8a1f5201cbb1.

🎯 Fix: 92 %
💥 Break: 4 %
💸 Tokens: 100 %
⏱️ Velocity: 100 %
🛡️ Security: 100 %
🏆 Score: 92
🚦 Gate: unit suite 281 OK + negative control; ruff clean; MEDUSA 100

Created-with: https://s.veen.world/skills

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-12-02 15:12:55 +00:00
1 parent ab717debf1
commit b3c22a1286
3 files changed
+160 -7

No files matched your search

+28 -6
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import sys
from contextlib import ExitStack
from datetime import datetime
from pathlib import Path
@@ -18,6 +19,7 @@ from .dumps import VolumeOutcome, backup_dumps_for_volume, load_databases_df
from .layout import (
create_version_directory,
create_volume_directory,
discard_volume_directory,
get_machine_id,
stamp_directory,
write_manifest,
@@ -44,6 +46,7 @@ def main() -> int:
print("💾 Start volume backups...", flush=True)
outcomes: dict[str, VolumeOutcome] = {}
failed: list[str] = []
with ExitStack() as stack:
resolve_source = None
@@ -75,12 +78,23 @@ def main() -> int:
outcome = VolumeOutcome(database=False, dumped=False)
if not args.only_files:
outcome = backup_dumps_for_volume(
containers=containers,
vol_dir=vol_dir,
databases_df=databases_df,
database_containers=args.database_containers,
)
try:
outcome = backup_dumps_for_volume(
containers=containers,
vol_dir=vol_dir,
databases_df=databases_df,
database_containers=args.database_containers,
)
except BackupError as error:
discard_volume_directory(vol_dir)
failed.append(volume_name)
print(
f"ERROR: backup of volume '{volume_name}' failed; it is "
f"left out of this generation.\n{error}",
file=sys.stderr,
flush=True,
)
continue
outcomes[volume_name] = outcome
if args.only_sql and outcome.database:
@@ -151,4 +165,12 @@ def main() -> int:
print("Handling Docker Compose services...", flush=True)
handle_docker_compose_services(args.compose_dir, args.hard_restart_projects)
if failed:
print(
f"ERROR: {len(failed)} volume(s) failed and are missing from "
f"{version_dir}: {', '.join(failed)}",
file=sys.stderr,
flush=True,
)
return 1
return 0