EnterpriseOn-premisesBackup and restore

Performing a backup

Configure automated PostgreSQL backups for IBM Bob databases and verify that backup jobs are running correctly.

Use this procedure to configure automated PostgreSQL backups for IBM Bob databases. After backups are configured, the operator automatically creates and manages scheduled backup jobs.

Before you begin

Before configuring backups, verify the following prerequisites:

  • A supported storage class is available in the cluster.
  • Database credential secrets exist.
  • Sufficient storage capacity is allocated.
  • PostgreSQL clusters are running and healthy.

Configure and enable backups

Create a backup ConfigMap that defines the backup schedule, retention policy, storage configuration, and target database clusters.

The operator automatically discovers any ConfigMap labeled with:

bob.ibm.com/backup-config: "true"

Create the configuration file:

apiVersion: v1
kind: ConfigMap
metadata:
  name: bob-postgres-backup-config
  namespace: <bob-instance-namespace>
  labels:
    bob.ibm.com/backup-config: "true"  # Required
    app.kubernetes.io/name: bob
    app.kubernetes.io/component: postgres-backup
data:
  config.yaml: |
    # Backup schedule in cron format (UTC timezone)
    schedule: "0 2 * * *"

    # Storage class for backup PVCs
    backupStorageClass: "nfs-storage"

    # Number of backups to retain per cluster (default: 7)
    retention: 7

    # Size of backup PVC per cluster (default: 10Gi)
    pvcSize: "10Gi"

    # Optional: PostgreSQL image override
    # If not specified, image is auto-detected from running clusters
    # postgresImage: "icr.io/cpopen/ibm-postgresql:16.4"

    # Clusters to back up
    # If omitted, defaults to bob-db and bob-keycloak-db
    clusters:
      - name: bob-db
        database: bob
        secretName: bob-db-app
      - name: bob-keycloak-db
        database: app  # Note: Keycloak database is named "app"
        secretName: bob-keycloak-db-app

Apply the ConfigMap:

oc apply -f backup-config.yaml

Enable backup management in the Bob custom resource:

apiVersion: bob.ibm.com/v1beta1
kind: Bob
metadata:
  name: bob-instance
  namespace: <bob-instance-namespace>
spec:
  postgresBackup:
    enabled: true
    suspend: false

This setting instructs the operator to create and manage backup resources automatically.

Apply the updated custom resource:

oc apply -f bob-cr.yaml

Verify that the operator successfully created the scheduled backup infrastructure.

Check CronJobs:

oc get cronjobs -n <bob-instance-namespace> -l app.kubernetes.io/component=postgres-backup

Expected output:

NAME                              SCHEDULE    SUSPEND   ACTIVE   LAST SCHEDULE   AGE
bob-db-backup-cronjob             0 2 * * *   False     0        <none>          1m
bob-keycloak-db-backup-cronjob    0 2 * * *   False     0        <none>          1m

Check PVCs:

oc get pvc -n <bob-instance-namespace> -l app.kubernetes.io/component=postgres-backup

Check the backup script ConfigMap:

oc get configmap postgres-backup-script -n <bob-instance-namespace>

Check Bob CR events:

oc describe bob bob-instance -n <bob-instance-namespace>

IBM recommends running a manual backup after initial configuration. A test backup validates connectivity, permissions, storage configuration, and backup execution before relying on scheduled backups.

Create a one-time backup job from the generated CronJob:

# Manually create a job from the CronJob
oc create job --from=cronjob/bob-db-backup-cronjob manual-backup-$(date +%s) -n <bob-instance-namespace>

# Monitor the job
oc get jobs -n <bob-instance-namespace> -l app.kubernetes.io/component=postgres-backup

# View job logs
oc logs -n <bob-instance-namespace> job/manual-backup-<timestamp>

After the backup finishes, validate that the backup files were created successfully.

Verify the following:

  • The job completed successfully.
  • The backup file exists.
  • The metadata file exists.
  • The backup size appears reasonable.
  • No errors appear in the job logs.
# Check job status
oc get jobs -n <bob-instance-namespace> -l app.kubernetes.io/component=postgres-backup

# View backup logs
oc logs -n <bob-instance-namespace> -l app.kubernetes.io/component=postgres-backup --tail=50

# Access backup files
oc run backup-check -n <bob-instance-namespace> --image=busybox --rm -it --restart=Never \
  --overrides='{
    "spec": {
      "containers": [{
        "name": "backup-check",
        "image": "busybox",
        "command": ["sh"],
        "stdin": true,
        "tty": true,
        "volumeMounts": [{
          "name": "backup",
          "mountPath": "/backups"
        }]
      }],
      "volumes": [{
        "name": "backup",
        "persistentVolumeClaim": {
          "claimName": "bob-db-backup-pvc"
        }
      }]
    }
  }'

# Inside the pod:
ls -lh /backups/bob-db/
cat /backups/bob-db/backup_bob_*.sql.gz.meta

A successful backup produces output similar to the following:

==========================================
PostgreSQL Backup Script
==========================================
Cluster: bob-db
Database: bob
Timestamp: 20260902_020000
Backup file: /backups/bob-db/backup_bob_20260902_020000.sql.gz
Retention: 7 backups
==========================================
Starting pg_dump...
✓ Backup completed successfully
  Size: 1.2G
✓ Metadata file created
Cleaning up old backups...
  Current backup count: 7
✓ Cleanup completed
==========================================
✓ Backup process completed successfully
==========================================

Configuration parameters

ParameterRequiredDefaultDescription
scheduleYes—Cron schedule expression (UTC timezone).
backupStorageClassYes—Storage class for backup PVCs.
retentionNo7Number of backups to retain per cluster.
pvcSizeNo10GiPVC size per cluster.
postgresImageNoAuto-detectedPostgreSQL image for backup jobs.
clustersNoDefault clustersList of clusters to back up.

Storage sizing guidelines

To calculate the required storage per cluster:

Required size = (database size × 0.3) × retention × 1.5

Example:
- Database: 5 GB
- Compression: 0.3 (70% compression)
- Retention: 7 backups
- Safety factor: 1.5

Required: 5 × 0.3 × 7 × 1.5 = 15.75 GB ≈ 20 GB
Database sizeRecommended PVCRetention
Less than 1 GB5 Gi7
1–5 GB10 Gi7
5–20 GB50 Gi7
20–50 GB100 Gi5
Greater than 50 GBCustom3–5
How is this topic?