feat(backup): check a backup against what is in place, changing nothing (#5823)
#5823 "Check a backup: compare what it would restore with what is in place, without restoring". - steward/backup/check.py: pg_restore writes the backup's rows as COPY text with no database involved. The rows in place go out through COPY in the same form. Tables are compared on their primary keys, over the columns both sides have, and grouped by area. - Sealed values are opened with each side's own key and compared as plaintext digests, so a secret sealed twice still matches. They are never shown. A backup whose key can't open its own secrets fails the check. - What Steward records as it runs (last-seen times, a schedule's last run, backup history, scraped UniFi fields) is left out of the comparison: contents.ACTIVITY, STATE_SETTINGS and HAND_SET_ONLY. - Settings → Backups: - a Check button on each sent backup, which fetches it from the bucket (new s3.get_file); - "Check a file" to upload one, with the size limit raised before the CSRF check reads the form; - a results page. - Each backup Steward sends checks itself once written, and its history row says how that went. - New CLI command `steward check-backup FILE`. CI's image smoke step checks a real backup against its source and expects a match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -110,3 +110,27 @@ def test_list_reads_contents():
|
||||
s3.StoredObject("steward-20261011T000000Z.tar", 1200, "2026-10-11T00:00:01.000Z"),
|
||||
s3.StoredObject("steward-20261012T000000Z.tar", 1300, "2026-10-12T00:00:01.000Z"),
|
||||
]
|
||||
|
||||
|
||||
def test_get_streams_the_object_to_a_file(tmp_path):
|
||||
seen = {}
|
||||
|
||||
def handler(request):
|
||||
seen["method"], seen["url"] = request.method, str(request.url)
|
||||
seen["auth"] = request.headers["authorization"]
|
||||
return httpx.Response(200, content=b"y" * 3000)
|
||||
|
||||
out = tmp_path / "b.tar"
|
||||
size = asyncio.run(s3.get_file(TARGET, "b.tar", out, transport=httpx.MockTransport(handler)))
|
||||
assert (seen["method"], seen["url"]) == ("GET", "http://archives:8081/s3/steward/b.tar")
|
||||
assert seen["auth"].startswith("AWS4-HMAC-SHA256 ")
|
||||
assert size == 3000 and out.read_bytes() == b"y" * 3000
|
||||
|
||||
|
||||
def test_a_refused_get_leaves_no_file(tmp_path):
|
||||
body = b"<Error><Code>AccessDenied</Code><Message>no</Message></Error>"
|
||||
out = tmp_path / "b.tar"
|
||||
with pytest.raises(s3.S3Error, match="Reading b.tar refused: HTTP 403 AccessDenied"):
|
||||
asyncio.run(s3.get_file(TARGET, "b.tar", out,
|
||||
transport=httpx.MockTransport(lambda r: httpx.Response(403, content=body))))
|
||||
assert not out.exists()
|
||||
|
||||
Reference in New Issue
Block a user