feat(manifest)!: record per volume what the run established

A finished generation cannot show whether a volume held a database, nor whether a dump was produced for it: under --only-sql a failed dump falls back to a file copy, and the resulting files/ tree looks like any other copy. The run knows both and threw the knowledge away as a printed warning, leaving every reader to guess from file names.

Each generation now carries a manifest.json stating its layout and, per volume, database / dumped / engine. baudolo.generation is the single place those names are spelled; restore/paths.py, backup/db.py and backup/volume.py stop repeating them. It is deliberately import-free so a consumer can read the manifest with nothing but json, on hosts where this package is not installed.

BREAKING CHANGE: BackupException is renamed BackupError. The rename is atomic across the ten modules that define or import it, three of which also carry the manifest change, so it lands in this commit rather than a separate one that could not import.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-18 01:47:38 +02:00
parent 03da186a06
commit 94637c32aa
22 changed files with 422 additions and 106 deletions

View File

@@ -3,8 +3,9 @@
from __future__ import annotations
import sys
from typing import NamedTuple
import pandas
import pandas as pd
from pandas.errors import EmptyDataError
from baudolo.databases import COLUMNS, DELIMITER
@@ -21,6 +22,19 @@ DUMP_TOOLS: tuple[tuple[str, str], ...] = (
_ENGINE_BY_IMAGE: dict[str, tuple[str, str] | None] = {}
class VolumeOutcome(NamedTuple):
"""What a dump attempt established about one volume.
``database`` says a container serving the volume speaks an engine this
tool can dump; ``dumped`` says a dump was actually written. ``engine`` is
the engine that was detected, or None when none was.
"""
database: bool
dumped: bool
engine: str | None = None
def container_engine(container: str) -> tuple[str, str] | None:
"""The (engine, dump tool) a container can serve, or None for neither.
@@ -55,15 +69,13 @@ def backup_mariadb_or_postgres(
*,
container: str,
volume_dir: str,
databases_df: pandas.DataFrame,
databases_df: pd.DataFrame,
database_containers: list[str],
) -> tuple[bool, bool]:
"""
Returns (is_db_container, dumped_any)
"""
) -> VolumeOutcome:
"""What this container contributes to its volume's outcome."""
engine = container_engine(container)
if engine is None:
return False, False
return VolumeOutcome(database=False, dumped=False)
db_type, dump_tool = engine
dumped = backup_database(
container=container,
@@ -73,20 +85,20 @@ def backup_mariadb_or_postgres(
databases_df=databases_df,
database_containers=database_containers,
)
return True, dumped
return VolumeOutcome(database=True, dumped=dumped, engine=db_type)
def _empty_databases_df() -> pandas.DataFrame:
def _empty_databases_df() -> pd.DataFrame:
"""
Create an empty DataFrame with the expected schema for databases.csv.
This allows the backup to continue without DB dumps when the CSV is missing
or empty (pandas EmptyDataError).
"""
return pandas.DataFrame(columns=list(COLUMNS))
return pd.DataFrame(columns=list(COLUMNS))
def load_databases_df(csv_path: str) -> pandas.DataFrame:
def load_databases_df(csv_path: str) -> pd.DataFrame:
"""
Load databases.csv robustly.
@@ -95,9 +107,7 @@ def load_databases_df(csv_path: str) -> pandas.DataFrame:
- Valid CSV -> return dataframe
"""
try:
return pandas.read_csv(
csv_path, sep=DELIMITER, keep_default_na=False, dtype=str
)
return pd.read_csv(csv_path, sep=DELIMITER, keep_default_na=False, dtype=str)
except FileNotFoundError:
print(
f"WARNING: databases.csv not found: {csv_path}. Continuing without database dumps.",
@@ -118,25 +128,26 @@ def backup_dumps_for_volume(
*,
containers: list[str],
vol_dir: str,
databases_df: pandas.DataFrame,
databases_df: pd.DataFrame,
database_containers: list[str],
) -> tuple[bool, bool]:
"""
Returns (found_db_container, dumped_any)
"""
) -> VolumeOutcome:
"""The volume's outcome across every container that mounts it."""
found_db = False
dumped_any = False
engine: str | None = None
for c in containers:
is_db, dumped = backup_mariadb_or_postgres(
outcome = backup_mariadb_or_postgres(
container=c,
volume_dir=vol_dir,
databases_df=databases_df,
database_containers=database_containers,
)
if is_db:
if outcome.database:
found_db = True
if dumped:
if outcome.dumped:
dumped_any = True
if engine is None:
engine = outcome.engine
return found_db, dumped_any
return VolumeOutcome(database=found_db, dumped=dumped_any, engine=engine)