Closed vitabaks closed 1 year ago
# pgBackRest
pgbackrest_install: true
pgbackrest_install_from_pgdg_repo: true
pgbackrest_stanza: "{{ patroni_cluster_name }}"
pgbackrest_repo_type: "posix"
pgbackrest_repo_host: "10.172.0.100" # dedicated repository host
pgbackrest_repo_user: "postgres"
pgbackrest_conf_file: "/etc/pgbackrest/pgbackrest.conf"
pgbackrest_conf:
global: # [global] section
- { option: "log-level-file", value: "detail" }
- { option: "log-path", value: "/var/log/pgbackrest" }
# - { option: "repo1-host", value: "{{ pgbackrest_repo_host }}" }
# - { option: "repo1-host-user", value: "{{ pgbackrest_repo_user }}" }
- { option: "repo1-type", value: "{{ pgbackrest_repo_type |lower }}" }
- { option: "repo1-path", value: "/var/lib/pgbackrest" }
stanza: # [stanza_name] section
- { option: "pg1-path", value: "{{ postgresql_data_dir }}" }
- { option: "recovery-option", value: "recovery_target_action=promote" }
- { option: "log-level-console", value: "info" }
- { option: "process-max", value: "4" }
pgbackrest_server_conf:
global:
- { option: "log-level-file", value: "detail" }
- { option: "log-level-console", value: "info" }
- { option: "log-path", value: "/var/log/pgbackrest" }
- { option: "repo1-type", value: "{{ pgbackrest_repo_type |lower }}" }
- { option: "repo1-path", value: "/var/lib/pgbackrest" }
- { option: "repo1-retention-full", value: "4" }
- { option: "repo1-retention-archive", value: "4" }
- { option: "repo1-bundle", value: "y" }
- { option: "repo1-block", value: "y" }
- { option: "start-fast", value: "y" }
- { option: "stop-auto", value: "y" }
- { option: "resume", value: "n" }
- { option: "link-all", value: "y" }
- { option: "archive-check", value: "y" }
- { option: "archive-copy", value: "n" }
- { option: "backup-standby", value: "y" }
# the stanza section will be generated automatically
we expect automation to specify these parameters for us:
Ansible log
TASK [pre-checks : pgBackRest | Ensure 'repo1-host' and 'repo1-host-user' are set correctly] ***
ok: [10.172.0.20]
ok: [10.172.0.21]
ok: [10.172.0.22]
Check result:
postgres@pgnode01:~$ cat /etc/pgbackrest/pgbackrest.conf
[global]
log-level-file=detail
log-path=/var/log/pgbackrest
repo1-type=posix
repo1-path=/var/lib/pgbackrest
repo1-host=10.172.0.100
repo1-host-user=postgres
[postgres-cluster]
pg1-path=/var/lib/postgresql/15/main
recovery-option=recovery_target_action=promote
log-level-console=info
process-max=4
postgres@pgnode01:~$ pgbackrest info
WARN: configuration file contains invalid option 'include-path'
stanza: postgres-cluster
status: error (no valid backups)
cipher: none
db (current)
wal archive min/max (15): 000000010000000000000001/000000010000000000000004
postgres@pgnode01:~$
postgres@pgnode01:~$ cat /etc/cron.d/pgbackrest
#Ansible: pgBackRest: Full Backup
30 6 * * 0 postgres pgbackrest --type=full --stanza=postgres-cluster backup
#Ansible: pgBackRest: Diff Backup
30 6 * * 1-6 postgres pgbackrest --type=diff --stanza=postgres-cluster backup
postgres@pgnode01:~$
postgres@pgnode01:~$ pgbackrest --type=full --stanza=postgres-cluster backup
WARN: configuration file contains invalid option 'include-path'
2023-07-06 12:14:05.695 P00 INFO: backup command begin 2.46: --archive-check --no-archive-copy --backup-standby --exec-id=8485-5e62611e --log-level-console=info --log-level-file=detail --log-path=/var/log/pgbackrest --pg1-host=10.172.0.20 --pg2-host=10.172.0.21 --pg3-host=10.172.0.22 --pg1-path=/var/lib/postgresql/15/main --pg2-path=/var/lib/postgresql/15/main --pg3-path=/var/lib/postgresql/15/main --pg1-port=5432 --pg2-port=5432 --pg3-port=5432 --repo1-block --repo1-bundle --repo1-path=/var/lib/pgbackrest --repo1-retention-archive=4 --repo1-retention-full=4 --repo1-type=posix --no-resume --stanza=postgres-cluster --start-fast --stop-auto --type=full
2023-07-06 12:14:08.298 P00 INFO: execute non-exclusive backup start: backup begins after the requested immediate checkpoint completes
2023-07-06 12:14:08.704 P00 INFO: backup start archive = 000000010000000000000006, lsn = 0/6000028
2023-07-06 12:14:08.704 P00 INFO: wait for replay on the standby to reach 0/6000028
2023-07-06 12:14:09.008 P00 INFO: replay on the standby reached 0/6000028
2023-07-06 12:14:09.008 P00 INFO: check archive for prior segment 000000010000000000000005
2023-07-06 12:14:11.724 P00 INFO: execute non-exclusive backup stop and wait for all WAL segments to archive
2023-07-06 12:14:11.925 P00 INFO: backup stop archive = 000000010000000000000006, lsn = 0/6000138
2023-07-06 12:14:11.931 P00 INFO: check archive for segment(s) 000000010000000000000006:000000010000000000000006
2023-07-06 12:14:12.233 P00 INFO: new backup label = 20230706-121408F
2023-07-06 12:14:12.272 P00 INFO: full backup size = 22.2MB, file total = 970
2023-07-06 12:14:12.272 P00 INFO: backup command end: completed successfully (6579ms)
2023-07-06 12:14:12.272 P00 INFO: expire command begin 2.46: --exec-id=8485-5e62611e --log-level-console=info --log-level-file=detail --log-path=/var/log/pgbackrest --repo1-path=/var/lib/pgbackrest --repo1-retention-archive=4 --repo1-retention-full=4 --repo1-type=posix --stanza=postgres-cluster
2023-07-06 12:14:12.379 P00 INFO: expire command end: completed successfully (107ms)
postgres@pgnode01:~$ pgbackrest info
WARN: configuration file contains invalid option 'include-path'
stanza: postgres-cluster
status: ok
cipher: none
db (current)
wal archive min/max (15): 000000010000000000000001/000000010000000000000006
full backup: 20230706-121408F
timestamp start/stop: 2023-07-06 12:14:08 / 2023-07-06 12:14:11
wal start/stop: 000000010000000000000006 / 000000010000000000000006
database size: 22.2MB, database backup size: 22.2MB
repo1: backup size: 3MB
postgres@pgnode01:~$
passed
This PR adds a check for the existence of the 'repo1-host' and 'repo1-host-user' options when 'pgbackrest_repo_host' is defined. If these options are not set, the configuration is adjusted automatically. This is crucial for the proper functioning of pgBackRest when using a dedicated backup server.
Issue: https://github.com/vitabaks/postgresql_cluster/issues/393