-
Notifications
You must be signed in to change notification settings - Fork 31
/
pitrery.1
1184 lines (963 loc) · 39.8 KB
/
pitrery.1
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Hey, EMACS: -*- nroff -*-
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH PITRERY 1 "February 3, 2021"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
.\" .nh disable hyphenation
.\" .hy enable hyphenation
.\" .ad l left justify
.\" .ad b justify to both left and right margins
.\" .nf disable filling
.\" .fi enable filling
.\" .br insert line break
.\" .sp <n> insert n+1 empty lines
.\" for manpage-specific macros, see man(7)
.SH NAME
pitrery \- Manage point-in-time recovery for PostgreSQL
.SH SYNOPSIS
.B pitrery
.RI [ options ]
.I action
.RI [ args ]
The command needs to be written in a specific order: pitrery options should be
stated first, and the action options should be stated after the action
keywords. This is important since some switches are the same in both lists of
options, but with different meanings.
.SH DESCRIPTION
The purpose of \fBpitrery\fP is to make it easy to manage the archiving of
PostgreSQL WAL segments and automate the tasks of taking base backups and
preparing a point in time recovery operation if or when that is needed.
The \fBpitrery\fP script itself provides six archive maintenance actions,
.BR backup ", " restore ", " purge ", " list ", " check ", and " configure ,
which create a new base backup, prepare the necessary files for
initiating a recovery, clean up old base backup and WAL segments that
are no longer wanted, display the available base backups, and check
and create the configuration, respectively. It is designed to be run
on the same machine as the PostgreSQL cluster, but the base backups
and WAL segments that it operates on can be archived either locally or
on a remote server using an SSH connection.
The \fBpitrery\fP package also provides two helper scripts,
\fBarchive_wal\fP(1) and \fBrestore_wal\fP(1), which can help with the
task of managing the WAL segments that accumulate between base backups,
allowing them to be compressed and/or stored on remote host away from the
database server. It is not required to use these two scripts to use
\fBpitrery\fP, but similar functionality to copy WAL segments to an archive
space and retrieve them on demand, will need to be provided by some other
means if they are not. They can also be called from other scripts if you
require additional functionality that they don't provide. The main advantage
they offer is keeping all needed configuration for backup and restore tasks
coherently in a single location.
.SH OPTIONS
The following options are available:
.TP
.BI "\-f, \-c " conf
Use option settings from the specified configuration file instead of the
default \fIpitrery.conf\fP file. This may be a full path to the file to use,
or the name of a configuration file in \fI/etc/pitrery\fP.
.TP
.B \-l
List available configuration files in the default directory.
.TP
.B \-V
Display the \fBpitrery\fP version and exit.
.TP
.B \-?
Output the brief help summarising the above options.
.SH ACTIONS
Each of the actions also has its own individual set of options, which must
be passed after the action name.
.SS list
The \fBlist\fP action is used to obtain information about the available base
backups which can be used to begin a recovery operation.
.TP 4
.B SYNOPSIS
.B pitrery
.RI [ options ]
.B list
.RI [ list-options ]
.RI [ [[user@]host:]/path/to/backups ]
.TP 4
.B LIST-OPTIONS
The following options are available for the \fBlist\fP action:
.RS
.TP
.B \-j
Display verbose details in \fBJSON\fP format.
.TP
.B \-v
Display verbose details about the listed base backups.
.TP
.B \-?
Output the brief help summarising the \fBlist\fP options.
.TP
.I [[user@]host:]/path/to/backups
The path to the directory storing the backups. If a host name is
provided, it is used to login to a remote archive with
\fBssh\fP(1). When the host is not given, the lookup is local.
.RE
.SS backup
The \fBbackup\fP action is used to create a new base backup of the present
state of a PostgreSQL cluster. This provides a starting point which WAL
segments can be replayed on top of, so that point in time recovery may be done
for any time after the base backup was completed and for which there is a
sequence of archived WAL segment files up to the desired recovery time.
This must be run on the same machine as the cluster that is to be backed up,
though the base backup may be pushed to a remote machine for storage.
.TP 4
.B SYNOPSIS
.B pitrery
.RI [ options ]
.B backup
.RI [ backup-options ]
.RI [ hostname ]
.TP 4
.B BACKUP-OPTIONS
The following options are available for the \fBbackup\fP action:
.RS
.TP
.BI "\-D " dir
The \fBPGDATA\fP path of the cluster to back up on the local machine. This
will override the \fBPGDATA\fP option from the configuration file.
.TP
.BI "\-s " mode
The storage mode to use for the base backup. The \fImode\fP may be \fBtar\fP
or \fBrsync\fP. This will override the \fBSTORAGE\fP option from the
configuration file.
Using \fBrsync\fP will attempt to hardlink any files that have not changed
since the last base backup was taken. Whether this will actually use less
disk space than a compressed tarball will depend on the size of your cluster
and its pattern of use. It will only try to do this to the most recent base
backup, so it will be equivalent to a plain copy of the \fBPGDATA\fP directory
if the previous backup was not also taken with the rsync method.
.TP
.BI "\-c " compress_bin
The command to use for compressing a base backup taken with the \fBtar\fP
mode. This will override the \fBBACKUP_COMPRESS_BIN\fP option from the
configuration file.
.TP
.BI "\-e " compress_suffix
The suffix to add to a compressed base backup taken with the \fBtar\fP
mode. This will override the \fBBACKUP_COMPRESS_SUFFIX\fP option from the
configuration file.
.TP
.B \-E
Encrypt the file using GnuPG. The list of recipients must given using
the \fB-r\fP option. When this option is used, \fBtar\fP storage method
must be used. This will override the \fBBACKUP_ENCRYPT\fP option from the
configuration file.
.TP
.BI "\-r " keys:...
List of public keys for GPG encryption, it is a colon separeted list
of USER-ID recognized by the \fB--recipient\fP option of \fBgpg\fP(1).
This will override the \fBGPG_ENCRYPT_KEYS\fP option from the
configuration file.
.TP
.B \-t
When naming the backup directory from the stop time of the backup, use
ISO 8601 format. This will override the \fBUSE_ISO8601_TIMESTAMPS\fP
option from the configuration file.
.TP
.B \-T
Timestamp the log messages. This will override the \fBLOG_TIMESTAMP\fP option
from the configuration file (forcing it to be "yes").
.TP
.BI "\-P " psql
The \fBpsql\fP(1) command to use to run SQL statements on the database cluster.
This will override the \fBPGPSQL\fP option from the configuration file.
You should avoid using this to pass extra options to \fBpsql\fP (and instead
use the options below for that). It is mostly for overriding the default
\fBpsql\fP(1) that would otherwise be found in the system \fBPATH\fP.
.TP
.BI "\-h " host
The host address to use to query the database cluster. This may be an IP
address for TCP connection or the path to a unix socket directory for a
local peer connection. It is passed as the \fB\-\-host\fP option to
\fBpsql\fP(1). This will override the \fBPGHOST\fP option from the
configuration file.
.TP
.BI "\-p " port
The port to use to query the database cluster. It is passed as the
\fB\-\-port\fP option to \fBpsql\fP(1). This will override the \fBPGPORT\fP
option from the configuration file.
.TP
.BI "\-U " name
The user name to use to query the database cluster. It is passed as
the \fB\-\-username\fP option to \fBpsql\fP(1). This will override
the \fBPGUSER\fP option from the configuration file. This role must
be a superuser or have the replication attribute to execute
\fBpg_start_backup\fP() on the cluster.
.TP
.BI "\-d " database
The database to use when querying the cluster. It is passed as the
\fB\-\-dbname\fP option to \fBpsql\fP(1). This will override the
\fBPGDATABASE\fP option from the configuration file. Note that this does not
influence what is included in the base backup, point in time recovery is
always for the entire cluster.
.TP
.B \-?
Output the brief help summarising the \fBbackup\fP options.
.TP
.I [[user@]host:]/path/to/backups
The path to the directory storing the backups. If a host name is
provided, it is used to login to a remote archive with
\fBssh\fP(1). When the host is not given, the lookup is local.
.RE
.SS restore
The \fBrestore\fP action is used to select and retrieve the files needed to
begin recovery of a cluster to a particular state, either to the most recently
archived state or a point in time between the oldest base backup and the most
recent WAL segment that is available to be replayed.
It will create a new \fBPGDATA\fP tree from the archived data with a minimal
\fIrecovery.conf\fP ready to begin recovery operations. It may also place a
copy of the \fBpostgres\fP configuration files from the time that the base
backup was made in \fIPGDATA/restored_config_files\fP if they did not exist in
the \fBPGDATA\fP directory at that time.
It will create a new \fBPGDATA\fP tree from the archived data with a minimal set
of recovery configuration keys in \fIpostgresql.conf\fP with a "*.signal" file
(PG>=12) or a minimal \fIrecovery.conf\fP (PG<=11) ready to begin
recovery operations.
It may also place a copy of the \fBpostgres\fP configuration files from the time
that the base backup was made in \fIPGDATA/restored_config_files\fP if they did
not exist in the \fBPGDATA\fP directory at that time.
.TP 4
.B SYNOPSIS
.B pitrery
.RI [ options ]
.B restore
.RI [ restore-options ]
.RI [ [[user@]host:]/path/to/backups ]
.TP 4
.B RESTORE-OPTIONS
The following options are available for the \fBrestore\fP action:
.RS
.TP
.BI "\-D " dir
The \fBPGDATA\fP path of the cluster on the local machine, that is to be
repopulated ready for recovery. This directory will be created if it does not
already exist, but must be empty if it does (unless the \fB\-R\fP option is
used to force overwriting it). This will override the \fBPGDATA\fP option
from the configuration file.
.TP
.BI "\-x " dir
The directory where WAL segment files will be placed if you wish to
keep those outside of the \fBPGDATA\fP tree. If specified this will
create \fIPGDATA/pg_wal\fP (or \fIPGDATA/pg_xlog\fP as of PostgreSQL
9.6 or less) as a symlink to \fIdir\fP rather than as a directory in
its own right. This will override the \fBPGWAL\fP option from the
configuration file.
.TP
.BI "\-d " date
The initial \fIrecovery_target_time\fP to place in
\fIpostgresql.conf\fP (PG>=12) or in \fIrecovery.conf\fP (PG<=11) which is
the first point in time that replaying the WAL segment files will pause at.
The canonical form of the \fIdate\fP string is:
.nh
.nf
\fIYYYY\-MM\-DD HH:MM:SS\fP [\fI(+|\-)XXXX\fP]
.fi
.hy
where \fIXXXX\fP is the optional timezone offset, however the \fIdate\fP may be
specified here in any form that \fBdate\fP(1) on your system will recognise,
including the relative date strings such as '1\ hour\ ago' which GNU \fBdate\fP
accepts.
This cannot be earlier than the oldest archived base backup, and can only be
restored to if all the WAL segment files from the nearest base backup to that
time are available and uncorrupted.
.TP
.BI "\-O " user
The user which should be set as the owner of the restored files if
\fBpitrery\fP is run as root. This will override the \fBPGOWNER\fP option
from the configuration file.
.TP
.BI "\-t " tblspc:dir
Change the target directory of tablespace \fItblspc\fP to \fIdir\fP. This
option may be used as many times as required if multiple tablespaces need to
to relocated.
.TP
.B \-n
Do a dry run of the restore, showing information about what it would do but
stopping before actually making any changes to \fBPGDATA\fP.
.TP
.B \-R
Overwrite destination directories. By default the \fBrecovery\fP action will
refuse to proceed if any of the destination directories are not empty. Even
with this option it will still refuse to proceed if a \fIpostmaster.pid\fP
file is present, since attempting a restore into directory that a running
\fBpostgres\fP instance is using is likely to Go Very Badly.
.TP
.BI "\-c " uncompress_bin
The command to use for uncompressing a base backup taken with the \fBtar\fP
mode. This will override \fBBACKUP_UNCOMPRESS_BIN\fP option from the
configuration file.
.TP
.BI "\-e " compress_suffix
The file suffix to expect (e.g., gz, bz2, xz) for a compressed base backup
taken with the \fBtar\fP mode. This will override the
\fBBACKUP_COMPRESS_SUFFIX\fP option from the configuration file.
.TP
.BI "\-m " restore_mode
Restore either in \fBstandby\fP or \fBrecovery\fP mode, which will create
respectivily a \fIstandby.signal\fP or \fPrecovery.signal\fP file. This will
override the \fBRESTORE_MODE\fP option from the configuration file.
.TP
.BI "\-r " command
The command line to use in the \fIrestore_command\fP option written in the
\fIpostgresql.conf\fP file (PG>=12) or of the generated \fIrecovery.conf\fP
file (PG<=11). This will override the \fBRESTORE_COMMAND\fP option from the
configuration file. The default is to use \fBrestore_wal\fP(1).
.TP
.BI "\-C " config
The configuration file to use for \fBrestore_wal\fP(1) if
\fBRESTORE_COMMAND\fP was not explicitly specified on either the command line
or in the configuration file.
.TP
.BI "\-y " command
The command to use to set the \fIrecover_end_command\fP option written in the
\fIpostgresql.conf\fP file (PG>=12) or of the generated \fIrecovery.conf\fP
file (PG<=11). This will override the \fBRECOVERY_END_COMMAND\fP option from
the configuration file.
.TP
.B \-T
Timestamp the log messages. This will override the \fBLOG_TIMESTAMP\fP option
from the configuration file (forcing it to be "yes").
.TP
.B \-?
Output the brief help summarising the \fBrestore\fP options.
.TP
.I [[user@]host:]/path/to/backups
The path to the directory storing the backups. If a host name is
provided, it is used to login to a remote archive with
\fBssh\fP(1). When the host is not given, the lookup is local.
.RE
.SS purge
The \fBpurge\fP action is used to perform an orderly expiry of old archived
data that you no longer wish to retain. It will remove both base backups and
any archived WAL segment files that would no longer be usable with just the
base backups that remain. (It will not remove any archived WAL segment files
if there are no base backups at all though).
Expiry of backups can be based on the maximum number of them that you wish to
keep, the maximum age of them that you wish to keep, or a combination of both
where they will only be removed if they exceed both the age limit and the
limit on the number of backups to retain. This can avoid accidentally removing
all the existing backups if all of them are older than the maximum age.
.TP 4
.B SYNOPSIS
.B pitrery
.RI [ options ]
.B purge
.RI [ purge-options ]
.RI [ [[user@]host:]/path/to/backups ]
.TP 4
.B PURGE-OPTIONS
The following options are available for the \fBpurge\fP action:
.RS
.TP
.BI "\-a " [[user@]host:]/dir
The directory on the (local or remote) host where WAL segment files will be
stored. This will override the \fBARCHIVE_DIR\fP option from the
configuration file. When the host name is omited, the archiving is local.
.TP
.BI "\-m " count
Keep (at least) this number of base backups. The \fBpurge\fP action will
never reduce the number of backups to less than this count, regardless of
their age. This will override the \fBPURGE_KEEP_COUNT\fP option from the
configuration file.
.TP
.BI "\-d " days
Keep all base backups dating back to (at least) this number of days. The
\fBpurge\fP action will never remove backups that are more recent than this,
regardless of the number of them which remain. This will override the
\fBPURGE_OLDER_THAN\fP option from the configuration file.
.TP
.B \-N
Do a dry run of the purge, showing information about what it would remove but
stopping before actually making any changes to the archived files.
.TP
.B \-T
Timestamp the log messages. This will override the \fBLOG_TIMESTAMP\fP option
from the configuration file (forcing it to be "yes").
.TP
.B \-?
Output the brief help summarising the \fBpurge\fP options.
.TP
.I [[user@]host:]/path/to/backups
The path to the directory storing the backups. If a host name is
provided, it is used to login to a remote archive with
\fBssh\fP(1). When the host is not given, the lookup is local.
.RE
.SS configure
The \fBconfigure\fP action creates a configuration file. It needs a
destination of the form \fB[[user@]host:]/path\fP to know where backups
shall be stored. If a host is not provided, the backup is considered
local.
.TP 4
.B SYNOPSIS
.B pitrery
.RI [ options ]
.B configure
.RI [ configure-options ]
.RI destination
.TP 4
.B CONFIGURE-OPTIONS
The following options are available for the \fBconfigure\fP action:
.RS
.TP
.BI "\-o " config_file
The configuration file to create. If it is not a path, the file is
created in the default configuration directory.
.TP
.B \-C
Do not connect to check the configuration of PostgreSQL and output the
parameters to modify in postgresql.conf for WAL archiving.
.TP
.B \-f
If the output configuration file already exists, overwrite it.
.TP
.BI "\-s " mode
The storage mode to use for the base backup. The \fImode\fP may be
\fBtar\fP or \fBrsync\fP. This will configure the \fBSTORAGE\fP
option in the configuration file.
.TP
.BI "\-m " count
Keep (at least) this number of base backups. The \fBpurge\fP action
will never reduce the number of backups to less than this count,
regardless of their age. This will configure the
\fBPURGE_KEEP_COUNT\fP option in the configuration file. Defaults to
2.
.TP
.BI "\-g " days
Keep all base backups dating back to (at least) this number of days. The
\fBpurge\fP action will never remove backups that are more recent than this,
regardless of the number of them which remain. This will configure the
\fBPURGE_OLDER_THAN\fP option in the configuration file.
.TP
.BI "\-D " dir
The \fBPGDATA\fP path of the cluster to back up on the local machine.
This will configure the \fBPGDATA\fP option from the configuration
file. When \-c is given, the configure action gets the the PGDATA
from the \fBdata_directory\fP setting of the cluster, \-D overrides
this, and it is mandatory when not checking the cluster. This will
configure the \fBPGDATA\fP option in the configuration file.
.TP
.BI "\-a " [[user@]host:]/dir
Place to store WAL files, used by \fBarchive_wal\fP(1) and
\fBrestore_wal\fP(1). This will configure \fBARCHIVE_USER\fP,
\fBARCHIVE_HOST\fP and \fBARCHIVE_DIR\fP. When a host is missing,
archiving is considered local. When not used, the configuration falls
back to the destination provided for backups, and \fBARCHIVE_DIR\fP is
configured to "$BACKUP_DIR/archived_wal"
.TP
.B \-E
Encrypt the backup's files and the archived WAL files using GnuPG. The list of
recipients must given using the \fB-r\fP option. When this option is used,
\fBtar\fP storage method must be used for base backups. This will override the
\fBBACKUP_ENCRYPT\fP and \fBARCHIVE_ENCRYPT\fP options from the
configuration file.
.TP
.BI "\-r " keys:...
List of public keys for GPG encryption, it is a colon separeted list
of USER-ID recognized by the \fB--recipient\fP option of \fBgpg\fP(1).
This will override the \fBGPG_ENCRYPT_KEYS\fP option from the
configuration file.
.TP
.BI "\-P " psql
The \fBpsql\fP(1) command to use to run SQL statements on the database cluster.
This will configure the \fBPGPSQL\fP option in the configuration file.
You should avoid using this to pass extra options to \fBpsql\fP (and instead
use the options below for that). It is mostly for overriding the default
\fBpsql\fP(1) that would otherwise be found in the system \fBPATH\fP.
.TP
.BI "\-h " host
The host address to use to query the database cluster. This may be an IP
address for TCP connection or the path to a unix socket directory for a
local peer connection. It is passed as the \fB\-\-host\fP option to
\fBpsql\fP(1). This will configure the \fBPGHOST\fP option in the
configuration file.
.TP
.BI "\-p " port
The port to use to query the database cluster. It is passed as the
\fB\-\-port\fP option to \fBpsql\fP(1). This will configure the \fBPGPORT\fP
option in the configuration file.
.TP
.BI "\-U " name
The user name to use to query the database cluster. It is passed as
the \fB\-\-username\fP option to \fBpsql\fP(1). This will configure
the \fBPGUSER\fP option in the configuration file. This role must
be a superuser or have the replication attribute to execute
\fBpg_start_backup\fP() on the cluster.
.TP
.BI "\-d " database
The database to use when querying the cluster. It is passed as the
\fB\-\-dbname\fP option to \fBpsql\fP(1). This will configure the
\fBPGDATABASE\fP option in the configuration file. Note that this does not
influence what is included in the base backup, point in time recovery is
always for the entire cluster.
.TP
.B \-?
Output the brief help summarising the \fBconfigure\fP options.
.TP
.I [[user@]host:]/path/to/backups
Place where to store the backups. When host is given, backup is done
over SSH, otherwise it is considered local. This will configure the
\fBBACKUP_USER\fP, \fBBACKUP_HOST\fP and \fBBACKUP_DIR\fP options in
the configuration file.
.RE
.SS check
The \fBcheck\fP action is used to check if a configuration file is
correct or backup policy and archived WAL files. The action tests if
the backup directory is reachable, if WAL archiving can be done with
\fBarchive_wal\fP(1), if PostgreSQL is up and properly configured for
PITR and if the current user can actually backup the files.
.TP 4
.B SYNOPSIS
.B pitrery
.RI [ options ]
.B check
.RI [ check-options ]
.RI [ [[user@]host:]/path/to/backups ]
.TP 4
.B CHECK-OPTIONS
The following options are available for the \fBcheck\fP action:
.RS
.TP
.BI "\-C " config_file
The configuration file to check. It can also be provided using the \-c
option of \fBpitrery\fP.
.TP
.B \-B
Check backups instead of the configuration.
.TP
.BI "\-m " count
When checking backups, fail when the number of backups is less than
count. If not set, fallback to the value of \fBPURGE_KEEP_COUNT\fP.
.TP
.BI "\-g " age
When checking backups, Fail when the newest backup is older than age
in days. A time unit can specified: the supported units are "s"
(seconds), "min" (minutes), "h" (hours) and "d" (days). If not set,
fallback to the value of \fBPURGE_OLDER_THAN\fP.
.TP
.B \-A
Check archived WAL files instead of the configuration.
.TP
.BI "\-c " uncompress_bin
The command to use for uncompressing WAL segment files. This will override
\fBARCHIVE_UNCOMPRESS_BIN\fP option from the configuration file.
.TP
.BI "\-a " [[user@]host:]/dir
Place where WAL files are stored.
.TP
.B \-n
When checking backups, behave like a Nagios plugin.
.TP
.B \-?
Output the brief help summarising the \fBcheck\fP options.
.TP
.I [[user@]host:]/path/to/backups
The path to the directory storing the backups. If a host name is
provided, it is used to login to a remote archive with
\fBssh\fP(1). When the host is not given, the lookup is local.
.RE
.SH CONFIGURATION
The following options may be configured persistently in one or more
configuration files. The configuration file will be sourced as a
\fBbash\fP(1) shell snippet, so it must contain only valid shell syntax,
though it should usually only contain assignments to the following variables:
.SS Cluster configuration
These variables specify the location and manner of accessing the PostgreSQL
cluster for \fBbackup\fP and \fBrestore\fP operations.
.TP
.B PGDATA
The path to the PostgreSQL cluster data directory. This must be set (or
passed on the command line) for \fBbackup\fP and \fBrestore\fP operations.
.TP
.B PGPSQL
The \fBpsql\fP(1) program to use when querying the database for \fBbackup\fP
operations. If not set, then the \fBpsql\fP binary found in the system
\fBPATH\fP will be used.
You should avoid using this to pass extra options to \fBpsql\fP (and instead
use the options below for that). It is mostly for overriding the default
\fBpsql\fP(1) that would otherwise be found in the system \fBPATH\fP.
.TP
.B PGHOST
The host address to use to query the database cluster. This may be an IP
address for TCP connection or the path to a unix socket directory for a
local peer connection. It is passed as the \fB\-\-host\fP option to
\fBpsql\fP(1) for \fBbackup\fP operations. If not set the \fBpsql\fP default
will be used.
.TP
.B PGPORT
The port to use to query the database cluster. It is passed as the
\fB\-\-port\fP option to \fBpsql\fP(1) for \fBbackup\fP operations.
If not set the \fBpsql\fP default will be used.
.TP
.B PGUSER
The username to use when querying the database. It is passed as the
\fB\-\-username\fP option to \fBpsql\fP(1) for \fBbackup\fP operations.
This must be a superuser with permission to execute \fBpg_start_backup\fP()
on the cluster. If not set the \fBpsql\fP default will be used.
.TP
.B PGDATABASE
The database to use when querying the cluster. It is passed as the
\fB\-\-dbname\fP option to \fBpsql\fP(1) for \fBbackup\fP operations.
Note that this does not influence what is included in the base backup,
point in time recovery is always for the entire cluster.
If not set the \fBpsql\fP default will be used.
.TP
.B PGOWNER
The user which should be set as the owner of the restored files if
\fBpitrery\ restore\fP is run as root.
.TP
.B PGWAL
The directory where WAL segment files will be placed if you wish to
keep those outside of the \fBPGDATA\fP tree when a \fBrestore\fP
operation is performed. If set this will create \fIPGDATA/pg_wal\fP
(or \fIPGDATA/pg_xlog\fP as of PostgreSQL 9.6 or less) as a symlink
to the specified path rather than as a directory in its own right.
.SS Base backup configuration
These variables specify the location and manner of accessing the base backup
archive for all operations.
.TP
.B BACKUP_DIR
The directory on the (local or remote) host where base backups are stored.
Each backup will have its own subdirectory under this, named with the timestamp
of when the \fBbackup\fP operation completed.
.TP
.B BACKUP_HOST
The target host where remote backups will be stored. The user running
\fBpitrery\fP must be able to \fBssh\fP(1) to this host and run commands in
the remote shell. Typically this means that either a passwordless \fBssh\fP
key must be available, or an agent must be active to permit this access.
If left empty, backups are local.
.TP
.B BACKUP_USER
The username to use for \fBssh\fP(1) access to the remote backup storage.
If not set, the \fBssh\fP default will be used (either taking the user from
the \fBssh\fP configuration for the target host, or the user that is running
the command).
.TP
.B STORAGE
The base backup storage method to use. The \fBtar\fP method creates one
compressed tarball for \fBPGDATA\fP and each tablespace. The \fBrsync\fP
method will attempt to optimise the amount of data transferred and the amount
of disk space used by doing a differential backup, hardlinking files that have
not changed to the copies from the previous backup (which must also have been
done with the rsync method for this to work). The disk space used by a highly
compressed tarball may still be less than what is saved by the hardlinks
(depending on the size of your cluster and its use patterns), but rsync is
likely to be able to complete the backup faster with less data transferred.
.TP
.B PRE_BACKUP_COMMAND
An optional user defined command which may be run before a \fBbackup\fP
operation begins. See the \fBBACKUP\ HOOKS\fP section below for more
details.
.TP
.B POST_BACKUP_COMMAND
An optional user defined command which may be run after a \fBbackup\fP
operation us completed. See the \fBBACKUP\ HOOKS\fP section below for more
details.
.SS WAL archiving configuration
These variables are used by the \fBarchive_wal\fP(1) and
\fBrestore_wal\fP(1) scripts and by the \fBpurge\fP action when managing
archived WAL segment files.
.TP
.B ARCHIVE_HOST
The host name for \fBssh\fP(1) login to a remote WAL archive. Leave
it empty to archive on the local host.
.TP
.B ARCHIVE_USER
The user name for \fBssh\fP(1) login to a remote WAL archive.
If not set, the PostgreSQL server process owner is used for
\fBarchive_wal\fP(1) and \fBrestore_wal\fP(1) operations and the
user that run pitrery is used during \fBpurge\fP operations.
.TP
.B ARCHIVE_DIR
The directory where archived WAL segment files will be kept on the (local
or remote) host. If they are kept on the same machine as the \fBBACKUP_HOST\fP
they can be stored near the base backups by setting this to something like:
.nh
.nf
ARCHIVE_DIR="$BACKUP_DIR/archived_wal"
.fi
.hy
.TP
.B ARCHIVE_OVERWRITE
If set to "yes", overwrite destination files if they exist. Since
preventing overwrite adds a performance penalty over SSH, it is set to
"yes" by default.
.TP
.B ARCHIVE_CHECK
If set set to "yes", check the md5 of the archived
file to the md5 of the original WAL file. It is useful when the
storage and the network is not reliable. If overwriting is disabled,
the md5 check enabled and the archive already exists, the archiving
returns success if the md5 check is successful. This option does not
apply on local archiving.
.TP
.B ARCHIVE_FLUSH
If set to "yes", force an immediate flush of the archived file to disk
before returning success. It may slow down the archiving process but
ensure archives are not corrupted in case of a power loss on the
destination.
.TP
.B ARCHIVE_FILE_CHMOD
Configures the permission of the archived file. The value must be in
octal form as understood by \fBchmod\fP(1). It can help with uid/gid
issues on NFS shares used by different hosts, and should not be
necessary in most of the cases.
.SS Compression configuration
These variables are used to configure the compression of the archived WAL
segment files and base backups which use the \fBtar\fP \fBSTORAGE\fP mode.
.TP
.B ARCHIVE_COMPRESS
If set to "yes", compress the archived WAL segment files with
.BR ARCHIVE_COMPRESS_BIN.
.TP
.B ARCHIVE_COMPRESS_BIN
The command line to use to compress archived WAL segment files.
The program used here must support a \fB\-c\fP option to send output to
\fIstdout\fP and read input from \fIstdin\fP (such as
.BR gzip (1),
.BR pigz (1),
.BR bzip2 (1),
.BR pbzip2 (1),
.BR xz (1)
). If not set, the default is to use "gzip \-4".
.TP
.B ARCHIVE_COMPRESS_SUFFIX
The suffix to use for files compressed by \fBARCHIVE_COMPRESS_BIN\fP.
If not set the default is to use "gz".
.TP
.B ARCHIVE_UNCOMPRESS_BIN
The command line to use to decompress archived WAL segment files.
It must take the file to process as its first parameter. If not set, the
default is to use
.BR gunzip (1).
.TP
.B BACKUP_COMPRESS_BIN
The command to use for compressing a base backup taken with the \fBtar\fP
\fBSTORAGE\fP mode. It must be able to take input piped to \fIstdin\fP
and send its output to \fIstdout\fP (such as
.BR gzip (1),
.BR pigz (1),
.BR bzip2 (1),
.BR pbzip2 (1),
.BR xz (1)
). If not set, the default is to use "gzip \-4".
.TP
.B BACKUP_COMPRESS_SUFFIX
The suffix to add to a compressed base backup taken with the \fBtar\fP
\fBSTORAGE\fP mode. If not set the default is to use "gz".
.TP
.B BACKUP_UNCOMPRESS_BIN
The command to use for uncompressing a base backup taken with the \fBtar\fP
\fBSTORAGE\fP mode. It must be able to take the file to process as its first
parameter or input piped to \fIstdin\fP, and support a \fB\-c\fP option to
send output to \fIstdout\fP. If not set, the default is to use
.BR gunzip (1).
.TP
.B USE_ISO8601_TIMESTAMPS
When naming the backup directory from the stop time of the backup, use
ISO 8601 format. Defaults to "no" to keep the backward compatibility,
as mixing formats of backup names would break the sorting of backups on
restore.
.SS Encryption configuration
This variables are used to configure the encryption with GnuPG for the
base backups and the archived WAL files.
.TP
.B BACKUP_ENCRYPT
When set to "yes", use GPG to encrypt the backups.
This only applies to the \fBtar\fP storage, as ciphered files would not be
synchronized by rsync. Note that compression options do not apply when
encrypting files as GPG already compresses the output file using
\fBzlib\fP(3) by default.
.TP
.B ARCHIVE_ENCRYPT
When set to "yes", use GPG to encrypt the archived WAL files.
.TP
.B GPG_ENCRYPT_KEYS
When GPG encryption is enabled, specifies the recipients to encrypt
data to. It can be a colon separated list of recipients. All public
keys must be available in the keyring of the user running the
PostgreSQL cluster and the user who runs pitrery for base backups if
different.
.SS Transfer configuration
This variables are used to configure the behavior of rsync when used
for the base backups.
.TP
.B RSYNC_WHOLEFILE
When set to "yes", disable the rsync on the fly comparison algorithm
by adding --whole-file to the \fBrsync\fP(1) commandline. This may improve
performance over NFS. Default is "no".
.TP
.B RSYNC_BWLIMIT
Limit the bandwidth usage for rsync. This is the value of --bwlimit of
\fBrsync\fP(1). With no unit, it is in kB/s. Leave empty for no limit,
there is no limit by default.
.SS Restore configuration
These variables are used to configure the \fBrestore\fP action operation.
.TP
.B RESTORE_COMMAND
The command line to use in the \fIrestore_command\fP option of the
\fIpostgresql.conf\fP file (PG>=12) or of \fIrecovery.conf\fP file (PG<=11)
that is generated by the \fBrestore\fP action.
This is the command that PostgreSQL will use to attempt to retrieve archived
WAL segment files needed during recovery.
If not set, the default is to use \fBrestore_wal\fP(1).
.TP
.B RESTORE_MODE
Which mode to use when the cluster starts after its restore, "recovery" or
"standby" are the two choices. If not set, the default is to use
\fBrecovery\fP mode.
.TP
.B RECOVERY_END_COMMAND
The command to use to set the \fIrecover_end_command\fP option written in the
\fIpostgresql.conf\fP file (PG>=12) or of the generated \fIrecovery.conf\fP
file (PG<=11) that is generated by the \fBrestore\fP action.
This parameter specifies, in PostgreSQL version 8.4 and greater, a shell
command that will be executed once only at the end of recovery. Any %r is
replaced by the name of the file containing the last valid restart point, like