PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
1. Proxy from the environment
- 1.1 Add
Proxy: http.ProxyFromEnvironmentto the S3 transport ingetClientParamsand add a test instorages/models/s3/model_test.goasserting that the returned transport'sProxyishttp.ProxyFromEnvironment(compared throughreflect.ValueOf(...).Pointer()) and thatTLSClientConfig.InsecureSkipVerifystill followsSkipTLSVerify; verify the test fails before the change and passes after it withjust test-package ./internal/features/storages/models/s3/...inbackend/ - 1.2 Do the same for Azure Blob in
buildClientOptions, reaching the transport through the*http.Clientin the returned options, and verify withjust test-package ./internal/features/storages/models/azure_blob/... - 1.3 Do the same for Google Drive in
buildHTTPClient, reaching the transport through theoauth2.Transportbase, and verify withjust test-package ./internal/features/storages/models/google_drive/... - 1.4 Do the same for the Mattermost transport built when TLS verification is off in
newHTTPClient, assert thatInsecureSkipVerifyandMinVersionare unchanged, and verify withjust test-package ./internal/features/notifiers/models/mattermost/... - 1.5 Add a test helper to
backend/internal/util/testingthat starts a localCONNECTproxy recording every request it receives and anhttptestTLS server recording the requests that reach it, and verify it with its own test that a plainhttp.Transport{Proxy: http.ProxyURL(...)}withInsecureSkipVerifyreaches the server through oneCONNECT, usingjust test-package ./internal/util/testing/... - 1.6 For each of the four builders from tasks 1.1-1.4, add a test that replaces only the built transport's
Proxywithhttp.ProxyURLto the helper's proxy and asserts: the proxy receives exactly oneCONNECTnaming the server's host and port and no request line, headers or credentials; with TLS verification on the request fails with a certificate error; for S3 and Mattermost with TLS verification off the request reaches the server with itsAuthorizationheader; verify with the package commands from tasks 1.1-1.4 - 1.7 Verify with
git grep -n "&http.Transport{" -- backend/internalthat every remaining transport literal either setsProxyor is outside the scope listed in proposal.md, and that the existing Telegram testTest_BuildHTTPClient_WhenProxyEnabled_UsesConfiguredProxystill passes withjust test-package ./internal/features/notifiers/models/telegram/...
2. Shared backup context and interruption classification
- 2.1 Add
errors.gotobackups_core_logicalwithErrBackupShutdown(backup interrupted by application shutdown) andErrBackupTimeout(backup exceeded the time limit of 23 hours, the hours taken from the time limit constant), and verify the package builds withgo build ./internal/features/backups/backups/core/logical/...inbackend/ - 2.2 Move the backup time limit, the shutdown check interval and the context setup from the engines into
backups_core_logicalasNewBackupContext(callerCtx), matching today's PostgreSQLcreateBackupContext, and verify withgo build ./internal/features/backups/backups/core/logical/... - 2.3 Add
DescribeBackupInterruption(callerCtx, backupCtx)with the order from design.md decision 3: shutdown cause, time limit cause, caller cancelled, otherwisesave to storage: %wwith the cause; verify withgo build ./internal/features/backups/backups/core/logical/...and with the table test in task 2.5 - 2.4 Add a helper to
backend/internal/util/testingthat returns a real network timeout error, produced by anhttp.Clientwith a shortResponseHeaderTimeoutagainst anhttptestserver that never answers, and verify with its own test that the error matchescontext.DeadlineExceeded, usingjust test-package ./internal/util/testing/... - 2.5 Add a table test for
DescribeBackupInterruptioncovering shutdown, time limit, caller cancelled, a storage timeout from the helper in task 2.4, a storage error wrappingcontext.Canceled, and a caller cancelled while the cause is a storage error; assert the storage cases wrap the storage error and are notbackup cancelled, and verify withjust test-package ./internal/features/backups/backups/core/logical/...
3. Engines use the shared code
- 3.1 In the PostgreSQL use case, replace
createBackupContext,checkCancellation,classifyCancellation, the two sentinels and the moved constants with the shared code, passing the caller's context toDescribeBackupInterruption; delete the private copies and verify withgo build ./...inbackend/ - 3.2 Do the same in the MySQL use case and verify with
go build ./... - 3.3 Do the same in the MariaDB use case and verify with
go build ./... - 3.4 Do the same in the MongoDB use case and verify with
go build ./... - 3.5 Verify with
git grep -n "classifyCancellation\|createBackupContext\|errBackupShutdown\|errBackupTimeout" -- backend/internal/features/backups/backups/usecases/logicalthat no private copy is left
4. Backuper decides cancellation from its own context
- 4.1 Write backuper tests through
MakeBackupwith use case doubles inbackuping/logical/backuper_test.go, none of which cancels through the registry: a storage timeout error ends as failed, with the storage error in the fail message, the database marked as failing and the failure notification sent; an error wrappingcontext.Canceledends as failed with a failure notification;ErrBackupTimeoutends as failed with the fail messagebackup exceeded the time limit of 23 hours, the database marked as failing and a failure notification;ErrBackupShutdownends as failed, not cancelled, with the fail messagebackup interrupted by application shutdown; name the storage-timeout test after issue #816; verify the storage-timeout,context.Canceledand time-limit tests fail against the current backuper - 4.2 Rewrite
Test_MakeBackup_WhenCancelledAfterStoringArtifact_ArtifactRemovedso its use case stores the artifact, signals the test, and blocks until its context ends, while the test cancels the backup through the cancellation registry; assert the backup is cancelled, no failure notification is sent, the database is not marked as failing and the artifact is removed - 4.3 Add a registry-cancel variant whose use case, after its context ends, returns a storage timeout error instead of a cancellation error; assert the backup is cancelled, no failure notification is sent and the database is not marked as failing
- 4.4 In
backuper.go, record the backup as cancelled exactly whenexecutionCtx.Err() != nilafter the use case returns, delete thestrings.Containsanderrors.Is(err, context.Canceled)checks with theisShutdownflag, and verify all backuper and scheduler tests pass withjust test-package ./internal/features/backups/backups/backuping/logical/..., includingTest_FailBackupsInProgress_WhenSchedulerStarts_CancelsBackupsAndUpdatesStatus, which covers the restart scenario's status and fail message
5. Engine regression tests with a real dump
- 5.1 Add a
BackupFileStoretest double to the logical backup test helpers with two modes: read the whole stream and then fail with a real timeout error, or fail before reading anything; take the timeout error from the helper in task 2.4 - 5.2 Add a PostgreSQL test to
usecases/logical/postgresql/create_backup_uc_test.gothat runs the real use case against the always-on logical fixture (databases.GetTestPostgresConfig) with both modes of the double, and asserts each error wraps the storage error and is notbackup cancelled; verify the "after the dump finished" case fails when task 3.1 is reverted locally, then passes withjust test-package ./internal/features/backups/backups/usecases/logical/postgresql/... - 5.3 Add the same test for MySQL in
usecases/logical/mysql/create_backup_uc_test.go, starting one container withcontainers.StartMysql, and verify withjust test-package ./internal/features/backups/backups/usecases/logical/mysql/... - 5.4 Add the same test for MariaDB with
containers.StartMariadband verify withjust test-package ./internal/features/backups/backups/usecases/logical/mariadb/... - 5.5 Add the same test for MongoDB in a new
usecases/logical/mongodb/create_backup_uc_test.gowithcontainers.StartMongodband verify withjust test-package ./internal/features/backups/backups/usecases/logical/mongodb/...
6. Verification
- 6.1 Run the logical backup packages and the end-to-end hang regressions with
just test-package ./internal/features/backups/... ./internal/features/tests/logical/...inbackend/, and confirm the issue #582 hang tests still see backups to a missing bucket end as failed - 6.2 Run the storage and notifier packages with
just test-package ./internal/features/storages/... ./internal/features/notifiers/...inbackend/ - 6.3 Run
just lintandjust formatinbackend/ - 6.4 Run
openspec validate fix-storage-proxy-and-backup-failure-status --strict