PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
Paths are relative to backend/internal/features/backups/backups/. Test commands run from backend/.
1. Bounded WAL span lookup
- 1.1 In
core/physical/repositories/wal_segment_repository.go, move the span condition ofFindByChainSpaninto a private helper that adds the lower bound from design Decision 4:start_lsnat or above the greateststart_lsnat or below the span start, falling back to'0/0'. Keep theend_lsnfilter and thestart_lsn ASCorder. Verify withgo test ./internal/features/backups/backups/core/physical/... -count=1; the existing boundary-segment tests inchain_view/restore_set_test.goandbackuping/physical/cleaner_test.gomust keep passing. - 1.2 Add
GetLatestReceivedAtInChainSpan(databaseID, timelineID, startLSN, endLSN) (*time.Time, error)besideFindByChainSpan, returningMAX(received_at)under the same helper and nil when the span holds no segment. Verify withgo build ./.... - 1.3 In
core/physical/chain_view/service_test.go, addTest_FindByChainSpan_ForMiddleChain_ReturnsOnlyItsSegmentsIncludingBoundary: three chains on one timeline, the middle full backup starting partway into a segment; the lookup for the middle span returns that boundary segment and the middle chain's later segments, and no segment of the first or third chain. Verify withgo test ./internal/features/backups/backups/core/physical/chain_view/... -run Test_FindByChainSpan -count=1. - 1.4 Add
Test_FindByChainSpan_WhenSpanStartsOnSegmentBoundary_ExcludesSegmentEndingThereto the same file: the span starts exactly where one segment ends and the next begins; the lookup returns the segment starting at the span start and not the one ending there. Verify with the same command as 1.3. - 1.5 Add
Test_FindByChainSpan_WhenOtherTimelineAndDatabaseHaveSegmentsInRange_IgnoresThemto the same file: segments of a second timeline and of a second database sit at LSNs inside and just below the span start; the lookup returns only the requested database's segments on the requested timeline, with the same boundary segment as without them. Verify with the same command as 1.3.
2. Chain model without WAL
- 2.1 Remove
WalSegments,GapsandMaxReplayableLSNfromChainViewincore/physical/chain_view/view.go, shrink its doc diagram to the span, and stopbuildChainViewfrom loading WAL or callingFindWalGapsInChain. DeleteFindWalSegmentsInSpan. Updateservice_test.go: drop theWalSegmentsandGapsassertions from the healthy-chain test, deleteTest_FindLastExtendableChainByDatabase_WhenChainHasGap_MaxReplayableLSNStopsAtFirstGap, and make the two span tests read through the repository. Verify withgo build ./...andgo test ./internal/features/backups/backups/core/physical/chain_view/... -count=1. - 2.2 Rewrite
FindLastExtendableChainByDatabaseandFindNonExtendableChainsByDatabaseon one read of the completed full backups, per design Decision 2: only the newest can be extendable, and only when none of its incremental backups isCHAIN_BROKEN. Move the body ofGetChainSpaninto a privategetChainSpanForFull(full)thatGetChainSpanwraps andbuildChainViewcalls with the full backup it holds. DeletegetChainState,findNewerCompletedFullsand theChainStateenum, and move the rule that WAL gaps never change chain state into a comment on the extendability check. Verify withgo test ./internal/features/backups/backups/core/physical/chain_view/... -count=1; the existing extendable, broken and newer-full tests must pass unchanged. - 2.3 Add
Test_FindNonExtendableChainsByDatabase_WhenNewestChainBroken_ListsItWithOlderChainstoservice_test.go: with two completed full backups and aCHAIN_BROKENincremental on the newer one, the extendable lookup returns nil and the closed list holds both chains, newest first. Verify withgo test ./internal/features/backups/backups/core/physical/chain_view/... -run Test_FindNonExtendableChainsByDatabase -count=1.
3. Chain end time from the built chain
- 3.1 Change
GetChainEndTimestampto take a*ChainViewand compute the latest of the root full backup's completion, the incremental backups' completion andGetLatestReceivedAtInChainSpanover the view's span, per design Decision 3. UpdateTest_GetChainEndTimestamp_WhenWalReceivedAfterIncr_ReturnsWalReceivedAtto build the view first, and addTest_GetChainEndTimestamp_WhenChainHasNoWal_ReturnsLatestBackupCompletion. Verify withgo test ./internal/features/backups/backups/core/physical/chain_view/... -run Test_GetChainEndTimestamp -count=1. - 3.2 In
backuping/physical/cleaner.go, pass each view toGetChainEndTimestampinnonExtendableChainsNewestEndFirst, and changeisChainWithinGraceto take the candidate's end time instead of a full backup ID, so each chain's end time is computed once per pass. Verify withgo test ./internal/features/backups/backups/backuping/physical/... -run "Test_Clean" -count=1; the grace and keep-count tests must pass unchanged.
4. Background cadence
- 4.1 In
decideBackupKindinbackuping/physical/scheduler.go, move theIncrementalBackupInterval.ShouldTriggerBackupcheck above theFindLastExtendableChainByDatabasecall, per design Decision 5. Verify withgo test ./internal/features/backups/backups/backuping/physical/... -run Test_DecideBackupKind -count=1. - 4.2 In
backuping/physical/constants.go, setcleanerTickIntervalto one minute and rewrite its comment with the reason from design Decision 6. Verify withgo test ./internal/features/backups/backups/backuping/physical/... -count=1.
5. Verification
- 5.1 Confirm that no reference to the removed names is left:
grep -rnE "FindWalSegmentsInSpan|ChainState|getChainState|findNewerCompletedFulls|\bview\.(WalSegments|Gaps|MaxReplayableLSN)" backend/returns nothing. - 5.2 Run
just lintinbackend/and fix every finding in the touched files. - 5.3 Run the touched packages and confirm that they pass:
go test ./internal/features/backups/backups/core/physical/... ./internal/features/backups/backups/backuping/physical/... ./internal/features/backups/backups/services/... -count=1. - 5.4 Run the physical backup and restore cycle packages, which prove end to end that restore still ships the right WAL through the bounded lookup:
go test ./internal/features/tests/physical/postgresql/pg17/... ./internal/features/tests/physical/postgresql/pg18/... -count=1 -timeout 60m. - 5.5 Run
openspec validate reduce-physical-idle-load --strictand confirm that it passes.