CYBERTEC PostgreSQL Logo

Exploration: PostgreSQL Cluster Backup with Barman(CNPG)

08.2025
Category: 

Introduction

The importance of backups is universally acknowledged in our digital world. One of my former esteemed colleagues told me that he can't think of a database system without backups. This perspective has resonated with me over the years. Today, in our CNPG series, we will be taking a look at the backup solution and how we restore a database from the backup.

Backing up PostgreSQL in a Kubernetes-native way is easy with the CloudNativePG (CNPG) operator and the Barman Cloud plugin. So, for the backup, we will be using barman, and as storage, MinIO S3 compatible storage for creating a cloud-native environment.


Verify CloudNativePG Version

First, let’s check the version of the CNPG operator to ensure it supports the barman plugin as described here:


Install the Barman Cloud Plugin

At the moment, CNPG officially supports barman. That is why we need to apply the official plugin manifest:

You’ll see a number of resources created, including:

  • CRDs like ObjectStore
  • RBAC rules
  • A barman-cloud deployment

Check rollout status:


Define Your Cluster and Object Store

Here’s the full manifest used for a single-instance PostgreSQL cluster with plugin-based backups using MinIO:

An important thing to mention here is that how we define MinIO storage and access it is pretty similar to S3. Another important thing is that the barman-cloud plugin is responsible for WAL archiving as well as backups. Let' s apply it:

Note: only one plugin can be responsible for archiving at a time.


Check Backup Status

Verify all pods are running and confirm the backups:

During the verification, it is important to emphasize two things:

  • This backup is just a one time backup, it is not a backup schedule.
  • Due to default settings, our cluster has 3 services; rw, ro, and r, as we mentioned in our previous blog.

Let's create a simple test database for recovery:


Create a Scheduled Backup

We can create a backup schedule now. Here’s how to run backups every 5 seconds (for demo purposes):

Apply it:


Restore Cluster From ObjectStore

Here's the manifest for a new PostgreSQL cluster (this is not an in-place recovery) called cluster-restore, which will be bootstrapped from the object store, which is minio-store in our case:

Key parts of this manifest:

  • bootstrap.recovery.source: tells CNPG to recover from an external cluster called origin
  • externalClusters: defines the recovery source

Apply the restore configuration:

In order to recover a specific backup, we could use:


Validate Recovered Cluster

Validate the cluster:

The cluster "cluster-restore" is up and running with its own services (rw, ro and r).

 

Leave a Reply

Your email address will not be published. Required fields are marked *

CYBERTEC Logo white
Get the newest PostgreSQL Info & Tools


    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    ©
    2025
    CYBERTEC PostgreSQL International GmbH
    phone-handsetmagnifiercrosscross-circle
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram