mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-09 20:26:33 +00:00
fix(svc-bkp-nfs-2-local): leave backup-disabled volumes out of the export snapshot
The NFS backup rsynced the whole export and honoured only one exclude, the shared backup root. Volumes declared `backup: false` were copied anyway and then pulled a second time by remote-2-local; in the swarm DR drill of Magento#0 (run 40625679270) docs_sites alone (a full repo clone plus its prepared and work trees) took about 15.5 GiB per copy and filled the runner. The volume backup already skipped these through the backup_volume lookup; only the NFS path ignored the declaration. - utils/storage/nfs.py: volume_dir() names the state directory a volume binds to (pinned name or key), shared with compose_volumes; backup_disabled_dirs() returns every NFS-backed `backup: false` volume dir that no backed-up volume also binds to. - The role-local lookup backup_nfs_excludes feeds them into BKP_NFS_2_LOCAL_EXCLUDES next to the backup root; script.sh takes any number of excludes. Compose installs still pass only the backup root. - recover.py protects every live state directory the snapshot does not hold, so `rsync --delete` keeps the excluded volumes (model weights, the docs tree, caches) and volumes created after the snapshot instead of wiping them. - The swarm DR drill restores BACKUP_NFS_VOLUME, the first NFS volume not declared `backup: false`; PRIMARY_NFS_VOLUME stays for the drain tests. BookWyrm now drills bookwyrm_media; decidim, fusiondirectory, meta, coturn, svc-registry-cache and svc-registry-docker have nothing backed up on NFS and skip the drill. Measured: compose_volumes renders identically before and after for 291 roles across compose/swarm x local/nfs (1940 of 1940); the 15 excluded directories are exactly the backup-disabled device dirs; the systemd unit renders shell-safe on ansible-core 2.20 and 2.21 and stays byte-identical in compose and swarm-local. A new unit test runs the real script.sh over two generations and the real recover.py back into the export, and fails without the restore protection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
39df0967d7
commit
4fcf097e5b
16 files changed
+428
-48
No files matched your search
@@ -188,6 +188,27 @@ class NfsRecoverTests(unittest.TestCase):
|
||||
)
|
||||
self.assertFalse((target / "stale.txt").exists())
|
||||
|
||||
def test_a_volume_the_snapshot_does_not_hold_survives_the_restore(self):
|
||||
mod = _load("svc-bkp-nfs-2-local", "nfs_recover")
|
||||
state = mod.STATE_SUBDIR
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
source = Path(td) / "source"
|
||||
target = Path(td) / "target"
|
||||
(source / state / "app_data").mkdir(parents=True)
|
||||
(source / state / "app_data" / "db").write_text("from-snapshot")
|
||||
(target / state / "app_data").mkdir(parents=True)
|
||||
(target / state / "app_data" / "stale").write_text("pre-recover")
|
||||
(target / state / "docs_sites").mkdir(parents=True)
|
||||
(target / state / "docs_sites" / "site").write_text("regenerable")
|
||||
recovery = mod.NfsExportRecovery(
|
||||
str(source), str(target), service_backup=False
|
||||
)
|
||||
self.assertEqual(recovery.volumes_missing_from_snapshot(), ["docs_sites"])
|
||||
recovery.restore()
|
||||
self.assertTrue((target / state / "docs_sites" / "site").exists())
|
||||
self.assertTrue((target / state / "app_data" / "db").exists())
|
||||
self.assertFalse((target / state / "app_data" / "stale").exists())
|
||||
|
||||
def test_main_wires_argparse_to_recovery(self):
|
||||
mod = _load("svc-bkp-nfs-2-local", "nfs_recover")
|
||||
for argv, expect_backup in (
|
||||
|
||||
@@ -6,6 +6,7 @@ from utils.storage.nfs import (
|
||||
mount_opts,
|
||||
state_path,
|
||||
swarm_nfs_backed,
|
||||
volume_dir,
|
||||
)
|
||||
|
||||
|
||||
@@ -62,6 +63,15 @@ class TestNfsHelpers(unittest.TestCase):
|
||||
"1.2.3.4:/srv/nfs/infinito-state",
|
||||
)
|
||||
|
||||
def test_volume_dir_is_the_pinned_name(self):
|
||||
self.assertEqual(
|
||||
volume_dir("whiteboard_tmp", {"name": "nextcloud_whiteboard_tmp"}),
|
||||
"nextcloud_whiteboard_tmp",
|
||||
)
|
||||
|
||||
def test_volume_dir_falls_back_to_the_key_without_a_pin(self):
|
||||
self.assertEqual(volume_dir("docs_sites", {"backup": False}), "docs_sites")
|
||||
|
||||
|
||||
class TestSwarmNfsBacked(unittest.TestCase):
|
||||
"""The predicate mirrors the compose_volumes rewrite decision: swarm mode
|
||||
|
||||
Reference in new issue
Block a user