Skip to content

Commit a5bc777

Browse files
committed
docs: import CloudNativePG v1.29.0-rc1
1 parent ebccaed commit a5bc777

File tree

194 files changed

+34623
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+34623
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Appendixes",
3+
"position": 600,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,361 @@
1+
---
2+
id: backup_barmanobjectstore
3+
title: Appendix B - Backup on object stores
4+
---
5+
6+
# Appendix B - Backup on object stores
7+
8+
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
9+
10+
:::warning
11+
As of CloudNativePG 1.26, **native Barman Cloud support is deprecated** in
12+
favor of the **Barman Cloud Plugin**. This page has been moved to the appendix
13+
for reference purposes. While the native integration remains functional for
14+
now, we strongly recommend beginning a gradual migration to the plugin-based
15+
interface after appropriate testing. For guidance, see
16+
[Migrating from Built-in CloudNativePG Backup](https://cloudnative-pg.io/plugin-barman-cloud/docs/migration/).
17+
:::
18+
19+
CloudNativePG natively supports **online/hot backup** of PostgreSQL
20+
clusters through continuous physical backup and WAL archiving on an object
21+
store. This means that the database is always up (no downtime required)
22+
and that Point In Time Recovery is available.
23+
24+
The operator can orchestrate a continuous backup infrastructure
25+
that is based on the [Barman Cloud](https://pgbarman.org) tool. Instead
26+
of using the classical architecture with a Barman server, which
27+
backs up many PostgreSQL instances, the operator relies on the
28+
`barman-cloud-wal-archive`, `barman-cloud-check-wal-archive`,
29+
`barman-cloud-backup`, `barman-cloud-backup-list`, and
30+
`barman-cloud-backup-delete` tools. As a result, base backups will
31+
be *tarballs*. Both base backups and WAL files can be compressed
32+
and encrypted.
33+
34+
For this, it is required to use an image with `barman-cli-cloud` included.
35+
You can use the image `ghcr.io/cloudnative-pg/postgresql` for this scope,
36+
as it is composed of a community PostgreSQL image and the latest
37+
`barman-cli-cloud` package.
38+
39+
:::info[Important]
40+
Always ensure that you are running the latest version of the operands
41+
in your system to take advantage of the improvements introduced in
42+
Barman cloud (as well as improve the security aspects of your cluster).
43+
:::
44+
45+
:::warning[Changes in Barman Cloud 3.16+ and Bucket Creation]
46+
Starting with Barman Cloud 3.16, most Barman Cloud commands no longer
47+
automatically create the target bucket, assuming it already exists. Only the
48+
`barman-cloud-check-wal-archive` command creates the bucket now. Whenever this
49+
is not the first operation run on an empty bucket, CloudNativePG will throw an
50+
error. As a result, to ensure reliable, future-proof operations and avoid
51+
potential issues, we strongly recommend that you create and configure your
52+
object store bucket *before* creating a `Cluster` resource that references it.
53+
:::
54+
55+
A backup is performed from a primary or a designated primary instance in a
56+
`Cluster` (please refer to
57+
[replica clusters](../replica_cluster.md)
58+
for more information about designated primary instances), or alternatively
59+
on a [standby](../backup.md#backup-from-a-standby).
60+
61+
## Common object stores
62+
63+
If you are looking for a specific object store such as
64+
[AWS S3](object_stores.md#aws-s3),
65+
[Microsoft Azure Blob Storage](object_stores.md#azure-blob-storage),
66+
[Google Cloud Storage](object_stores.md#google-cloud-storage), or a compatible
67+
provider, please refer to [Appendix C - Common object stores for backups](object_stores.md).
68+
69+
## WAL archiving
70+
71+
WAL archiving is the process that feeds a [WAL archive](../backup.md#wal-archive)
72+
in CloudNativePG.
73+
74+
The WAL archive is defined in the `.spec.backup.barmanObjectStore` stanza of
75+
a `Cluster` resource.
76+
77+
:::info
78+
Please refer to [`BarmanObjectStoreConfiguration`](https://pkg.go.dev/github.com/cloudnative-pg/barman-cloud/pkg/api#BarmanObjectStoreConfiguration)
79+
in the barman-cloud API for a full list of options.
80+
:::
81+
82+
If required, you can choose to compress WAL files as soon as they
83+
are uploaded and/or encrypt them:
84+
85+
```yaml
86+
apiVersion: postgresql.cnpg.io/v1
87+
kind: Cluster
88+
[...]
89+
spec:
90+
backup:
91+
barmanObjectStore:
92+
[...]
93+
wal:
94+
compression: gzip
95+
encryption: AES256
96+
```
97+
98+
You can configure the encryption directly in your bucket, and the operator
99+
will use it unless you override it in the cluster configuration.
100+
101+
PostgreSQL implements a sequential archiving scheme, where the
102+
`archive_command` will be executed sequentially for every WAL
103+
segment to be archived.
104+
105+
:::info[Important]
106+
By default, CloudNativePG sets `archive_timeout` to `5min`, ensuring
107+
that WAL files, even in case of low workloads, are closed and archived
108+
at least every 5 minutes, providing a deterministic time-based value for
109+
your Recovery Point Objective ([RPO](../before_you_start.md#postgresql-terminology)). Even though you change the value
110+
of the [`archive_timeout` setting in the PostgreSQL configuration](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-ARCHIVE-TIMEOUT),
111+
our experience suggests that the default value set by the operator is
112+
suitable for most use cases.
113+
:::
114+
115+
When the bandwidth between the PostgreSQL instance and the object
116+
store allows archiving more than one WAL file in parallel, you
117+
can use the parallel WAL archiving feature of the instance manager
118+
like in the following example:
119+
120+
```yaml
121+
apiVersion: postgresql.cnpg.io/v1
122+
kind: Cluster
123+
[...]
124+
spec:
125+
backup:
126+
barmanObjectStore:
127+
[...]
128+
wal:
129+
compression: gzip
130+
maxParallel: 8
131+
encryption: AES256
132+
```
133+
134+
In the previous example, the instance manager optimizes the WAL
135+
archiving process by archiving in parallel at most eight ready
136+
WALs, including the one requested by PostgreSQL.
137+
138+
When PostgreSQL will request the archiving of a WAL that has
139+
already been archived by the instance manager as an optimization,
140+
that archival request will be just dismissed with a positive status.
141+
142+
## Retention policies
143+
144+
CloudNativePG can manage the automated deletion of backup files from
145+
the backup object store, using **retention policies** based on the recovery
146+
window.
147+
148+
Internally, the retention policy feature uses `barman-cloud-backup-delete`
149+
with `--retention-policy “RECOVERY WINDOW OF {{ retention policy value }} {{ retention policy unit }}”`.
150+
151+
For example, you can define your backups with a retention policy of 30 days as
152+
follows:
153+
154+
```yaml
155+
apiVersion: postgresql.cnpg.io/v1
156+
kind: Cluster
157+
[...]
158+
spec:
159+
backup:
160+
barmanObjectStore:
161+
destinationPath: "<destination path here>"
162+
s3Credentials:
163+
accessKeyId:
164+
name: aws-creds
165+
key: ACCESS_KEY_ID
166+
secretAccessKey:
167+
name: aws-creds
168+
key: ACCESS_SECRET_KEY
169+
retentionPolicy: "30d"
170+
```
171+
172+
:::note[There's more ...]
173+
The **recovery window retention policy** is focused on the concept of
174+
*Point of Recoverability* (`PoR`), a moving point in time determined by
175+
`current time - recovery window`. The *first valid backup* is the first
176+
available backup before `PoR` (in reverse chronological order).
177+
CloudNativePG must ensure that we can recover the cluster at
178+
any point in time between `PoR` and the latest successfully archived WAL
179+
file, starting from the first valid backup. Base backups that are older
180+
than the first valid backup will be marked as *obsolete* and permanently
181+
removed after the next backup is completed.
182+
:::
183+
184+
## Compression algorithms
185+
186+
CloudNativePG by default archives backups and WAL files in an
187+
uncompressed fashion. However, it also supports the following compression
188+
algorithms via `barman-cloud-backup` (for backups) and
189+
`barman-cloud-wal-archive` (for WAL files):
190+
191+
* bzip2
192+
* gzip
193+
* lz4
194+
* snappy
195+
* xz
196+
* zstd
197+
198+
The compression settings for backups and WALs are independent. See the
199+
[DataBackupConfiguration](https://pkg.go.dev/github.com/cloudnative-pg/barman-cloud/pkg/api#DataBackupConfiguration) and
200+
[WALBackupConfiguration](https://pkg.go.dev/github.com/cloudnative-pg/barman-cloud/pkg/api#WalBackupConfiguration) sections in
201+
the barman-cloud API reference.
202+
203+
It is important to note that archival time, restore time, and size change
204+
between the algorithms, so the compression algorithm should be chosen according
205+
to your use case.
206+
207+
The Barman team has performed an evaluation of the performance of the supported
208+
algorithms for Barman Cloud. The following table summarizes a scenario where a
209+
backup is taken on a local MinIO deployment. The Barman GitHub project includes
210+
a [deeper analysis](https://github.com/EnterpriseDB/barman/issues/344#issuecomment-992547396).
211+
212+
| Compression | Backup Time (ms) | Restore Time (ms) | Uncompressed size (MB) | Compressed size (MB) | Approx ratio |
213+
|-------------|------------------|-------------------|------------------------|-----------------------|--------------|
214+
| None | 10927 | 7553 | 395 | 395 | 1:1 |
215+
| bzip2 | 25404 | 13886 | 395 | 67 | 5.9:1 |
216+
| gzip | 116281 | 3077 | 395 | 91 | 4.3:1 |
217+
| snappy | 8134 | 8341 | 395 | 166 | 2.4:1 |
218+
219+
## Tagging of backup objects
220+
221+
Barman 2.18 introduces support for tagging backup resources when saving them in
222+
object stores via `barman-cloud-backup` and `barman-cloud-wal-archive`. As a
223+
result, if your PostgreSQL container image includes Barman with version 2.18 or
224+
higher, CloudNativePG enables you to specify tags as key-value pairs
225+
for backup objects, namely base backups, WAL files and history files.
226+
227+
You can use two properties in the `.spec.backup.barmanObjectStore` definition:
228+
229+
* `tags`: key-value pair tags to be added to backup objects and archived WAL
230+
file in the backup object store
231+
* `historyTags`: key-value pair tags to be added to archived history files in
232+
the backup object store
233+
234+
The excerpt of a YAML manifest below provides an example of usage of this
235+
feature:
236+
237+
```yaml
238+
apiVersion: postgresql.cnpg.io/v1
239+
kind: Cluster
240+
[...]
241+
spec:
242+
backup:
243+
barmanObjectStore:
244+
[...]
245+
tags:
246+
backupRetentionPolicy: "expire"
247+
historyTags:
248+
backupRetentionPolicy: "keep"
249+
```
250+
251+
## Extra options for the backup and WAL commands
252+
253+
You can append additional options to the `barman-cloud-backup` and `barman-cloud-wal-archive` commands by using
254+
the `additionalCommandArgs` property in the
255+
`.spec.backup.barmanObjectStore.data` and `.spec.backup.barmanObjectStore.wal` sections respectively.
256+
These properties are lists of strings that will be appended to the
257+
`barman-cloud-backup` and `barman-cloud-wal-archive` commands.
258+
259+
For example, you can use the `--read-timeout=60` to customize the connection
260+
reading timeout.
261+
262+
For additional options supported by `barman-cloud-backup` and `barman-cloud-wal-archive` commands you can refer to the
263+
official barman documentation [here](https://www.pgbarman.org/documentation/).
264+
265+
If an option provided in `additionalCommandArgs` is already present in the
266+
declared options in its section (`.spec.backup.barmanObjectStore.data` or `.spec.backup.barmanObjectStore.wal`), the extra option will be
267+
ignored.
268+
269+
The following is an example of how to use this property:
270+
271+
For backups:
272+
273+
```yaml
274+
apiVersion: postgresql.cnpg.io/v1
275+
kind: Cluster
276+
[...]
277+
spec:
278+
backup:
279+
barmanObjectStore:
280+
[...]
281+
data:
282+
additionalCommandArgs:
283+
- "--min-chunk-size=5MB"
284+
- "--read-timeout=60"
285+
```
286+
287+
For WAL files:
288+
289+
```yaml
290+
apiVersion: postgresql.cnpg.io/v1
291+
kind: Cluster
292+
[...]
293+
spec:
294+
backup:
295+
barmanObjectStore:
296+
[...]
297+
wal:
298+
additionalCommandArgs:
299+
- "--max-concurrency=1"
300+
- "--read-timeout=60"
301+
```
302+
303+
## Recovery from an object store
304+
305+
You can recover from a backup created by Barman Cloud and stored on a supported
306+
object store. After you define the external cluster, including all the required
307+
configuration in the `barmanObjectStore` section, you need to reference it in
308+
the `.spec.recovery.source` option.
309+
310+
This example defines a recovery object store in a blob container in Azure:
311+
312+
```yaml
313+
apiVersion: postgresql.cnpg.io/v1
314+
kind: Cluster
315+
metadata:
316+
name: cluster-restore
317+
spec:
318+
[...]
319+
320+
superuserSecret:
321+
name: superuser-secret
322+
323+
bootstrap:
324+
recovery:
325+
source: clusterBackup
326+
327+
externalClusters:
328+
- name: clusterBackup
329+
barmanObjectStore:
330+
destinationPath: https://STORAGEACCOUNTNAME.blob.core.windows.net/CONTAINERNAME/
331+
azureCredentials:
332+
storageAccount:
333+
name: recovery-object-store-secret
334+
key: storage_account_name
335+
storageKey:
336+
name: recovery-object-store-secret
337+
key: storage_account_key
338+
wal:
339+
maxParallel: 8
340+
```
341+
342+
The previous example assumes that the application database and its owning user
343+
are named `app` by default. If the PostgreSQL cluster being restored uses
344+
different names, you must specify these names before exiting the recovery phase,
345+
as documented in ["Configure the application database"](../recovery.md#configure-the-application-database).
346+
347+
:::info[Important]
348+
By default, the `recovery` method strictly uses the `name` of the
349+
cluster in the `externalClusters` section as the name of the main folder
350+
of the backup data within the object store. This name is normally reserved
351+
for the name of the server. You can specify a different folder name
352+
using the `barmanObjectStore.serverName` property.
353+
:::
354+
355+
:::note
356+
This example takes advantage of the parallel WAL restore feature,
357+
dedicating up to 8 jobs to concurrently fetch the required WAL files from the
358+
archive. This feature can appreciably reduce the recovery time. Make sure that
359+
you plan ahead for this scenario and correctly tune the value of this parameter
360+
for your environment. It will make a difference when you need it, and you will.
361+
:::

0 commit comments

Comments
 (0)