From 392dc34acf3099458df9e555cc514a1d1f9e1436 Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik Date: Fri, 10 Mar 2023 17:10:09 +0300 Subject: [PATCH] pgbackrest: stanza-create issue: https://github.com/vitabaks/postgresql_cluster/issues/143 also added an example of pgbackrest_conf parameters for configuring local backup. --- deploy_pgcluster.yml | 3 + roles/pgbackrest/stanza-create/tasks/main.yml | 58 +++++++++++++++++++ tags.md | 2 +- vars/main.yml | 20 +++++-- 4 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 roles/pgbackrest/stanza-create/tasks/main.yml diff --git a/deploy_pgcluster.yml b/deploy_pgcluster.yml index 7bc902d77..cb72d82bb 100644 --- a/deploy_pgcluster.yml +++ b/deploy_pgcluster.yml @@ -229,6 +229,9 @@ - role: patroni + - role: pgbackrest/stanza-create + when: pgbackrest_install|bool + - role: vip-manager when: not with_haproxy_load_balancing|bool and (cluster_vip is defined and cluster_vip | length > 0) diff --git a/roles/pgbackrest/stanza-create/tasks/main.yml b/roles/pgbackrest/stanza-create/tasks/main.yml new file mode 100644 index 000000000..da22755ed --- /dev/null +++ b/roles/pgbackrest/stanza-create/tasks/main.yml @@ -0,0 +1,58 @@ +--- + +- name: Get repo1-path value + set_fact: + repo1_path: "{{ pgbackrest_conf['global'] | selectattr('option', 'equalto', 'repo1-path') | map(attribute='value') | list | first }}" + tags: pgbackrest, pgbackrest_stanza_create + +# Create a stanza locally (if "pgbackrest_repo_host" is not set) +- block: + - name: "Make sure the {{ repo1_path }} directory exists" + file: + path: "{{ repo1_path }}" + state: directory + owner: postgres + group: postgres + mode: 0755 + when: repo1_path | length > 0 + + - name: Create stanza "{{ pgbackrest_stanza }}" + become: true + become_user: postgres + command: "pgbackrest --stanza={{ pgbackrest_stanza }} --no-online stanza-create" + register: stanza_create_result + changed_when: + - stanza_create_result.rc == 0 + - stanza_create_result.stdout is not search("already exists") + when: + - pgbackrest_repo_host | length < 1 + - "'postgres_cluster' in group_names" + tags: pgbackrest, pgbackrest_stanza_create + +# Create a stanza on the dedicated repository host +- block: + - name: "Make sure the {{ repo1_path }} directory exists" + file: + path: "{{ repo1_path }}" + state: directory + owner: "{{ pgbackrest_repo_user }}" + group: "{{ pgbackrest_repo_user }}" + mode: 0755 + when: repo1_path | length > 0 + + - name: Create stanza "{{ pgbackrest_stanza }}" + become: true + become_user: "{{ pgbackrest_repo_user }}" + delegate_to: "{{ groups['pgbackret'][0] }}" + run_once: true + command: "pgbackrest --stanza={{ pgbackrest_stanza }} stanza-create" + register: stanza_create_result + changed_when: + - stanza_create_result.rc == 0 + - stanza_create_result.stdout is not search("already exists") + when: + - pgbackrest_repo_host | length > 0 + - "'pgbackrest' in group_names" + tags: pgbackrest, pgbackrest_stanza_create + +... diff --git a/tags.md b/tags.md index 9694b4ee0..4ad358eaf 100644 --- a/tags.md +++ b/tags.md @@ -94,7 +94,7 @@ - - pgbackrest_install - - pgbackrest_conf - - pgbackrest_ssh_keys -- - pgbackrest_cron +- - pgbackrest_stanza_create - pg_probackup - - pg_probackup_repo - - pg_probackup_install diff --git a/vars/main.yml b/vars/main.yml index 7741eda41..2ae24ae0e 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -405,24 +405,32 @@ wal_g_patroni_cluster_bootstrap_command: "wal-g backup-fetch {{ postgresql_data_ # pgBackRest pgbackrest_install: false # or 'true' pgbackrest_install_from_pgdg_repo: true # or 'false' -pgbackrest_stanza: "stanza_name" # specify your --stanza +pgbackrest_stanza: "{{ patroni_cluster_name }}" # specify your --stanza pgbackrest_repo_type: "posix" # or "s3", "gcs", "azure" -pgbackrest_repo_host: "10.128.64.50" # dedicated repository host (if repo_type: "posix") -pgbackrest_repo_user: "postgres" # if "repo_host" is set +pgbackrest_repo_host: "" # dedicated repository host +pgbackrest_repo_user: "" # if "repo_host" is set pgbackrest_conf_file: "/etc/pgbackrest/pgbackrest.conf" # see more options https://pgbackrest.org/configuration.html 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-host", value: "{{ pgbackrest_repo_host }}" } - - { option: "repo1-host-user", value: "{{ pgbackrest_repo_user }}" } + - { option: "repo1-path", value: "/var/lib/pgbackrest" } + - { option: "repo1-retention-full", value: "4" } + - { option: "start-fast", value: "y" } + - { option: "delta", value: "y" } + - { option: "stop-auto", value: "y" } + - { option: "resume", value: "n" } + - { option: "link-all", value: "y" } # - { option: "", value: "" } stanza: # [stanza_name] section - { option: "pg1-path", value: "{{ postgresql_data_dir }}" } - - { option: "process-max", value: "2" } - { option: "recovery-option", value: "recovery_target_action=promote" } + - { option: "log-level-console", value: "info" } + - { option: "process-max", value: "4" } # - { option: "", value: "" } pgbackrest_patroni_cluster_restore_command: '/usr/bin/pgbackrest --stanza={{ pgbackrest_stanza }} --delta restore' # restore from latest backup