audit 3: a restore is ended by its Resync, and half an archive is refused
test / test (push) Canceled after 0s
test / test (push) Canceled after 0s
The restore manifest was consumed as soon as its version was checked, before store.Open and the Resync; a start that failed in between left a data directory the next start took for an ordinary one (M1). openData now runs CheckRestore, store.Open, the Resync, and only then ConsumeRestore. A truncated archive had nothing to refuse it: the manifest is the first entry, so a download cut short or a tar stopped by a damaged block was a restore on half a database. Every archive now ends with data/contents.json, the size and SHA-256 of each data/ file (deploy files are the operator's to edit), and CheckRestore compares /data with it before the database is opened, then renames it contents.checked.json so a start after a failed one does not compare again unless the manifest changed. Tests: a start whose Resync fails, then a start that resyncs and consumes; an archive cut in the database, before the deploy files and in its last entry (refused, database untouched, no -wal); a damaged key named; the record's names confined to data/; the domain import of a cut plain export, a cut and an altered .spde (refused, nothing created). e2e on the test server: full_backup_restore now also sees contents.json in the archive and gone after the first start, through the real entrypoint and daemons (all pass, 762 s); go vet + go test of 24 packages pass there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -70,7 +70,7 @@ func testFullBackupRestore(t *testing.T, sc *scenario) {
|
||||
if err != nil {
|
||||
t.Fatalf("unpack the backup into the empty project directory: %v", err)
|
||||
}
|
||||
for _, want := range []string{"docker-compose.yml", ".env", "data/manifest.json", "data/selfpost.db", "certs/fullchain.pem", "certs/privkey.pem"} {
|
||||
for _, want := range []string{"docker-compose.yml", ".env", "data/manifest.json", "data/selfpost.db", "data/contents.json", "certs/fullchain.pem", "certs/privkey.pem"} {
|
||||
if !names[want] {
|
||||
t.Fatalf("the backup has no %s (it has %d entries)", want, len(names))
|
||||
}
|
||||
@@ -93,12 +93,15 @@ func testFullBackupRestore(t *testing.T, sc *scenario) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The manifest guards the first start only and is removed by it.
|
||||
// The manifest guards the first start only and is removed by it, with the
|
||||
// record of the archive's files that start compared /data with - after
|
||||
// the entrypoint had set owners and modes and the daemons had started,
|
||||
// which is what this run shows the comparison survives.
|
||||
if err := waitFor("manifest.json to be removed by the first start", 30*time.Second, 500*time.Millisecond, func() (bool, error) {
|
||||
out, _ := h.execIn("selfpost", "sh", "-c", "test -e /data/manifest.json && echo present || echo gone")
|
||||
return strings.TrimSpace(out) == "gone", fmt.Errorf("manifest.json is %s", strings.TrimSpace(out))
|
||||
out, _ := h.execIn("selfpost", "sh", "-c", "ls /data/manifest.json /data/contents.json /data/contents.checked.json 2>/dev/null; true")
|
||||
return strings.TrimSpace(out) == "", fmt.Errorf("still there: %s", strings.TrimSpace(out))
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fatalf("%v\n%s", err, logTail(h.logs("selfpost"), "backup"))
|
||||
}
|
||||
|
||||
p, err := newPanelClient()
|
||||
|
||||
Reference in New Issue
Block a user