additional restore config support

This commit is contained in:
ace 2023-02-20 12:44:18 +03:00
parent 922582e57e
commit ada55a27d0
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
9 changed files with 55 additions and 10 deletions

View File

@ -1,14 +1,16 @@
wal_g_version: "2.0.1-3.el{{ ansible_distribution_major_version }}"
wal_g_pg: no
wal_g_pg_home_dir: "/var/lib/pgsql"
wal_g_pg: false
wal_g_restore: false
wal_g_config_name: ".walg.json"
wal_g_restore_config_name: ".walg-restore.json"
wal_g_pg_binary_name: "wal-g-pg"
wal_g_pg_config_owner: "postgres"
wal_g_pg_config_group: "postgres"
wal_g_pg_backup_owner: "postgres"
wal_g_pg_backup_group: "postgres"
wal_g_pg_package_name_regex: 'postgresql.*server'
wal_g_postgresql_major_version: "14"
wal_g_pg_package_name_regex: "postgresql.*server"
wal_g_postgresql_major_version: "15"
wal_g_backup_schedule: ""
wal_g_backup_retention_schedule: ""
@ -22,7 +24,13 @@ wal_g_default_config: # more options see https://github.com/wal-g/wal-g#configu
# WALG_S3_PREFIX: "s3://bucket"
# AWS_S3_FORCE_PATH_STYLE: "true"
WALG_COMPRESSION_METHOD: "brotli"
PGDATA: "/var/lib/pgsql/{{ wal_g_postgresql_major_version }}/data"
PGDATA: "{{ wal_g_pg_data_dir }}"
PGHOST: "/var/run/postgresql"
# WALG_LIBSODIUM_KEY: "d82560ddab2b096c56ea8c6573dfdf29de8cd6f2bb5e672d1d3b5a89749b8cbd"
WALG_LIBSODIUM_KEY_TRANSFORM: "hex"
wal_g_default_restore_config:
WALG_COMPRESSION_METHOD: "brotli"
PGDATA: "{{ wal_g_pg_data_dir }}"
PGHOST: "/var/run/postgresql"
WALG_LIBSODIUM_KEY_TRANSFORM: "hex"

View File

@ -1,4 +1,21 @@
---
- name: Load a variable file based on the OS type
include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_facts['distribution'] }}.yaml"
- "{{ ansible_facts['os_family'] }}.yaml"
paths:
- "vars"
tags: wal_g_vars
- name: Set facts about needed vars
set_fact:
wal_g_pg_home_dir: "{{ wal_g_pg_home_dir }}"
wal_g_pg_data_dir: "{{ wal_g_pg_data_dir }}"
- name: "Include install WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: pg.yaml
when: wal_g_pg

View File

@ -4,7 +4,7 @@
name: "epel-release"
state: present
- name: "Install WAL-G for PostgreSQL"
- name: "Install WAL-G {{ wal_g_version }} for PostgreSQL"
dnf:
name: "wal-g{{ ('-' ~ wal_g_version) | default('') }}"
state: installed
@ -31,9 +31,23 @@
- name: "Generate conf file walg.json"
copy:
content: "{{ wal_g_combined_config | to_nice_json }}"
dest: "{{ wal_g_pg_home_dir }}/.walg.json"
dest: "{{ wal_g_pg_home_dir }}/{{ wal_g_config_name }}"
owner: "{{ wal_g_pg_config_owner }}"
group: "{{ wal_g_pg_config_group }}"
mode: 0644
tags: wal-g, wal_g, wal_g_conf
- name: Create wal-g restore config
when: wal_g_restore
block:
- name: Merge user options for WAL-G part of restore config
set_fact:
wal_g_restore_combined_config: "{{ wal_g_default_restore_config | combine(wal_g_restore_config|default({}), recursive=true) }}"
- name: "Generate conf file walg-restore.json"
copy:
content: "{{ wal_g_restore_combined_config | to_nice_json }}"
dest: "{{ wal_g_pg_home_dir }}/{{ wal_g_restore_config_name }}"
owner: "{{ wal_g_pg_config_owner }}"
group: "{{ wal_g_pg_config_group }}"
mode: 0644

View File

@ -4,7 +4,7 @@ flock -x 200
role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role')
if [ "${role}" == "\"master\"" ] ; then
{{ wal_g_pg_binary_name }} backup-push {{ wal_g_pg_home_dir }}/{{ wal_g_postgresql_major_version }}/data --full --permanent 2>&1 | tee -a /var/log/postgresql/backup-permanent.log
{{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} backup-push {{ wal_g_pg_data_dir }} --full --permanent 2>&1 | tee -a /var/log/postgresql/backup-permanent.log
else
echo ""
fi

View File

@ -4,7 +4,7 @@ flock -x 200
role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role')
if [ "${role}" == "\"master\"" ] ; then
{{ wal_g_pg_binary_name }} retain {{ wal_g_backup_retention_number }} --confirm --use-sentinel-time 2>&1 | tee -a /var/log/postgresql/backup-retention.log
{{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} retain {{ wal_g_backup_retention_number }} --confirm --use-sentinel-time 2>&1 | tee -a /var/log/postgresql/backup-retention.log
else
echo ""
fi

View File

@ -4,7 +4,7 @@ flock -x 200
role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role')
if [ "${role}" == "\"master\"" ] ; then
{{ wal_g_pg_binary_name }} backup-push {{ wal_g_pg_home_dir }}/{{ wal_g_postgresql_major_version }}/data --full 2>&1 | tee -a /var/log/postgresql/backup.log
{{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} backup-push {{ wal_g_pg_data_dir }} --full 2>&1 | tee -a /var/log/postgresql/backup.log
else
echo ""
fi

3
vars/Debian.yaml Normal file
View File

@ -0,0 +1,3 @@
wal_g_pg_home_dir: "/var/lib/postgresql"
wal_g_pg_data_dir: "{{ wal_g_pg_home_dir }}/{{ wal_g_pg_major_version }}/{{ wal_g_pg_cluster_name }}"
wal_g_pg_cluster_name: "main"

3
vars/RedHat.yaml Normal file
View File

@ -0,0 +1,3 @@
wal_g_pg_home_dir: "/var/lib/pgsql"
wal_g_pg_data_dir: "{{ wal_g_pg_home_dir }}/{{ postgresql_major_version }}/data"

0
vars/main.yaml Normal file
View File