|
1 | | -# Backup on object stores |
| 1 | +# Appendix B - Backup on object stores |
| 2 | + |
2 | 3 | <!-- SPDX-License-Identifier: CC-BY-4.0 --> |
3 | 4 |
|
4 | 5 | !!! Warning |
5 | | - With the deprecation of native Barman Cloud support in CloudNativePG in |
6 | | - favor of the Barman Cloud Plugin, this page—and the backup and recovery |
7 | | - documentation—may undergo changes before the official release of version |
8 | | - 1.26.0. |
| 6 | + As of CloudNativePG 1.26, **native Barman Cloud support is deprecated** in |
| 7 | + favor of the **Barman Cloud Plugin**. This page has been moved to the appendix |
| 8 | + for reference purposes. While the native integration remains functional for |
| 9 | + now, we strongly recommend beginning a gradual migration to the plugin-based |
| 10 | + interface after appropriate testing. For guidance, see |
| 11 | + [Migrating from Built-in CloudNativePG Backup](https://cloudnative-pg.io/plugin-barman-cloud/docs/migration/). |
9 | 12 |
|
10 | 13 | CloudNativePG natively supports **online/hot backup** of PostgreSQL |
11 | 14 | clusters through continuous physical backup and WAL archiving on an object |
@@ -34,23 +37,90 @@ as it is composed of a community PostgreSQL image and the latest |
34 | 37 |
|
35 | 38 | A backup is performed from a primary or a designated primary instance in a |
36 | 39 | `Cluster` (please refer to |
37 | | -[replica clusters](replica_cluster.md) |
| 40 | +[replica clusters](../replica_cluster.md) |
38 | 41 | for more information about designated primary instances), or alternatively |
39 | | -on a [standby](backup.md#backup-from-a-standby). |
| 42 | +on a [standby](../backup.md#backup-from-a-standby). |
40 | 43 |
|
41 | 44 | ## Common object stores |
42 | 45 |
|
43 | 46 | If you are looking for a specific object store such as |
44 | | -[AWS S3](appendixes/object_stores.md#aws-s3), |
45 | | -[Microsoft Azure Blob Storage](appendixes/object_stores.md#azure-blob-storage), |
46 | | -[Google Cloud Storage](appendixes/object_stores.md#google-cloud-storage), or |
47 | | -[MinIO Gateway](appendixes/object_stores.md#minio-gateway), or a compatible |
48 | | -provider, please refer to [Appendix A - Common object stores](appendixes/object_stores.md). |
| 47 | +[AWS S3](object_stores.md#aws-s3), |
| 48 | +[Microsoft Azure Blob Storage](object_stores.md#azure-blob-storage), |
| 49 | +[Google Cloud Storage](object_stores.md#google-cloud-storage), or a compatible |
| 50 | +provider, please refer to [Appendix C - Common object stores for backups](object_stores.md). |
49 | 51 |
|
50 | | -## Retention policies |
| 52 | +## WAL archiving |
| 53 | + |
| 54 | +WAL archiving is the process that feeds a [WAL archive](../backup.md#wal-archive) |
| 55 | +in CloudNativePG. |
| 56 | + |
| 57 | +The WAL archive is defined in the `.spec.backup.barmanObjectStore` stanza of |
| 58 | +a `Cluster` resource. |
| 59 | + |
| 60 | +!!! Info |
| 61 | + Please refer to [`BarmanObjectStoreConfiguration`](https://pkg.go.dev/github.com/cloudnative-pg/barman-cloud/pkg/api#BarmanObjectStoreConfiguration) |
| 62 | + in the barman-cloud API for a full list of options. |
| 63 | + |
| 64 | +If required, you can choose to compress WAL files as soon as they |
| 65 | +are uploaded and/or encrypt them: |
| 66 | + |
| 67 | +```yaml |
| 68 | +apiVersion: postgresql.cnpg.io/v1 |
| 69 | +kind: Cluster |
| 70 | +[...] |
| 71 | +spec: |
| 72 | + backup: |
| 73 | + barmanObjectStore: |
| 74 | + [...] |
| 75 | + wal: |
| 76 | + compression: gzip |
| 77 | + encryption: AES256 |
| 78 | +``` |
| 79 | +
|
| 80 | +You can configure the encryption directly in your bucket, and the operator |
| 81 | +will use it unless you override it in the cluster configuration. |
| 82 | +
|
| 83 | +PostgreSQL implements a sequential archiving scheme, where the |
| 84 | +`archive_command` will be executed sequentially for every WAL |
| 85 | +segment to be archived. |
51 | 86 |
|
52 | 87 | !!! Important |
53 | | - Retention policies are not currently available on volume snapshots. |
| 88 | + By default, CloudNativePG sets `archive_timeout` to `5min`, ensuring |
| 89 | + that WAL files, even in case of low workloads, are closed and archived |
| 90 | + at least every 5 minutes, providing a deterministic time-based value for |
| 91 | + your Recovery Point Objective ([RPO](../before_you_start.md#rpo)). Even though you change the value |
| 92 | + of the [`archive_timeout` setting in the PostgreSQL configuration](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-ARCHIVE-TIMEOUT), |
| 93 | + our experience suggests that the default value set by the operator is |
| 94 | + suitable for most use cases. |
| 95 | + |
| 96 | +When the bandwidth between the PostgreSQL instance and the object |
| 97 | +store allows archiving more than one WAL file in parallel, you |
| 98 | +can use the parallel WAL archiving feature of the instance manager |
| 99 | +like in the following example: |
| 100 | + |
| 101 | +```yaml |
| 102 | +apiVersion: postgresql.cnpg.io/v1 |
| 103 | +kind: Cluster |
| 104 | +[...] |
| 105 | +spec: |
| 106 | + backup: |
| 107 | + barmanObjectStore: |
| 108 | + [...] |
| 109 | + wal: |
| 110 | + compression: gzip |
| 111 | + maxParallel: 8 |
| 112 | + encryption: AES256 |
| 113 | +``` |
| 114 | + |
| 115 | +In the previous example, the instance manager optimizes the WAL |
| 116 | +archiving process by archiving in parallel at most eight ready |
| 117 | +WALs, including the one requested by PostgreSQL. |
| 118 | + |
| 119 | +When PostgreSQL will request the archiving of a WAL that has |
| 120 | +already been archived by the instance manager as an optimization, |
| 121 | +that archival request will be just dismissed with a positive status. |
| 122 | + |
| 123 | +## Retention policies |
54 | 124 |
|
55 | 125 | CloudNativePG can manage the automated deletion of backup files from |
56 | 126 | the backup object store, using **retention policies** based on the recovery |
@@ -163,7 +233,7 @@ spec: |
163 | 233 | You can append additional options to the `barman-cloud-backup` and `barman-cloud-wal-archive` commands by using |
164 | 234 | the `additionalCommandArgs` property in the |
165 | 235 | `.spec.backup.barmanObjectStore.data` and `.spec.backup.barmanObjectStore.wal` sections respectively. |
166 | | -This properties are lists of strings that will be appended to the |
| 236 | +These properties are lists of strings that will be appended to the |
167 | 237 | `barman-cloud-backup` and `barman-cloud-wal-archive` commands. |
168 | 238 |
|
169 | 239 | For example, you can use the `--read-timeout=60` to customize the connection |
@@ -209,3 +279,61 @@ spec: |
209 | 279 | - "--max-concurrency=1" |
210 | 280 | - "--read-timeout=60" |
211 | 281 | ``` |
| 282 | + |
| 283 | +## Recovery from an object store |
| 284 | + |
| 285 | +You can recover from a backup created by Barman Cloud and stored on a supported |
| 286 | +object store. After you define the external cluster, including all the required |
| 287 | +configuration in the `barmanObjectStore` section, you need to reference it in |
| 288 | +the `.spec.recovery.source` option. |
| 289 | + |
| 290 | +This example defines a recovery object store in a blob container in Azure: |
| 291 | + |
| 292 | +```yaml |
| 293 | +apiVersion: postgresql.cnpg.io/v1 |
| 294 | +kind: Cluster |
| 295 | +metadata: |
| 296 | + name: cluster-restore |
| 297 | +spec: |
| 298 | + [...] |
| 299 | +
|
| 300 | + superuserSecret: |
| 301 | + name: superuser-secret |
| 302 | +
|
| 303 | + bootstrap: |
| 304 | + recovery: |
| 305 | + source: clusterBackup |
| 306 | +
|
| 307 | + externalClusters: |
| 308 | + - name: clusterBackup |
| 309 | + barmanObjectStore: |
| 310 | + destinationPath: https://STORAGEACCOUNTNAME.blob.core.windows.net/CONTAINERNAME/ |
| 311 | + azureCredentials: |
| 312 | + storageAccount: |
| 313 | + name: recovery-object-store-secret |
| 314 | + key: storage_account_name |
| 315 | + storageKey: |
| 316 | + name: recovery-object-store-secret |
| 317 | + key: storage_account_key |
| 318 | + wal: |
| 319 | + maxParallel: 8 |
| 320 | +``` |
| 321 | + |
| 322 | +The previous example assumes that the application database and its owning user |
| 323 | +are named `app` by default. If the PostgreSQL cluster being restored uses |
| 324 | +different names, you must specify these names before exiting the recovery phase, |
| 325 | +as documented in ["Configure the application database"](../recovery.md#configure-the-application-database). |
| 326 | + |
| 327 | +!!! Important |
| 328 | + By default, the `recovery` method strictly uses the `name` of the |
| 329 | + cluster in the `externalClusters` section as the name of the main folder |
| 330 | + of the backup data within the object store. This name is normally reserved |
| 331 | + for the name of the server. You can specify a different folder name |
| 332 | + using the `barmanObjectStore.serverName` property. |
| 333 | + |
| 334 | +!!! Note |
| 335 | + This example takes advantage of the parallel WAL restore feature, |
| 336 | + dedicating up to 8 jobs to concurrently fetch the required WAL files from the |
| 337 | + archive. This feature can appreciably reduce the recovery time. Make sure that |
| 338 | + you plan ahead for this scenario and correctly tune the value of this parameter |
| 339 | + for your environment. It will make a difference when you need it, and you will. |
0 commit comments