fix(backup): skip prune when DB capture failed — preserve recovery source

Address #68805 review: when failed_dbs is non-empty, skip
_prune_quick_snapshots so the incomplete snapshot does not delete
the older snapshot containing the last good database. The updater's
keep=1 would otherwise evict the recovery source.
This commit is contained in:
Jasmine Naderi 2026-07-22 20:07:29 -04:00 committed by Teknium
parent ed5e41ddd6
commit fc99b549ee
1 changed files with 12 additions and 1 deletions

View File

@ -1177,7 +1177,18 @@ def create_quick_snapshot(
# Auto-prune. Defaults preserve historical manual /snapshot behavior; callers
# with known high-churn safety snapshots (for example pre-update) can pass a
# smaller keep value so large state.db copies do not accumulate indefinitely.
_prune_quick_snapshots(root, keep=_QUICK_DEFAULT_KEEP if keep is None else keep)
# #68805 review: skip pruning when a present DB failed to capture — the
# incomplete snapshot must not delete the older snapshot that may contain
# the last good database (the recovery source this hardening is meant to
# preserve).
if not failed_dbs:
_prune_quick_snapshots(root, keep=_QUICK_DEFAULT_KEEP if keep is None else keep)
else:
logger.warning(
"Skipping snapshot prune because %d DB(s) failed to capture — "
"preserving older snapshots as recovery source",
len(failed_dbs),
)
logger.info("State snapshot created: %s (%d files)", snap_id, len(manifest))
return snap_id