PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
1. Label-filtered removal routine
- 1.1 Replace the engine's
ListManaged(ctx, agentID)with a container listing that takes a label set, add a network listing with the same signature, and pass every label as a separatelabelfilter value. Both return only the resource ID and its verification ID, so cutManagedContainerdown to those fields and delete the network lookup. Until task 1.2 replaces it, the old purge compiles against the new container listing and skips its network step. Verify withjust buildinagent/verification. - 1.2 In one step, replace the container-driven startup purge with one routine and the test fake with a fake Docker host, then rewrite the existing purge tests against it. The routine lists containers by labels and removes them, then lists networks by labels and removes them, so a failure in one half does not skip the other. It treats a removal error that
IsNotFoundfromgithub.com/containerd/errdefsrecognizes as success and accepts the narrow engine interface. Makegithub.com/containerd/errdefsa direct dependency inagent/verification/go.mod. The fake host infake_engine_test.gostores containers and networks with their labels and applies a label filter with AND semantics. It also implementsCreateNetworkand records listing filters, removals and network creations in one ordered log, and it can be told to fail a listing, fail a removal or returnerrdefs.ErrNotFoundfor a removal. The fake's setup methods stay beside it infake_engine_test.go, because atesting.gofile is compiled without the test files and cannot see the fake. The label builders the tests share are the production helpersSpawnand the purge use, and the log-capturing helper joinsDiscardLoggerin the module's sharedinternal/testutil, so the package gets notesting.go. Rewrite the comments that tie the labels to the startup purge alone: the purge comment that says a leftover never collides with a fresh run,dockerengine.go:26-27andmanager.go:146-148. Verify by rewriting the existing tests ininternal/features/container/purge_test.goagainst the fake host and runningjust testinagent/verification.
2. Startup purge tests
Each test lives in internal/features/container/purge_test.go and is verified with just test in agent/verification.
- 2.1
Test_PurgeAgentContainers_WhenNetworkHasNoContainer_RemovesNetworkpins that a network labeled with the agent's ID and no attached container is removed. - 2.2
Test_PurgeAgentContainers_WhenContainerAndNetworkExist_RemovesContainerBeforeNetworkpins the removal order. - 2.3
Test_PurgeAgentContainers_WhenResourcesBelongToOtherAgentOrNoAgent_LeavesThemInPlacepins that a network and a container labeled with another agent ID, and a network with no agent labels, remain on the fake host. - 2.4
Test_PurgeAgentContainers_FiltersByAgentLabelOnlypins that both listings request exactly the agent label filter. - 2.5
Test_PurgeAgentContainers_WhenNetworkListFails_LogsAndRemovesContainerspins that a failed network listing does not stop the purge and does not return an error. - 2.6
Test_PurgeAgentContainers_WhenRemovalReturnsNotFound_ContinuesWithRemainingResourcespins that a not-found removal is treated as removed and the purge goes on. - 2.7
Test_PurgeAgentContainers_WhenContainerListFails_LogsAndRemovesNetworkspins that a failed container listing still lets the purge remove the agent's networks.
3. Cleanup before an attempt
- 3.1 Move the step of
Spawnthat clears leftovers and creates the network into a function that takes the narrow engine interface plusCreateNetwork, runs the removal routine with the agent and verification labels, and returns an error saying the leftovers of an earlier attempt could not be removed when the routine fails. MakeSpawncall it. Verify withjust buildinagent/verification.
4. Cleanup-before-attempt tests
Each test lives in a new internal/features/container/leftovers_test.go, or beside the function from 3.1 if it lands in another file, and is verified with just test in agent/verification.
- 4.1
Test_PrepareAttemptNetwork_WhenPreviousAttemptLeftNetwork_RemovesItAndCreatesNetworkpins the first scenario of the retry requirement. A comment on the test names issue #832, which the project rules allow for a test that pins an issue's behavior. - 4.2
Test_PrepareAttemptNetwork_WhenPreviousAttemptLeftContainerAndNetwork_RemovesContainerThenNetworkThenCreatespins the order across removal and creation. - 4.3
Test_PrepareAttemptNetwork_WhenLeftoverAlreadyRemoved_CreatesNetworkpins that a removal returningerrdefs.ErrNotFoundlets the attempt proceed. - 4.4
Test_PrepareAttemptNetwork_WhenNoLeftovers_CreatesNetworkWithoutRemovalspins the first-attempt scenario. - 4.5
Test_PrepareAttemptNetwork_WhenLeftoverRemovalFails_ReturnsLeftoverErrorAndCreatesNoNetworkpins the error message and thatCreateNetworkis never called. - 4.6
Test_PrepareAttemptNetwork_WhenListingFails_ReturnsLeftoverErrorAndCreatesNoNetworkpins the same behavior for a failed listing. - 4.7
Test_PrepareAttemptNetwork_WhenOtherVerificationRuns_LeavesItsResourcesInPlacepins that the container and network of another verification of the same agent remain on the fake host. - 4.8
Test_PrepareAttemptNetwork_WhenOtherAgentHasSameVerification_LeavesItsResourcesInPlacepins that resources with the same verification label but another agent ID remain on the fake host. - 4.9
Test_PrepareAttemptNetwork_FiltersByAgentAndVerificationLabelspins that both listings request exactly the agent label and the verification label.
5. End-to-end checks on real Docker
- 5.1 Add
agent/verification/e2e/scripts/test-restore-retry-leftover.sh, modeled ontest-restore-success.sh. After the agent has started and its startup purge has finished, and before the claim, it creates a network nameddatabasus-verif-<id>labeled with the agent ID and that verification ID, so the startup purge cannot remove it first. It asserts withdocker network ls --filter name=databasus-verif-<id>that the network exists right before it assigns the same verification ID throughPOST /mock/set-claim, then asserts a successful report and runsleak_check. A comment names issue #832. Register the script ine2e/scripts/run-all.sh. Verify withjust e2einagent/verification. - 5.2 Extend
agent/verification/e2e/scripts/test-startup-purge.shto also seed a network labeled with the agent ID and no container, and a network labeled with another agent ID. Assert that the first is gone after the agent starts and the second remains, then remove the second in the script's cleanup. Verify withjust e2einagent/verification.
6. Module checks
- 6.1 Run
just lintinagent/verificationand fix every finding.
Change verification
just --justfile agent/verification/Justfile test