Add database backups and automatic restore

Daemon job "backup" (online copy, quick_check, rotation), restore of the
newest valid copy when the database cannot be opened, change journal reset
after restore, last_restore in /health, docs and tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5 committed 2026-09-21 08:55:42 +03:00
1 parent c99665542a
commit 02f7b49e12
10 files changed
+294 -21

No files matched your search

+7 -1
View File
@@ -52,7 +52,7 @@ class CollectRequest(BaseModel):
class ScheduleUpdate(BaseModel):
type: Literal["asn", "fqdn"]
type: Literal["asn", "fqdn", "backup"]
cron: str
model_config = {"json_schema_extra": {"example": {"type": "asn", "cron": "*/10 * * * *"}}}
@@ -211,6 +211,11 @@ def health():
with db.session() as conn:
counts = {"cidrs": db.count_values(conn, "asn"), "fqdn_ips": db.count_values(conn, "fqdn")}
try:
last_restore = load_json(cc.RESTORE_FILE, None) # след автовосстановления базы из копии
except StorageError:
last_restore = None
healthy = alive and not any(j.get("last_error") for j in jobs.values())
return {
"status": "ok" if healthy else "degraded",
@@ -218,6 +223,7 @@ def health():
"collector_updated_at": updated_at,
"jobs": jobs,
"counts": counts,
"last_restore": last_restore,
}