OpenEBS VolumeSnapshots for CloudNativePG Backups
Overview#
As PostgreSQL deployments scale in Kubernetes environments, traditional logical backups such as pg_dump can become increasingly time-consuming and resource-intensive. These approaches often struggle to meet recovery time objectives (RTOs) for large or performance-sensitive databases.
OpenEBS VolumeSnapshots offer a more efficient alternative by capturing the state of persistent volumes at a specific point in time. This snapshot-based approach enables near-instant backups with minimal performance impact, making it well suited for cloud-native database workloads that require fast and reliable recovery.
By integrating OpenEBS VolumeSnapshots with CloudNativePG (CNPG), you can implement efficient, storage-level backups and restore PostgreSQL clusters directly from snapshots. This document explains how to configure the environment, set up snapshot classes, perform VolumeSnapshot-based backups, recover PostgreSQL clusters, and verify restored data in a Kubernetes environment.
Environment#
The following versions were used for this workflow:
| Component | Version |
|---|---|
| CloudNativePG | v1.25.1 |
| OpenEBS | v4.2.0 |
| Kubernetes | v1.29.6 |
| kubectl cnpg plugin | v1.25.1 |
Prerequisites#
Setup OpenEBS#
Install OpenEBS
Ensure that OpenEBS is installed in your cluster. Refer to the OpenEBS Installation Documentation for step-by-step instructions.
Install the
kubectl-openebsPluginEnsure that
kubectl-openebsplugin is installed. Refer to the Kubectl OpenEBS Plugin Documentation to install the plugin.Create a StorageClass
- Create a file named
StorageClass.yaml.
StorageClass.yaml
- Apply the configuration.
Create a VolumeSnapshotClass#
- Create a file named
VolumeSnapshotClass.yaml.
- Apply the configuration.
CloudNativePG Operator and PostgreSQL Cluster Setup#
- Install the CNPG operator using the official manifest.
note
By default, the operator is installed in the cnpg-system namespace.
Refer to the CloudNativePG Installation Documentation for alternative installation methods.
- Install the kubectl CNPG plugin using Homebrew on macOS.
Refer to the CloudNativePG kubectl Plugin Documentation for installation instructions on Linux, Windows, or other platforms.
Deploying a PostgreSQL Cluster#
- Create a namespace for PostgreSQL cluster.
- Create the PostgreSQL cluster custom resource.
Cluster.yaml
- Create the PostgreSQL cluster.
Sample Output
Insert Sample Data into the PostgreSQL Database#
- Connect to the PostgreSQL cluster.
- Create database and insert sample data.
Sample Output
Backup Using VolumeSnapshots#
important
Snapshot creation is subject to Replicated PV Mayastor capacity and commitment limits. Refer Operational Considerations - Snapshot Capacity and Commitment Considerations for more information.
CloudNativePG supports two snapshot-based backup modes:
Online (Hot) Backups: Taken while PostgreSQL is running
Offline (Cold) Backups: Taken while PostgreSQL instances are stopped
Perform an Online Backup
Create an online VolumeSnapshot backup.
Backup behavior can be controlled using spec.backup.volumeSnapshot options such as online, immediateCheckpoint, and waitForArchive.
- Perform an Offline Backup
warning
Performing a cold backup with volumesnapshots targeting the primary will result in primary instance shutdown and write operation disruption. This also occurs in single-instance clusters, even without explicitly targeting the primary.
Create an offline VolumeSnapshot backup.
Check backup status.
note
For reliable recovery, cold backups are recommended over hot backups. By default, backups are performed on the most suitable replica, or on the primary instance if no replicas are available. This behavior can be modified to explicitly target the primary instance by setting spec.backup.target="Primary" in the cluster definition or spec.target="Primary" in the Backup custom resource (CRD).
Recovery Using VolumeSnapshots#
- List VolumeSnapshots in the cluster namespace.
Sample Output
- Create a new cluster using the existing VolumeSnapshots.
RecoverCluster.yaml
Sample Output
info
The recovery cluster must be created in the same namespace as the source cluster.
Verify Restored Data#
- Connect to the restored PostgreSQL cluster.
- Verify the restored data.
Sample Output
Successful output confirms that the database was restored correctly from the VolumeSnapshots.
See Also#
- Replicated PV Mayastor Installation on OpenShift
- Replicated PV Mayastor Installation on Talos
- Kasten Backup and Restore using Replicated PV Mayastor Snapshots - FileSystem
- Velero Backup and Restore using Replicated PV Mayastor Snapshots - FileSystem
- KubeVirt VM Backup and Restore using Replicated PV Mayastor VolumeSnapshots and Velero - FileSystem