plugin-barman-cloud icon indicating copy to clipboard operation
plugin-barman-cloud copied to clipboard

Catalog maintenance deletes completed Backup objects after a short barman-cloud-backup-list result

Open ebertlion opened this issue 2 months ago • 5 comments

Versions: plugin-barman-cloud v0.13.0, CloudNativePG 1.30.0, Kubernetes 1.35, S3-compatible object storage (STACKIT).

What happened

On 2026-09-18 the plugin sidecar on the primary of two unrelated clusters logged Deleting backup not in the catalog for the two newest completed Backup objects (the base backups of the 17th and the 18th) and removed them:

{"level":"info","ts":"2026-09-18T09:50:05Z","msg":"Applying backup retention policy","logging_pod":"portal-postgres-2","retentionPolicy":"30d"}
{"level":"info","ts":"2026-09-18T09:50:07Z","msg":"Deleting backup not in the catalog","logging_pod":"portal-postgres-2","backup":"portal-postgres-daily-backup-20260917011500"}
{"level":"info","ts":"2026-09-18T09:50:07Z","msg":"Deleting backup not in the catalog","logging_pod":"portal-postgres-2","backup":"portal-postgres-daily-backup-20260918011500"}

The operator then logged terminal error: Backup.postgresql.cnpg.io "portal-postgres-daily-backup-20260917011500" not found for both objects. The same happened on a second cluster in another namespace at 13:05 UTC.

The bucket itself was intact: ObjectStore.status.serverRecoveryWindow kept its firstRecoverabilityPoint (2026-08-25) and lastSuccessfulBackupTime, WAL archiving never failed, and the next night's scheduled backup completed normally. The kube-apiserver showed a short 5xx spike in the same minute (about 16 errors/s for two five-minute windows, otherwise ~0.02/s), so the listing most likely came back short or empty.

Cause, as far as I can see

internal/cnpgi/instance/retention.go deletes every completed Backup object of the cluster whose status.backupID is not in the current GetBackupList result. There is no guard for the listing itself: an empty or partial catalog (transient object-store or API error, eventual consistency) deletes valid objects. On this side the effect was a false no backup in 26h alert; on a cluster that relies on Backup objects for restore selection it would hide two valid base backups.

Suggestions

  • Skip the deletion pass when the listing is empty, or when it lists fewer backups than the Backup objects that are older than the newest catalog entry.
  • Only delete objects whose backup is older than the retention window, since that is the only case where the catalog is expected to have dropped them.
  • Or require an ID to be missing in two consecutive listings before the object is removed.

Happy to provide more logs or test a fix.

ebertlion avatar Sep 24 '26 16:09 ebertlion

Hi @ebertlion, I’d like to help fix this issue. Are you already working on it?

Lumbenlengo avatar Sep 27 '26 15:09 Lumbenlengo

We see the same thing on a different provider, with a slightly different trigger: a partial listing rather than an empty one.

Versions: plugin-barman-cloud v0.14.0, CloudNativePG 1.29.1, PostgreSQL 18.4, Hetzner Object Storage (hel1), retentionPolicy: 30d, one scheduled base backup per day.

What we observed (34 days of sidecar logs on the primary)

  • 25 × Deleting backup not in the catalog. 17 were expected (backups past the 30-day window, removed right after the nightly backup). 8 were for completed backups 4–26 days old, removed at arbitrary times of day, one object at a time.
  • All 8 backups are still complete in the bucket (backup.info + data.tar.gz). The bucket holds 31 daily backups; kubectl get backups.postgresql.cnpg.io shows 23.
  • In the same period the object store returned GatewayTimeout on GetObject for a single backup.info 41 times, visible through barman-cloud-backup-delete:
WARNING: Unable to open backup.info file for 20260925T020000: An error occurred (GatewayTimeout) when calling the GetObject operation (reached max retries: 4): The server did not respond in time.
ERROR: Cannot read the following backups: ['20260925T020000']
Unsafe to proceed with deletion due to failure reading backup catalog

Likely mechanism

barman-cloud-backup-delete treats an unreadable backup.info as fatal and exits non-zero (we get RetentionPolicyFailed). barman-cloud-backup-list appears to skip the unreadable backup with only a warning and exit 0, so GetBackupList returns a list that is one entry short and deleteBackupsNotInCatalog removes that Backup object. This part is inferred: the sidecar logs nothing from the list step on success, so we have no log line tying a timeout to each deletion — only the timing pattern and the intact bucket.

If that is right, an "empty listing" guard would not cover this case. Of the suggestions above, deleting only objects older than the retention window, or requiring an ID to be missing in two consecutive listings, would. Surfacing barman's unreadable-backups warning as an error from the list step would also do it.

Happy to share more logs.

bisand avatar Oct 08 '26 05:10 bisand

Confirming the inferred part of the previous comment, from the barman source inside the sidecar (plugin-barman-cloud v0.13.0, barman 3.19.1), on Hetzner Object Storage (fsn1):

  • CloudBackupCatalog.get_backup_list() catches any exception from get_backup_info(), logs Unable to open backup.info file for …, appends the ID to catalog.unreadable_backups and continues.
  • barman-cloud-backup-delete checks unreadable_backups and aborts ("Unsafe to proceed with deletion…").
  • barman-cloud-backup-list does not check it and exits 0 with a list that is short by the unreadable entries.

So a single transient GetObject failure on one backup.info is enough for deleteBackupsNotInCatalog to remove that Backup object.

Scale on our side: 13 clusters, daily scheduled backups, all affected. Over the last 20 days between 1 and 12 completed Backup objects per cluster were removed at arbitrary times. Two deletions happened in the same pass in one case. For every case we checked, the base backup is still in the bucket with status=DONE. The barman_cloud_* metrics (and alerts built on them) stay correct, because they come from the catalog, not from the Backup objects.

A guard that matches what barman-cloud-backup-delete already does would fix this: have the list step fail (or report the unreadable IDs) when unreadable_backups is non-empty, and skip deleteBackupsNotInCatalog for that pass.

lireking avatar Nov 13 '26 08:11 lireking

Just hit the same issue tonight, where a Backup CR was deleted shortly after its creation. Also on STACKIT

Here's what happened as reconstructed by Claude based on logs, metrics, and the CRs in the cluster. n8n-1 and n8n-2 are the postgres pods (primary and standby).

Time Component Description
2026-11-20 02:00:00 CNPG operator Creating backup n8n-20261120020000, Starting backup on pod n8n-2
2026-11-20 02:00:09 n8n-2 sidecar Completed barman-cloud-backup to s3://<redacted>/
2026-11-20 02:00:11 n8n-2 sidecar Backup completed, backup ID 20261120T020001
2026-11-20 02:03:10 n8n-1 sidecar Deleting backup not in the catalog: n8n-20261020020000 (31 days old, normal retention)
2026-11-20 02:03 to 02:33 n8n-1 sidecar Retention cycles every 5 minutes. Tonight's backup is kept.
2026-11-20 02:05 Prometheus last_available_backup_timestamp = 11-20 02:00:07, backup is in the catalog
2026-11-20 02:38:32 n8n-1 sidecar Applying backup retention policy (30d)
2026-11-20 02:38:35 n8n-1 sidecar Deleting backup not in the catalog: n8n-20261120020000
2026-11-20 02:38:35 CNPG operator Backup.postgresql.cnpg.io "n8n-20261120020000" not found
2026-11-20 02:40 Prometheus last_available_backup_timestamp = 11-19 02:00:08, backup missing from the catalog
2026-11-20 02:45 Prometheus last_available_backup_timestamp = 11-20 02:00:07, backup back in the catalog

The backup was never deleted from S3, it was only the Backup CR that was removed from the cluster as far as I can tell.

If it helps I can share more logs or info.

KevinGimbel avatar Nov 20 '26 10:11 KevinGimbel

Experiencing the same issue with Hetzner S3, "missing backup records (17 and 19 November)", LLM stated:

  • What deleted them: the audit log shows the Postgres pods' own service account deleting both records on 19 November at 13:55 Berlin. The backup plugin logged "Deleting backup not in the catalog".
  • Why: in the minutes before, uploads to Hetzner's object storage failed several times with BadRequest, and every one was retried successfully. The plugin's bucket listing at that moment most likely came back short, and the plugin deletes every record whose backup isn't in the listing.
  • Known bug: this is plugin-barman-cloud #1115, still open. Others report it on Hetzner and STACKIT.

bluepuma77 avatar Nov 21 '26 07:11 bluepuma77