Skip to content

Commit 392dc34

Browse files
committed
pgbackrest: stanza-create
issue: vitabaks#143 also added an example of pgbackrest_conf parameters for configuring local backup.
1 parent 89deb7a commit 392dc34

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

deploy_pgcluster.yml

+3
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@
229229

230230
- role: patroni
231231

232+
- role: pgbackrest/stanza-create
233+
when: pgbackrest_install|bool
234+
232235
- role: vip-manager
233236
when: not with_haproxy_load_balancing|bool and
234237
(cluster_vip is defined and cluster_vip | length > 0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
3+
- name: Get repo1-path value
4+
set_fact:
5+
repo1_path: "{{ pgbackrest_conf['global'] | selectattr('option', 'equalto', 'repo1-path') | map(attribute='value') | list | first }}"
6+
tags: pgbackrest, pgbackrest_stanza_create
7+
8+
# Create a stanza locally (if "pgbackrest_repo_host" is not set)
9+
- block:
10+
- name: "Make sure the {{ repo1_path }} directory exists"
11+
file:
12+
path: "{{ repo1_path }}"
13+
state: directory
14+
owner: postgres
15+
group: postgres
16+
mode: 0755
17+
when: repo1_path | length > 0
18+
19+
- name: Create stanza "{{ pgbackrest_stanza }}"
20+
become: true
21+
become_user: postgres
22+
command: "pgbackrest --stanza={{ pgbackrest_stanza }} --no-online stanza-create"
23+
register: stanza_create_result
24+
changed_when:
25+
- stanza_create_result.rc == 0
26+
- stanza_create_result.stdout is not search("already exists")
27+
when:
28+
- pgbackrest_repo_host | length < 1
29+
- "'postgres_cluster' in group_names"
30+
tags: pgbackrest, pgbackrest_stanza_create
31+
32+
# Create a stanza on the dedicated repository host
33+
- block:
34+
- name: "Make sure the {{ repo1_path }} directory exists"
35+
file:
36+
path: "{{ repo1_path }}"
37+
state: directory
38+
owner: "{{ pgbackrest_repo_user }}"
39+
group: "{{ pgbackrest_repo_user }}"
40+
mode: 0755
41+
when: repo1_path | length > 0
42+
43+
- name: Create stanza "{{ pgbackrest_stanza }}"
44+
become: true
45+
become_user: "{{ pgbackrest_repo_user }}"
46+
delegate_to: "{{ groups['pgbackret'][0] }}"
47+
run_once: true
48+
command: "pgbackrest --stanza={{ pgbackrest_stanza }} stanza-create"
49+
register: stanza_create_result
50+
changed_when:
51+
- stanza_create_result.rc == 0
52+
- stanza_create_result.stdout is not search("already exists")
53+
when:
54+
- pgbackrest_repo_host | length > 0
55+
- "'pgbackrest' in group_names"
56+
tags: pgbackrest, pgbackrest_stanza_create
57+
58+
...

tags.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
- - pgbackrest_install
9595
- - pgbackrest_conf
9696
- - pgbackrest_ssh_keys
97-
- - pgbackrest_cron
97+
- - pgbackrest_stanza_create
9898
- pg_probackup
9999
- - pg_probackup_repo
100100
- - pg_probackup_install

vars/main.yml

+14-6
Original file line numberDiff line numberDiff line change
@@ -405,24 +405,32 @@ wal_g_patroni_cluster_bootstrap_command: "wal-g backup-fetch {{ postgresql_data_
405405
# pgBackRest
406406
pgbackrest_install: false # or 'true'
407407
pgbackrest_install_from_pgdg_repo: true # or 'false'
408-
pgbackrest_stanza: "stanza_name" # specify your --stanza
408+
pgbackrest_stanza: "{{ patroni_cluster_name }}" # specify your --stanza
409409
pgbackrest_repo_type: "posix" # or "s3", "gcs", "azure"
410-
pgbackrest_repo_host: "10.128.64.50" # dedicated repository host (if repo_type: "posix")
411-
pgbackrest_repo_user: "postgres" # if "repo_host" is set
410+
pgbackrest_repo_host: "" # dedicated repository host
411+
pgbackrest_repo_user: "" # if "repo_host" is set
412412
pgbackrest_conf_file: "/etc/pgbackrest/pgbackrest.conf"
413413
# see more options https://pgbackrest.org/configuration.html
414414
pgbackrest_conf:
415415
global: # [global] section
416416
- { option: "log-level-file", value: "detail" }
417417
- { option: "log-path", value: "/var/log/pgbackrest" }
418+
# - { option: "repo1-host", value: "{{ pgbackrest_repo_host }}" }
419+
# - { option: "repo1-host-user", value: "{{ pgbackrest_repo_user }}" }
418420
- { option: "repo1-type", value: "{{ pgbackrest_repo_type |lower }}" }
419-
- { option: "repo1-host", value: "{{ pgbackrest_repo_host }}" }
420-
- { option: "repo1-host-user", value: "{{ pgbackrest_repo_user }}" }
421+
- { option: "repo1-path", value: "/var/lib/pgbackrest" }
422+
- { option: "repo1-retention-full", value: "4" }
423+
- { option: "start-fast", value: "y" }
424+
- { option: "delta", value: "y" }
425+
- { option: "stop-auto", value: "y" }
426+
- { option: "resume", value: "n" }
427+
- { option: "link-all", value: "y" }
421428
# - { option: "", value: "" }
422429
stanza: # [stanza_name] section
423430
- { option: "pg1-path", value: "{{ postgresql_data_dir }}" }
424-
- { option: "process-max", value: "2" }
425431
- { option: "recovery-option", value: "recovery_target_action=promote" }
432+
- { option: "log-level-console", value: "info" }
433+
- { option: "process-max", value: "4" }
426434
# - { option: "", value: "" }
427435
pgbackrest_patroni_cluster_restore_command:
428436
'/usr/bin/pgbackrest --stanza={{ pgbackrest_stanza }} --delta restore' # restore from latest backup

0 commit comments

Comments
 (0)