diff --git a/defaults/main.yaml b/defaults/main.yaml index 09130cf..86f96d4 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -2,6 +2,9 @@ wal_g_version: "2.0.1" wal_g_install_repo: true wal_g_pg: false +wal_g_pg_binary_name: "wal-g-pg" +wal_g_pg_user: "postgres" +wal_g_pg_database: "postgres" wal_g_restore: false wal_g_config_name: ".walg.json" wal_g_restore_config_name: ".walg-restore.json" @@ -12,6 +15,7 @@ wal_g_pg_backup_owner: "postgres" wal_g_pg_backup_group: "postgres" wal_g_pg_major_version: "15" +wal_g_backup_enable: false wal_g_backup_schedule: "" wal_g_backup_retention_schedule: "" wal_g_backup_retention_number: 7 @@ -35,6 +39,8 @@ wal_g_default_config: # more options see https://github.com/wal-g/wal-g#configu WALG_COMPRESSION_METHOD: "brotli" PGDATA: "{{ wal_g_pg_data_dir }}" PGHOST: "/var/run/postgresql" + PGUSER: "{{ wal_g_pg_user }}" + PGDATABASE: "{{ wal_g_pg_database }}" # WALG_LIBSODIUM_KEY: "d82560ddab2b096c56ea8c6573dfdf29de8cd6f2bb5e672d1d3b5a89749b8cbd" WALG_LIBSODIUM_KEY_TRANSFORM: "hex" @@ -42,4 +48,6 @@ wal_g_default_restore_config: WALG_COMPRESSION_METHOD: "brotli" PGDATA: "{{ wal_g_pg_data_dir }}" PGHOST: "/var/run/postgresql" + PGUSER: "{{ wal_g_pg_user }}" + PGDATABASE: "{{ wal_g_pg_database }}" WALG_LIBSODIUM_KEY_TRANSFORM: "hex" diff --git a/tasks/backup_job_timer.yaml b/tasks/backup_job_timer.yaml index 5ace49d..5e6bf4a 100644 --- a/tasks/backup_job_timer.yaml +++ b/tasks/backup_job_timer.yaml @@ -8,7 +8,7 @@ - name: Enable and start systemd backup timer systemd: name: backup.timer - enabled: yes + enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}" masked: no state: started daemon_reload: yes diff --git a/tasks/backup_permanent_job_timer.yaml b/tasks/backup_permanent_job_timer.yaml index e5efdaf..bbca385 100644 --- a/tasks/backup_permanent_job_timer.yaml +++ b/tasks/backup_permanent_job_timer.yaml @@ -8,7 +8,7 @@ - name: Enable and start systemd backup permanent timer systemd: name: backup-permanent.timer - enabled: yes + enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}" masked: no state: started daemon_reload: yes diff --git a/tasks/backup_retention_job_timer.yaml b/tasks/backup_retention_job_timer.yaml index 3eb655b..dae7580 100644 --- a/tasks/backup_retention_job_timer.yaml +++ b/tasks/backup_retention_job_timer.yaml @@ -8,7 +8,7 @@ - name: Enable and start systemd backup retention timer systemd: name: backup-retention.timer - enabled: yes + enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}" masked: no state: started daemon_reload: yes diff --git a/templates/backup-permanent.sh.j2 b/templates/backup-permanent.sh.j2 index be55ba8..fec1948 100644 --- a/templates/backup-permanent.sh.j2 +++ b/templates/backup-permanent.sh.j2 @@ -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 +if [ "${role}" == "\"master\"" ] || [ "${role}" == "" ]; then {% if wal_g_http_proxy is defined %}http_proxy={{ wal_g_http_proxy }} {% else %}{% endif %}{% if wal_g_https_proxy is defined %}https_proxy={{ wal_g_https_proxy }} {% elif wal_g_http_proxy is defined %}https_proxy={{ wal_g_http_proxy }}{% else %}{% endif %} {{ 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 "" diff --git a/templates/backup-retention.sh.j2 b/templates/backup-retention.sh.j2 index 6b38690..ac543b9 100644 --- a/templates/backup-retention.sh.j2 +++ b/templates/backup-retention.sh.j2 @@ -3,7 +3,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 +if [ "${role}" == "\"master\"" ] || [ "${role}" == "" ]; then {% if wal_g_http_proxy is defined %}http_proxy={{ wal_g_http_proxy }} {% else %}{% endif %}{% if wal_g_https_proxy is defined %}https_proxy={{ wal_g_https_proxy }} {% elif wal_g_http_proxy is defined %}https_proxy={{ wal_g_http_proxy }}{% else %}{% endif %} {{ 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 "" diff --git a/templates/backup.sh.j2 b/templates/backup.sh.j2 index a99c853..617f5f3 100644 --- a/templates/backup.sh.j2 +++ b/templates/backup.sh.j2 @@ -3,7 +3,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 +if [ "${role}" == "\"master\"" ] || [ "${role}" == "" ]; then {% if wal_g_http_proxy is defined %}http_proxy={{ wal_g_http_proxy }} {% else %}{% endif %}{% if wal_g_https_proxy is defined %}https_proxy={{ wal_g_https_proxy }} {% elif wal_g_http_proxy is defined %}https_proxy={{ wal_g_http_proxy }}{% else %}{% endif %} {{ 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 ""