mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-20 13:12:48 +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:
@@ -1,5 +1,8 @@
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from baudolo.generation import FILES_DIR, MANIFEST_FILE, MANIFEST_SCHEMA, SQL_DIR
|
||||
|
||||
from .helpers import (
|
||||
POSTGRES_DATA_DIR,
|
||||
POSTGRES_IMAGE,
|
||||
@@ -159,6 +162,31 @@ class TestE2EOnlySqlFallbackToFiles(unittest.TestCase):
|
||||
f"Did not expect SQL dump files, found: {dumps}",
|
||||
)
|
||||
|
||||
def manifest(self) -> dict:
|
||||
generation = backup_path(
|
||||
self.backups_dir, self.repo_name, self.version, self.pg_volume
|
||||
).parent
|
||||
return json.loads((generation / MANIFEST_FILE).read_text(encoding="utf-8"))
|
||||
|
||||
def test_the_manifest_records_the_volume_as_a_database_left_undumped(self) -> None:
|
||||
"""The fallback is invisible in the tree: files/ looks like any copy."""
|
||||
self.assertEqual(
|
||||
self.manifest()["volumes"][self.pg_volume],
|
||||
{"database": True, "dumped": False, "engine": "postgres"},
|
||||
)
|
||||
|
||||
def test_the_manifest_layout_names_where_the_payload_really_landed(self) -> None:
|
||||
layout = self.manifest()["layout"]
|
||||
volume_dir = backup_path(
|
||||
self.backups_dir, self.repo_name, self.version, self.pg_volume
|
||||
)
|
||||
self.assertTrue((volume_dir / layout["files_dir"]).is_dir())
|
||||
self.assertEqual(layout["files_dir"], FILES_DIR)
|
||||
self.assertEqual(layout["sql_dir"], SQL_DIR)
|
||||
|
||||
def test_the_manifest_states_a_schema_a_reader_can_check(self) -> None:
|
||||
self.assertEqual(self.manifest()["schema"], MANIFEST_SCHEMA)
|
||||
|
||||
def test_restored_files_contain_marker(self) -> None:
|
||||
p = run(
|
||||
[
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from baudolo.generation import MANIFEST_FILE
|
||||
|
||||
from .helpers import (
|
||||
POSTGRES_DATA_DIR,
|
||||
POSTGRES_IMAGE,
|
||||
@@ -179,3 +182,21 @@ class TestE2EOnlySqlMixedRun(unittest.TestCase):
|
||||
(base / "files").exists(),
|
||||
f"Expected non-DB volume files backup to exist at: {base / 'files'}",
|
||||
)
|
||||
|
||||
def manifest(self) -> dict:
|
||||
generation = backup_path(
|
||||
self.backups_dir, self.repo_name, self.version, self.db_volume
|
||||
).parent
|
||||
return json.loads((generation / MANIFEST_FILE).read_text(encoding="utf-8"))
|
||||
|
||||
def test_the_manifest_records_the_dumped_volume_as_dumped(self) -> None:
|
||||
self.assertEqual(
|
||||
self.manifest()["volumes"][self.db_volume],
|
||||
{"database": True, "dumped": True, "engine": "postgres"},
|
||||
)
|
||||
|
||||
def test_the_manifest_records_the_plain_volume_as_no_database(self) -> None:
|
||||
self.assertEqual(
|
||||
self.manifest()["volumes"][self.files_volume],
|
||||
{"database": False, "dumped": False, "engine": None},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user