Skip to content

fix(restore): clean target directories after failed recovery - #11482

Open
opplion wants to merge 1 commit into
cloudnative-pg:mainfrom
opplion:fix/restore-cleanup-after-failure
Open

opplion wants to merge 1 commit into
cloudnative-pg:mainfrom
opplion:fix/restore-cleanup-after-failure

Conversation

@opplion

@opplion opplion commented Sep 15, 2026

Copy link
Copy Markdown

Summary

Backup recovery can fail after the base backup has been extracted, for example when PostgreSQL detects a WAL gap. These errors are not CloudRestoreError values, so the existing cleanup is skipped. On Kubernetes Job retries, the leftover PGDATA is preserved and another base backup is extracted, eventually filling the PVC.

  • clean the current PGDATA after every Restore failure
  • clean a separate PGWAL target when configured
  • keep pre-existing renamed data untouched by deleting only the exact current target paths
  • cover data/WAL cleanup and preservation of renamed data

Fixes cloudnative-pg/plugin-barman-cloud#1100

Testing

  • go test ./internal/cmd/manager/instance/restore
  • go test ./internal/cmd/manager/instance/...
  • go test ./pkg/management/postgres
  • go vet ./internal/cmd/manager/instance/restore

Clean PGDATA and a separate PGWAL directory whenever backup recovery fails, including PostgreSQL WAL replay failures that are not represented by CloudRestoreError. This prevents failed Job attempts from accumulating restored data on the PVC.

Signed-off-by: opplion <[email protected]>
@opplion
opplion requested a review from a team as a code owner September 15, 2026 10:57
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-barman-cloud does not clean PGDATA before re-extracting the base backup on Job retry, causing disk accumulation across failed attempts

2 participants