-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathindex.html
More file actions
762 lines (739 loc) · 33.7 KB
/
index.html
File metadata and controls
762 lines (739 loc) · 33.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="author" content="The CloudNativePG Contributors" />
<link rel="shortcut icon" href="../img/favicon.ico" />
<title>Backup - CloudNativePG v1.25</title>
<link rel="stylesheet" href="../css/theme.css" />
<link rel="stylesheet" href="../css/theme_extra.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css" />
<link href="../css/override.css" rel="stylesheet" />
<script>
// Current page data
var mkdocs_page_name = "Backup";
var mkdocs_page_input_path = "backup.md";
var mkdocs_page_url = null;
</script>
<!--[if lt IE 9]>
<script src="../js/html5shiv.min.js"></script>
<![endif]-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href=".." class="icon icon-home"> CloudNativePG v1.25
</a><div role="search">
<form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" title="Type search term here" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul>
<li class="toctree-l1"><a class="reference internal" href="..">CloudNativePG</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../before_you_start/">Before You Start</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../use_cases/">Use cases</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../architecture/">Architecture</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation_upgrade/">Installation and upgrades</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../quickstart/">Quickstart</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../image_catalog/">Image Catalog</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../bootstrap/">Bootstrap</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../database_import/">Importing Postgres databases</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../security/">Security</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../instance_manager/">Postgres instance manager</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../scheduling/">Scheduling</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../resource_management/">Resource management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../failure_modes/">Failure Modes</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../rolling_update/">Rolling Updates</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../replication/">Replication</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../logical_replication/">Logical Replication</a>
</li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal current" href="#">Backup</a>
<ul class="current">
<li class="toctree-l2"><a class="reference internal" href="#wal-archive">WAL archive</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cold-and-hot-backups">Cold and Hot backups</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#object-stores-or-volume-snapshots-which-one-to-use">Object stores or volume snapshots: which one to use?</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#scheduled-backups">Scheduled backups</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#on-demand-backups">On-demand backups</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#backup-from-a-standby">Backup from a standby</a>
</li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../backup_barmanobjectstore/">Backup on object stores</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../wal_archiving/">WAL archiving</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../backup_volumesnapshot/">Backup on volume snapshots</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../recovery/">Recovery</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../service_management/">Service Management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../postgresql_conf/">PostgreSQL Configuration</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../declarative_role_management/">PostgreSQL Role Management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../declarative_database_management/">PostgreSQL Database Management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tablespaces/">Tablespaces</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../operator_conf/">Operator configuration</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cluster_conf/">Instance pod configuration</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../storage/">Storage</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../labels_annotations/">Labels and annotations</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../monitoring/">Monitoring</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../logging/">Logging</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../certificates/">Certificates</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../ssl_connections/">Client TLS/SSL connections</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../applications/">Connecting from an application</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../connection_pooling/">Connection pooling</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../replica_cluster/">Replica clusters</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../kubernetes_upgrade/">Kubernetes Upgrade and Maintenance</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../kubectl-plugin/">Kubectl Plugin</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../failover/">Automated failover</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../troubleshooting/">Troubleshooting</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../fencing/">Fencing</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../declarative_hibernation/">Declarative hibernation</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../postgis/">PostGIS</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../e2e/">End-to-End Tests</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../container_images/">Container Image Requirements</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../operator_capability_levels/">Operator capability levels</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../controller/">Custom Pod Controller</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../samples/">Examples</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../networking/">Networking</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../benchmarking/">Benchmarking</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../faq/">Frequently Asked Questions (FAQ)</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cloudnative-pg.v1/">API Reference</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../supported_releases/">Supported releases</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../preview_version/">Preview Versions</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../release_notes/">Release notes</a>
</li>
</ul>
<p class="caption"><span class="caption-text">CNCF Projects Integrations</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cncf-projects/external-secrets/">External Secrets</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cncf-projects/cilium/">Cilium</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Appendixes</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../appendixes/object_stores/">Appendix A - Common object stores for backups</a>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="..">CloudNativePG v1.25</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href=".." class="icon icon-home" aria-label="Docs"></a></li>
<li class="breadcrumb-item active">Backup</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div class="section" itemprop="articleBody">
<h1 id="backup">Backup</h1>
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
<p>PostgreSQL natively provides first class backup and recovery capabilities based
on file system level (physical) copy. These have been successfully used for
more than 15 years in mission critical production databases, helping
organizations all over the world achieve their disaster recovery goals with
Postgres.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There's another way to backup databases in PostgreSQL, through the
<code>pg_dump</code> utility - which relies on logical backups instead of physical ones.
However, logical backups are not suitable for business continuity use cases
and as such are not covered by CloudNativePG (yet, at least).
If you want to use the <code>pg_dump</code> utility, let yourself be inspired by the
<a href="../troubleshooting/#emergency-backup">"Troubleshooting / Emergency backup" section</a>.</p>
</div>
<p>In CloudNativePG, the backup infrastructure for each PostgreSQL cluster is made
up of the following resources:</p>
<ul>
<li><strong>WAL archive</strong>: a location containing the WAL files (transactional logs)
that are continuously written by Postgres and archived for data durability</li>
<li><strong>Physical base backups</strong>: a copy of all the files that PostgreSQL uses to
store the data in the database (primarily the <code>PGDATA</code> and any tablespace)</li>
</ul>
<p>The WAL archive can only be stored on object stores at the moment.</p>
<p>On the other hand, CloudNativePG supports two ways to store physical base backups:</p>
<ul>
<li>on <a href="../backup_barmanobjectstore/">object stores</a>, as tarballs - optionally
compressed</li>
<li>on <a href="../backup_volumesnapshot/">Kubernetes Volume Snapshots</a>, if supported by
the underlying storage class</li>
</ul>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Before choosing your backup strategy with CloudNativePG, it is important that
you take some time to familiarize with some basic concepts, like WAL archive,
hot and cold backups.</p>
</div>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Please refer to the official Kubernetes documentation for a list of all
the supported <a href="https://kubernetes-csi.github.io/docs/drivers.html">Container Storage Interface (CSI) drivers</a>
that provide snapshotting capabilities.</p>
</div>
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Starting with version 1.25, CloudNativePG includes experimental support for
backup and recovery using plugins, such as the
<a href="https://github.com/cloudnative-pg/plugin-barman-cloud">Barman Cloud plugin</a>.</p>
</div>
<h2 id="wal-archive">WAL archive</h2>
<p>The WAL archive in PostgreSQL is at the heart of <strong>continuous backup</strong>, and it
is fundamental for the following reasons:</p>
<ul>
<li><strong>Hot backups</strong>: the possibility to take physical base backups from any
instance in the Postgres cluster (either primary or standby) without shutting
down the server; they are also known as online backups</li>
<li><strong>Point in Time recovery</strong> (PITR): to possibility to recover at any point in
time from the first available base backup in your system</li>
</ul>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>WAL archive alone is useless. Without a physical base backup, you cannot
restore a PostgreSQL cluster.</p>
</div>
<p>In general, the presence of a WAL archive enhances the resilience of a
PostgreSQL cluster, allowing each instance to fetch any required WAL file from
the archive if needed (normally the WAL archive has higher retention periods
than any Postgres instance that normally recycles those files).</p>
<p>This use case can also be extended to <a href="../replica_cluster/">replica clusters</a>,
as they can simply rely on the WAL archive to synchronize across long
distances, extending disaster recovery goals across different regions.</p>
<p>When you <a href="../wal_archiving/">configure a WAL archive</a>, CloudNativePG provides
out-of-the-box an <a href="../before_you_start/#rpo">RPO</a> <= 5 minutes for disaster
recovery, even across regions.</p>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Our recommendation is to always setup the WAL archive in production.
There are known use cases - normally involving staging and development
environments - where none of the above benefits are needed and the WAL
archive is not necessary. RPO in this case can be any value, such as
24 hours (daily backups) or infinite (no backup at all).</p>
</div>
<h2 id="cold-and-hot-backups">Cold and Hot backups</h2>
<p>Hot backups have already been defined in the previous section. They require the
presence of a WAL archive and they are the norm in any modern database management
system.</p>
<p><strong>Cold backups</strong>, also known as offline backups, are instead physical base backups
taken when the PostgreSQL instance (standby or primary) is shut down. They are
consistent per definition and they represent a snapshot of the database at the
time it was shut down.</p>
<p>As a result, PostgreSQL instances can be restarted from a cold backup without
the need of a WAL archive, even though they can take advantage of it, if
available (with all the benefits on the recovery side highlighted in the
previous section).</p>
<p>In those situations with a higher RPO (for example, 1 hour or 24 hours), and
shorter retention periods, cold backups represent a viable option to be considered
for your disaster recovery plans.</p>
<h2 id="object-stores-or-volume-snapshots-which-one-to-use">Object stores or volume snapshots: which one to use?</h2>
<p>In CloudNativePG, object store based backups:</p>
<ul>
<li>always require the WAL archive</li>
<li>support hot backup only</li>
<li>don't support incremental copy</li>
<li>don't support differential copy</li>
</ul>
<p>VolumeSnapshots instead:</p>
<ul>
<li>don't require the WAL archive, although in production it is always recommended</li>
<li>support incremental copy, depending on the underlying storage classes</li>
<li>support differential copy, depending on the underlying storage classes</li>
<li>also support cold backup</li>
</ul>
<p>Which one to use depends on your specific requirements and environment,
including:</p>
<ul>
<li>availability of a viable object store solution in your Kubernetes cluster</li>
<li>availability of a trusted storage class that supports volume snapshots</li>
<li>size of the database: with object stores, the larger your database, the
longer backup and, most importantly, recovery procedures take (the latter
impacts <a href="../before_you_start/#rto">RTO</a>); in presence of Very Large Databases
(VLDB), the general advice is to rely on Volume Snapshots as, thanks to
copy-on-write, they provide faster recovery</li>
<li>data mobility and possibility to store or relay backup files on a
secondary location in a different region, or any subsequent one</li>
<li>other factors, mostly based on the confidence and familiarity with the
underlying storage solutions</li>
</ul>
<p>The summary table below highlights some of the main differences between the two
available methods for storing physical base backups.</p>
<table>
<thead>
<tr>
<th></th>
<th style="text-align: center;">Object store</th>
<th style="text-align: center;">Volume Snapshots</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>WAL archiving</strong></td>
<td style="text-align: center;">Required</td>
<td style="text-align: center;">Recommended (1)</td>
</tr>
<tr>
<td><strong>Cold backup</strong></td>
<td style="text-align: center;">✗</td>
<td style="text-align: center;">✓</td>
</tr>
<tr>
<td><strong>Hot backup</strong></td>
<td style="text-align: center;">✓</td>
<td style="text-align: center;">✓</td>
</tr>
<tr>
<td><strong>Incremental copy</strong></td>
<td style="text-align: center;">✗</td>
<td style="text-align: center;">✓ (2)</td>
</tr>
<tr>
<td><strong>Differential copy</strong></td>
<td style="text-align: center;">✗</td>
<td style="text-align: center;">✓ (2)</td>
</tr>
<tr>
<td><strong>Backup from a standby</strong></td>
<td style="text-align: center;">✓</td>
<td style="text-align: center;">✓</td>
</tr>
<tr>
<td><strong>Snapshot recovery</strong></td>
<td style="text-align: center;">✗ (3)</td>
<td style="text-align: center;">✓</td>
</tr>
<tr>
<td><strong>Point In Time Recovery (PITR)</strong></td>
<td style="text-align: center;">✓</td>
<td style="text-align: center;">Requires WAL archive</td>
</tr>
<tr>
<td><strong>Underlying technology</strong></td>
<td style="text-align: center;">Barman Cloud</td>
<td style="text-align: center;">Kubernetes API</td>
</tr>
</tbody>
</table>
<blockquote>
<p>See the explanation below for the notes in the above table:</p>
<ol>
<li>WAL archive must be on an object store at the moment</li>
<li>If supported by the underlying storage classes of the PostgreSQL volumes</li>
<li>Snapshot recovery can be emulated using the
<code>bootstrap.recovery.recoveryTarget.targetImmediate</code> option</li>
</ol>
</blockquote>
<h2 id="scheduled-backups">Scheduled backups</h2>
<p>Scheduled backups are the recommended way to configure your backup strategy in
CloudNativePG. They are managed by the <code>ScheduledBackup</code> resource.</p>
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Please refer to <a href="../cloudnative-pg.v1/#postgresql-cnpg-io-v1-ScheduledBackupSpec"><code>ScheduledBackupSpec</code></a>
in the API reference for a full list of options.</p>
</div>
<p>The <code>schedule</code> field allows you to define a <em>six-term cron schedule</em> specification,
which includes seconds, as expressed in
the <a href="https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format">Go <code>cron</code> package format</a>.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Beware that this format accepts also the <code>seconds</code> field, and it is
different from the <code>crontab</code> format in Unix/Linux systems.</p>
</div>
<p>This is an example of a scheduled backup:</p>
<pre><code class="language-yaml">apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
name: backup-example
spec:
schedule: "0 0 0 * * *"
backupOwnerReference: self
cluster:
name: pg-backup
</code></pre>
<p>The above example will schedule a backup every day at midnight because the schedule
specifies zero for the second, minute, and hour, while specifying wildcard, meaning all,
for day of the month, month, and day of the week.</p>
<p>In Kubernetes CronJobs, the equivalent expression is <code>0 0 * * *</code> because seconds
are not included.</p>
<div class="admonition hint">
<p class="admonition-title">Hint</p>
<p>Backup frequency might impact your recovery time objective (<a href="../before_you_start/#rto">RTO</a>) after a
disaster which requires a full or Point-In-Time recovery operation. Our
advice is that you regularly test your backups by recovering them, and then
measuring the time it takes to recover from scratch so that you can refine
your RTO predictability. Recovery time is influenced by the size of the
base backup and the amount of WAL files that need to be fetched from the archive
and replayed during recovery (remember that WAL archiving is what enables
continuous backup in PostgreSQL!).
Based on our experience, a weekly base backup is more than enough for most
cases - while it is extremely rare to schedule backups more frequently than once
a day.</p>
</div>
<p>You can choose whether to schedule a backup on a defined object store or a
volume snapshot via the <code>.spec.method</code> attribute, by default set to
<code>barmanObjectStore</code>. If you have properly defined
<a href="../backup_volumesnapshot/#how-to-configure-volume-snapshot-backups">volume snapshots</a>
in the <code>backup</code> stanza of the cluster, you can set <code>method: volumeSnapshot</code>
to start scheduling base backups on volume snapshots.</p>
<p>ScheduledBackups can be suspended, if needed, by setting <code>.spec.suspend: true</code>.
This will stop any new backup from being scheduled until the option is removed
or set back to <code>false</code>.</p>
<p>In case you want to issue a backup as soon as the ScheduledBackup resource is created
you can set <code>.spec.immediate: true</code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code>.spec.backupOwnerReference</code> indicates which ownerReference should be put inside
the created backup resources.</p>
<ul>
<li><em>none:</em> no owner reference for created backup objects (same behavior as before the field was introduced)</li>
<li><em>self:</em> sets the Scheduled backup object as owner of the backup</li>
<li><em>cluster:</em> set the cluster as owner of the backup</li>
</ul>
</div>
<h2 id="on-demand-backups">On-demand backups</h2>
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Please refer to <a href="../cloudnative-pg.v1/#postgresql-cnpg-io-v1-BackupSpec"><code>BackupSpec</code></a>
in the API reference for a full list of options.</p>
</div>
<p>To request a new backup, you need to create a new <code>Backup</code> resource
like the following one:</p>
<pre><code class="language-yaml">apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: backup-example
spec:
method: barmanObjectStore
cluster:
name: pg-backup
</code></pre>
<p>In this case, the operator will start to orchestrate the cluster to take the
required backup on an object store, using <code>barman-cloud-backup</code>. You can check
the backup status using the plain <code>kubectl describe backup <name></code> command:</p>
<pre><code class="language-text">Name: backup-example
Namespace: default
Labels: <none>
Annotations: API Version: postgresql.cnpg.io/v1
Kind: Backup
Metadata:
Creation Timestamp: 2020-10-26T13:57:40Z
Self Link: /apis/postgresql.cnpg.io/v1/namespaces/default/backups/backup-example
UID: ad5f855c-2ffd-454a-a157-900d5f1f6584
Spec:
Cluster:
Name: pg-backup
Status:
Phase: running
Started At: 2020-10-26T13:57:40Z
Events: <none>
</code></pre>
<p>When the backup has been completed, the phase will be <code>completed</code>
like in the following example:</p>
<pre><code class="language-text">Name: backup-example
Namespace: default
Labels: <none>
Annotations: API Version: postgresql.cnpg.io/v1
Kind: Backup
Metadata:
Creation Timestamp: 2020-10-26T13:57:40Z
Self Link: /apis/postgresql.cnpg.io/v1/namespaces/default/backups/backup-example
UID: ad5f855c-2ffd-454a-a157-900d5f1f6584
Spec:
Cluster:
Name: pg-backup
Status:
Backup Id: 20201026T135740
Destination Path: s3://backups/
Endpoint URL: http://minio:9000
Phase: completed
s3Credentials:
Access Key Id:
Key: ACCESS_KEY_ID
Name: minio
Secret Access Key:
Key: ACCESS_SECRET_KEY
Name: minio
Server Name: pg-backup
Started At: 2020-10-26T13:57:40Z
Stopped At: 2020-10-26T13:57:44Z
Events: <none>
</code></pre>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>This feature will not backup the secrets for the superuser and the
application user. The secrets are supposed to be backed up as part of
the standard backup procedures for the Kubernetes cluster.</p>
</div>
<h2 id="backup-from-a-standby">Backup from a standby</h2>
<!-- TODO: Adapt for Volume Snapshots -->
<p>Taking a base backup requires to scrape the whole data content of the
PostgreSQL instance on disk, possibly resulting in I/O contention with the
actual workload of the database.</p>
<p>For this reason, CloudNativePG allows you to take advantage of a
feature which is directly available in PostgreSQL: <strong>backup from a standby</strong>.</p>
<p>By default, backups will run on the most aligned replica of a <code>Cluster</code>. If
no replicas are available, backups will run on the primary instance.</p>
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Although the standby might not always be up to date with the primary,
in the time continuum from the first available backup to the last
archived WAL this is normally irrelevant. The base backup indeed
represents the starting point from which to begin a recovery operation,
including PITR. Similarly to what happens with
<a href="https://www.postgresql.org/docs/current/app-pgbasebackup.html"><code>pg_basebackup</code></a>,
when backing up from an online standby we do not force a switch of the WAL on the
primary. This might produce unexpected results in the short term (before
<code>archive_timeout</code> kicks in) in deployments with low write activity.</p>
</div>
<p>If you prefer to always run backups on the primary, you can set the backup
target to <code>primary</code> as outlined in the example below:</p>
<pre><code class="language-yaml">apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
[...]
spec:
backup:
target: "primary"
</code></pre>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Beware of setting the target to primary when performing a cold backup
with volume snapshots, as this will shut down the primary for
the time needed to take the snapshot, impacting write operations.
This also applies to taking a cold backup in a single-instance cluster, even
if you did not explicitly set the primary as the target.</p>
</div>
<p>When the backup target is set to <code>prefer-standby</code>, such policy will ensure
backups are run on the most up-to-date available secondary instance, or if no
other instance is available, on the primary instance.</p>
<p>By default, when not otherwise specified, target is automatically set to take
backups from a standby.</p>
<p>The backup target specified in the <code>Cluster</code> can be overridden in the <code>Backup</code>
and <code>ScheduledBackup</code> types, like in the following example:</p>
<pre><code class="language-yaml">apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
[...]
spec:
cluster:
name: [...]
target: "primary"
</code></pre>
<p>In the previous example, CloudNativePG will invariably choose the primary
instance even if the <code>Cluster</code> is set to prefer replicas.</p>
</div>
</div><footer>
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
<a href="../logical_replication/" class="btn btn-neutral float-left" title="Logical Replication"><span class="icon icon-circle-arrow-left"></span> Previous</a>
<a href="../backup_barmanobjectstore/" class="btn btn-neutral float-right" title="Backup on object stores">Next <span class="icon icon-circle-arrow-right"></span></a>
</div>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
<p>Copyright © CloudNativePG a Series of LF Projects, LLC</p>
</div>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" aria-label="Versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span><a href="../logical_replication/" style="color: #fcfcfc">« Previous</a></span>
<span><a href="../backup_barmanobjectstore/" style="color: #fcfcfc">Next »</a></span>
</span>
</div>
<script src="../js/jquery-3.6.0.min.js"></script>
<script>var base_url = "..";</script>
<script src="../js/theme_extra.js"></script>
<script src="../js/theme.js"></script>
<script src="../search/main.js"></script>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>