|
| 1 | +--- |
| 2 | +sidebar_position: 10 |
| 3 | +--- |
| 4 | + |
| 5 | +# Main Concepts |
| 6 | + |
| 7 | +<!-- SPDX-License-Identifier: CC-BY-4.0 --> |
| 8 | + |
| 9 | +:::important |
| 10 | +Before proceeding, make sure to review the following sections of the |
| 11 | +CloudNativePG documentation: |
| 12 | + |
| 13 | +- [**Backup**](https://cloudnative-pg.io/documentation/current/backup/) |
| 14 | +- [**WAL Archiving**](https://cloudnative-pg.io/documentation/current/wal_archiving/) |
| 15 | +- [**Recovery**](https://cloudnative-pg.io/documentation/current/recovery/) |
| 16 | +::: |
| 17 | + |
| 18 | +The **Barman Cloud Plugin** enables **hot (online) backups** of PostgreSQL |
| 19 | +clusters in CloudNativePG through [`barman-cloud`](https://pgbarman.org), |
| 20 | +supporting continuous physical backups and WAL archiving to an **object |
| 21 | +store**—without interrupting write operations. |
| 22 | + |
| 23 | +It also supports both **full recovery** and **Point-in-Time Recovery (PITR)** |
| 24 | +of a PostgreSQL cluster. |
| 25 | + |
| 26 | +## The Object Store |
| 27 | + |
| 28 | +At the core is the [`ObjectStore` custom resource (CRD)](plugin-barman-cloud.v1.md#objectstorespec), |
| 29 | +which acts as the interface between the PostgreSQL cluster and the target |
| 30 | +object storage system. It allows you to configure: |
| 31 | + |
| 32 | +- **Authentication and bucket location** via the `.spec.configuration` section |
| 33 | +- **WAL archiving** settings—such as compression type, parallelism, and |
| 34 | + server-side encryption—under `.spec.configuration.wal` |
| 35 | +- **Base backup options**—with similar settings for compression, concurrency, |
| 36 | + and encryption—under `.spec.configuration.data` |
| 37 | +- **Retention policies** to manage the life-cycle of archived WALs and backups |
| 38 | + via `.spec.configuration.retentionPolicy` |
| 39 | + |
| 40 | +WAL files are archived in the `wals` directory, while base backups are stored |
| 41 | +as **tarballs** in the `base` directory, following the |
| 42 | +[Barman Cloud convention](https://docs.pgbarman.org/cloud/latest/usage/#object-store-layout). |
| 43 | + |
| 44 | +The plugin also offers advanced capabilities, including |
| 45 | +[backup tagging](misc.md#backup-object-tagging) and |
| 46 | +[extra options for backups and WAL archiving](misc.md#extra-options-for-backup-and-wal-archiving). |
| 47 | + |
| 48 | +:::tip |
| 49 | +For details, refer to the |
| 50 | +[API reference for the `ObjectStore` resource](plugin-barman-cloud.v1.md#objectstorespec). |
| 51 | +::: |
| 52 | + |
| 53 | +## Integration with a CloudNativePG Cluster |
| 54 | + |
| 55 | +CloudNativePG can delegate continuous backup and recovery responsibilities to |
| 56 | +the **Barman Cloud Plugin** by configuring the `.spec.plugins` section of a |
| 57 | +`Cluster` resource. This setup requires a corresponding `ObjectStore` resource |
| 58 | +to be defined. |
| 59 | + |
| 60 | +:::important |
| 61 | +While it is technically possible to reuse the same `ObjectStore` for multiple |
| 62 | +`Cluster` resources within the same namespace, it is strongly recommended to |
| 63 | +dedicate one object store per PostgreSQL cluster to ensure data isolation and |
| 64 | +operational clarity. |
| 65 | +::: |
| 66 | + |
| 67 | +The following example demonstrates how to configure a CloudNativePG cluster |
| 68 | +named `cluster-example` to use a previously defined `ObjectStore` (also named |
| 69 | +`cluster-example`) in the same namespace. Setting `isWALArchiver: true` enables |
| 70 | +WAL archiving through the plugin: |
| 71 | + |
| 72 | +```yaml |
| 73 | +apiVersion: postgresql.cnpg.io/v1 |
| 74 | +kind: Cluster |
| 75 | +metadata: |
| 76 | + name: cluster-example |
| 77 | +spec: |
| 78 | + # Other cluster settings... |
| 79 | + plugins: |
| 80 | + - name: barman-cloud.cloudnative-pg.io |
| 81 | + isWALArchiver: true |
| 82 | + parameters: |
| 83 | + barmanObjectName: cluster-example |
| 84 | +``` |
| 85 | +
|
| 86 | +## Backup of a Postgres Cluster |
| 87 | +
|
| 88 | +Once the object store is defined and the `Cluster` is configured to use the |
| 89 | +Barman Cloud Plugin, **WAL archiving is activated immediately** on the |
| 90 | +PostgreSQL primary. |
| 91 | + |
| 92 | +Physical base backups are seamlessly managed by CloudNativePG using the |
| 93 | +`Backup` and `ScheduledBackup` resources, respectively for |
| 94 | +[on-demand](https://cloudnative-pg.io/documentation/current/backup/#on-demand-backups) |
| 95 | +and |
| 96 | +[scheduled](https://cloudnative-pg.io/documentation/current/backup/#scheduled-backups) |
| 97 | +backups. |
| 98 | + |
| 99 | +To use the Barman Cloud Plugin, you must set the `method` to `plugin` and |
| 100 | +configure the `pluginConfiguration` section as shown: |
| 101 | + |
| 102 | +```yaml |
| 103 | +[...] |
| 104 | +spec: |
| 105 | + method: plugin |
| 106 | + pluginConfiguration: |
| 107 | + name: barman-cloud.cloudnative-pg.io |
| 108 | + [...] |
| 109 | +``` |
| 110 | + |
| 111 | +With this configuration, CloudNativePG supports: |
| 112 | + |
| 113 | +- Backups from both **primary** and **standby** instances |
| 114 | +- Backups from **designated primaries** in a distributed topology using |
| 115 | + [replica clusters](https://cloudnative-pg.io/documentation/current/replica_cluster/) |
| 116 | + |
| 117 | +:::tip |
| 118 | +For details on how to back up from a standby, refer to the official documentation: |
| 119 | +[Backup from a standby](https://cloudnative-pg.io/documentation/current/backup/#backup-from-a-standby). |
| 120 | +::: |
| 121 | + |
| 122 | +:::important |
| 123 | +Both backup and WAL archiving operations are executed by sidecar containers |
| 124 | +running in the same pod as the PostgreSQL `Cluster` primary instance—except |
| 125 | +when backups are taken from a standby, in which case the sidecar runs alongside |
| 126 | +the standby pod. |
| 127 | +The sidecar containers use a [dedicated container image](images.md) that |
| 128 | +includes only the supported version of Barman Cloud. |
| 129 | +::: |
| 130 | + |
| 131 | +## Recovery of a Postgres Cluster |
| 132 | + |
| 133 | +In PostgreSQL, *recovery* refers to the process of starting a database instance |
| 134 | +from an existing backup. The Barman Cloud Plugin integrates with CloudNativePG |
| 135 | +to support both **full recovery** and **Point-in-Time Recovery (PITR)** from an |
| 136 | +object store. |
| 137 | + |
| 138 | +Recovery in this context is *not in-place*: it bootstraps a brand-new |
| 139 | +PostgreSQL cluster from a backup and replays the necessary WAL files to reach |
| 140 | +the desired recovery target. |
| 141 | + |
| 142 | +To perform a recovery, define an *external cluster* that references the |
| 143 | +appropriate `ObjectStore`, and use it as the source in the `bootstrap` section |
| 144 | +of the target cluster: |
| 145 | + |
| 146 | +```yaml |
| 147 | +[...] |
| 148 | +spec: |
| 149 | + [...] |
| 150 | + bootstrap: |
| 151 | + recovery: |
| 152 | + source: source |
| 153 | + externalClusters: |
| 154 | + - name: source |
| 155 | + plugin: |
| 156 | + name: barman-cloud.cloudnative-pg.io |
| 157 | + parameters: |
| 158 | + barmanObjectName: cluster-example |
| 159 | + serverName: cluster-example |
| 160 | + [...] |
| 161 | +``` |
| 162 | + |
| 163 | +The critical element here is the `externalClusters` section of the `Cluster` |
| 164 | +resource, where the `plugin` stanza instructs CloudNativePG to use the Barman |
| 165 | +Cloud Plugin to access the object store for recovery. |
| 166 | + |
| 167 | +This same mechanism can be used for a variety of scenarios enabled by the |
| 168 | +CloudNativePG API, including: |
| 169 | + |
| 170 | +* **Full cluster recovery** from the latest backup |
| 171 | +* **Point-in-Time Recovery (PITR)** |
| 172 | +* Bootstrapping **replica clusters** in a distributed topology |
| 173 | + |
| 174 | +:::tip |
| 175 | +For complete instructions and advanced use cases, refer to the official |
| 176 | +[Recovery documentation](https://cloudnative-pg.io/documentation/current/recovery/). |
| 177 | +::: |
0 commit comments