mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-25 07:14:32 +00:00
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:
54
src/baudolo/generation.py
Normal file
54
src/baudolo/generation.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""The on-disk shape of a generation, and the manifest that states it.
|
||||
|
||||
Every name a reader needs to find payload in a generation is declared here
|
||||
once, and written into each generation's own manifest. A consumer therefore
|
||||
never has to hardcode the layout or match this package's version: it reads
|
||||
what the run that produced the tree recorded.
|
||||
|
||||
The manifest also carries what only the run itself can know: per volume,
|
||||
``database`` (it held one), ``dumped`` (a dump was produced for it) and
|
||||
``engine`` (which one was detected). Both flags true is a replayable dump;
|
||||
``database`` without ``dumped`` is a raw copy of live engine files.
|
||||
|
||||
Kept import-free: consumers read the manifest with nothing but ``json``, on
|
||||
hosts that do not have this package installed.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
FILES_DIR = "files"
|
||||
SQL_DIR = "sql"
|
||||
DUMP_SUFFIX = ".backup.sql"
|
||||
CLUSTER_SUFFIX = ".cluster.backup.sql"
|
||||
|
||||
MANIFEST_FILE = "manifest.json"
|
||||
MANIFEST_SCHEMA = 1
|
||||
|
||||
|
||||
def manifest_document(volumes: dict[str, object]) -> dict[str, object]:
|
||||
"""The manifest a finished run writes.
|
||||
|
||||
Args:
|
||||
volumes: per volume name, an object carrying ``database``, ``dumped``
|
||||
and ``engine`` -- a ``baudolo.backup.dumps.VolumeOutcome``.
|
||||
|
||||
Returns:
|
||||
The document, ready for ``json.dump``.
|
||||
"""
|
||||
return {
|
||||
"schema": MANIFEST_SCHEMA,
|
||||
"layout": {
|
||||
"files_dir": FILES_DIR,
|
||||
"sql_dir": SQL_DIR,
|
||||
"dump_suffix": DUMP_SUFFIX,
|
||||
"cluster_suffix": CLUSTER_SUFFIX,
|
||||
},
|
||||
"volumes": {
|
||||
name: {
|
||||
"database": bool(outcome.database),
|
||||
"dumped": bool(outcome.dumped),
|
||||
"engine": outcome.engine,
|
||||
}
|
||||
for name, outcome in sorted(volumes.items())
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user