fix: restore Mailu SQLite database in place
cc-ci/testme cc-ci: success

This commit is contained in:
notplants
2026-11-02 18:19:56 +00:00
parent fb245e26cd
commit d59ce5ff3a
3 changed files with 31 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
"""Restore Mailu's SQLite snapshot without replacing the live database inode."""
import sqlite3
from pathlib import Path
backup_path = Path("/data/backup/main.db")
live_path = Path("/data/main.db")
# The source and destination must already exist. A missing snapshot or live
# database is a restore failure, not a reason to create an empty database.
with sqlite3.connect(
f"{backup_path.as_uri()}?mode=ro", uri=True, timeout=60
) as source:
if source.execute("PRAGMA integrity_check").fetchall() != [("ok",)]:
raise RuntimeError(f"Invalid SQLite snapshot: {backup_path}")
with sqlite3.connect(
f"{live_path.as_uri()}?mode=rw", uri=True, timeout=60
) as destination:
source.backup(destination, pages=256, sleep=0.1)
print(f"SQLite restore complete: {live_path}", flush=True)