Skip to content

[Bug]: Full recovery fails to restore from S3 backup #7344

Closed

Description

@fcarucci

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

[email protected]

Version

1.26.0-rc1

What version of Kubernetes are you using?

1.32

What is your Kubernetes environment?

Self-managed: k3s

How did you install the operator?

YAML manifest

What happened?

I'm trying to restore my production cluster to a staging cluster to make sure restoring works, but it fails with this log.

ERROR: WAL archive check failed for server postgresql-test: Expected empty archive

The same exact configuration was working fine this morning when I tried the first time.

`
bootstrap:
recovery:
source: postgresql

externalClusters:
- name: postgresql
barmanObjectStore:
destinationPath: "s3://backups/"
endpointURL: "https://s3.k.example.com"
s3Credentials:
accessKeyId:
name: s3-creds
key: ACCESS_KEY_ID
secretAccessKey:
name: s3-creds
key: ACCESS_SECRET_KEY
wal:
maxParallel: 8
`

This is how I'm backing up the production cluster.


  backup:
    barmanObjectStore:
      destinationPath: "s3://backups/"
      endpointURL: "https://s3"
      s3Credentials:
        accessKeyId:
          name: s3-creds
          key: ACCESS_KEY_ID
        secretAccessKey:
          name: s3-creds
          key: ACCESS_SECRET_KEY
      wal:
        compression: bzip2
      data:
        compression: bzip2
    retentionPolicy: "1d"

Thanks for your help.

Cluster resource

# kind: StorageClass
# apiVersion: storage.k8s.io/v1
# metadata:
#   name: longhorn-postgresql
#   annotations:
#     storageclass.kubernetes.io/is-default-class: "true"
# provisioner: driver.longhorn.io
# allowVolumeExpansion: true
# reclaimPolicy: "Delete"
# volumeBindingMode: Immediate
# parameters:
#   numberOfReplicas: "1"
#   staleReplicaTimeout: "30"
#   fromBackup: ""
#   fsType: "ext4"
#   dataLocality: "strict-local"
#   encrypted: "true"
#   csi.storage.k8s.io/node-stage-secret-name: longhorn
#   csi.storage.k8s.io/node-stage-secret-namespace: database

# ---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: postgresql-test
  namespace: database
spec:
  instances: 1
  monitoring:
    enablePodMonitor: true
  certificates:
    serverTLSSecret: postgres-test-server-cert
    serverCASecret: postgres-test-server-cert
  backup:
    barmanObjectStore:
      destinationPath: "s3://backups/"
      endpointURL: "https://s3"
      s3Credentials:
        accessKeyId:
          name: s3-creds
          key: ACCESS_KEY_ID
        secretAccessKey:
          name: s3-creds
          key: ACCESS_SECRET_KEY
      wal:
        compression: bzip2
      data:
        compression: bzip2
    retentionPolicy: "1d"
  env:
    - name: TZ
      value: America/Los_Angeles
  postgresql:
    parameters:
      shared_buffers: "128MB"
  resources:
    requests:
      memory: "128Mi"
      cpu: "25m"
    limits:
      memory: "512Mi"
      cpu: "250m"

  bootstrap:
    recovery:
      source: postgresql

  externalClusters:
    - name: postgresql
      barmanObjectStore:
        destinationPath: "s3://backups/"
        endpointURL: "https://s3"
        s3Credentials:
          accessKeyId:
            name: s3-creds
            key: ACCESS_KEY_ID
          secretAccessKey:
            name: s3-creds
            key: ACCESS_SECRET_KEY
        wal:
          maxParallel: 8

  affinity:
    enablePodAntiAffinity: true #default value
    topologyKey: kubernetes.io/hostname #default value
    #podAntiAffinityType: prefer #default value
    nodeSelector:
      node-role.kubernetes.io/worker: "true"
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: ryzen
                operator: In
                values:
                  - "true"

  primaryUpdateStrategy: unsupervised
  storage:
    # storageClass: "longhorn-postgresql"
    storageClass: "local-path"
    size: 10Gi
  managed:
    services:
      disabledDefaultServices: ["ro", "r"]
      additional:
        - selectorType: rw
          serviceTemplate:
            metadata:
              name: postgresql-test-lb
              annotations:
                metallb.universe.tf/address-pool: default-pool
            spec:
              type: LoadBalancer
              loadBalancerIP: 10.20.0.165

---
apiVersion: postgresql.cnpg.io/v1
kind: Pooler
metadata:
  name: postgresql-test-pooler
  namespace: database
spec:
  cluster:
    name: postgresql-test
  instances: 1
  type: rw
  template:
    spec:
      containers: []
      resources:
        requests:
          memory: "24Mi"
          cpu: "10m"
        limits:
          memory: "128Mi"
          cpu: "200m"
      nodeSelector:
        node-role.kubernetes.io/worker: "true"
  serviceTemplate:
    metadata:
      labels:
        app: pooler
      annotations:
        metallb.universe.tf/address-pool: default-pool
    spec:
      type: LoadBalancer
      loadBalancerIP: 10.20.0.166
  pgbouncer:
    poolMode: session
    parameters:
      max_client_conn: "1000"
      default_pool_size: "10"

Relevant log output

{"level":"info","ts":"2025-04-12T14:04:55.853933753-07:00","msg":"Starting webserver","logging_pod":"postgresql-test-1-full-recovery","address":"localhost:8010","hasTLS":false}
{"level":"info","ts":"2025-04-12T14:04:56.236982428-07:00","msg":"barman-cloud-check-wal-archive checking the first wal","logging_pod":"postgresql-test-1-full-recovery"}
{"level":"info","ts":"2025-04-12T14:04:57.476706901-07:00","logger":"barman-cloud-check-wal-archive","msg":"2025-04-12 14:04:57,476 [19] ERROR: WAL archive check failed for server postgresql-test: Expected empty archive","pipe":"stderr","logging_pod":"postgresql-test-1-full-recovery"}
{"level":"error","ts":"2025-04-12T14:04:57.551247827-07:00","msg":"Error invoking barman-cloud-check-wal-archive","logging_pod":"postgresql-test-1-full-recovery","options":["--endpoint-url","https://s3.k.carucci.studio","--cloud-provider","aws-s3","s3://backups/","postgresql-test"],"exitCode":-1,"error":"exit status 1","stacktrace":"github.com/cloudnative-pg/machinery/pkg/log.(*logger).Error\n\tpkg/mod/github.com/cloudnative-pg/[email protected]/pkg/log/log.go:125\ngithub.com/cloudnative-pg/barman-cloud/pkg/walarchive.(*BarmanArchiver).CheckWalArchiveDestination\n\tpkg/mod/github.com/cloudnative-pg/[email protected]/pkg/walarchive/cmd.go:178\ngithub.com/cloudnative-pg/barman-cloud/pkg/archiver.(*WALArchiver).CheckWalArchiveDestination\n\tpkg/mod/github.com/cloudnative-pg/[email protected]/pkg/archiver/archiver.go:131\ngithub.com/cloudnative-pg/cloudnative-pg/pkg/management/postgres.(*InitInfo).checkBackupDestination\n\tpkg/management/postgres/restore.go:1023\ngithub.com/cloudnative-pg/cloudnative-pg/pkg/management/postgres.InitInfo.Restore\n\tpkg/management/postgres/restore.go:282\ngithub.com/cloudnative-pg/cloudnative-pg/internal/cmd/manager/instance/restore.restoreSubCommand\n\tinternal/cmd/manager/instance/restore/restore.go:75\ngithub.com/cloudnative-pg/cloudnative-pg/internal/cmd/manager/instance/restore.(*restoreRunnable).Start\n\tinternal/cmd/manager/instance/restore/restore.go:59\nsigs.k8s.io/controller-runtime/pkg/manager.(*runnableGroup).reconcile.func1\n\tpkg/mod/sigs.k8s.io/[email protected]/pkg/manager/runnable_group.go:226"}
{"level":"error","ts":"2025-04-12T14:04:57.551423038-07:00","msg":"Error while restoring a backup","logging_pod":"postgresql-test-1-full-recovery","error":"unexpected failure invoking barman-cloud-wal-archive: exit status 1","stacktrace":"github.com/cloudnative-pg/machinery/pkg/log.(*logger).Error\n\tpkg/mod/github.com/cloudnative-pg/[email protected]/pkg/log/log.go:125\ngithub.com/cloudnative-pg/cloudnative-pg/internal/cmd/manager/instance/restore.restoreSubCommand\n\tinternal/cmd/manager/instance/restore/restore.go:76\ngithub.com/cloudnative-pg/cloudnative-pg/internal/cmd/manager/instance/restore.(*restoreRunnable).Start\n\tinternal/cmd/manager/instance/restore/restore.go:59\nsigs.k8s.io/controller-runtime/pkg/manager.(*runnableGroup).reconcile.func1\n\tpkg/mod/sigs.k8s.io/[email protected]/pkg/manager/runnable_group.go:226"}
{

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    triage
    on Apr 12, 2025
  2. dosubot commented on Apr 12, 2025

    @dosubot

    Hello @fcarucci! I'm Dosu, your friendly bot here to help you with any bugs, questions, or contributions you might have while we wait for a human maintainer. Let's tackle this together!

    The error "WAL archive check failed for server postgresql-test: Expected empty archive" occurs because the CloudNativePG operator includes a safety check to prevent overwriting a storage bucket that already contains information. This error suggests that the storage bucket is not empty, and the operator detects existing WAL archives, which it expects to be empty for a new recovery process.

    To resolve this issue, ensure that the storage bucket specified in the barmanObjectStore configuration is empty before starting the recovery process. Alternatively, if you are certain that overwriting the existing data is safe and you are familiar with the PostgreSQL recovery system, you can set the cnpg.io/skipEmptyWalArchiveCheck annotation to enabled in the recovered cluster to skip this safety check. However, skipping this check is not recommended as it can lead to severe data loss [1].

    To continue talking to Dosu, mention @dosu.


    Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

  3. added
    bug 🐛
    on Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions