support enable/disable backups

This commit is contained in:
ace 2024-05-26 17:59:12 +03:00
parent b183d7441c
commit 4ae6dc8311
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
12 changed files with 26 additions and 46 deletions

View File

@ -2,7 +2,7 @@ wal_g_version: "3.0.0"
wal_g_install_repo: true
wal_g_pg: false
wal_g_pg_binary_name: "wal-g-pg"
wal_g_pg_binary: "/usr/bin/wal-g-pg"
wal_g_pg_user: "postgres"
wal_g_pg_database: "postgres"
wal_g_restore: false
@ -15,10 +15,12 @@ wal_g_pg_backup_group: "postgres"
wal_g_pg_major_version: "15"
wal_g_backup_enable: true
wal_g_backup_schedule: ""
wal_g_backup_retention_schedule: ""
wal_g_backup_schedule: "*-*-* 00:00:00"
wal_g_backup_permanent_enable: false
wal_g_backup_permanent_schedule: "*-*-* 05:00:00"
wal_g_backup_retention_enable: false
wal_g_backup_retention_schedule: "*-*-* 10:00:00"
wal_g_backup_retention_number: 7
wal_g_backup_permanent_schedule: ""
# If backuping through proxy
#wal_g_http_proxy: ''

View File

@ -1,7 +1,7 @@
---
galaxy_info:
description: WAL-G role for PostgreSQL
description: WAL-G backup util
galaxy_tags:
- wal-g-pg
- wal-g
dependencies: []

View File

@ -19,4 +19,4 @@
enabled: no
masked: no
daemon_reload: yes
when: not backup_service.changed
when: backup_service.changed

View File

@ -10,6 +10,5 @@
name: backup.timer
enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}"
masked: no
state: started
state: "{{ 'started' if wal_g_backup_enable else 'stopped' }}"
daemon_reload: yes
when: not backup_timer.changed

View File

@ -19,4 +19,4 @@
enabled: no
masked: no
daemon_reload: yes
when: not backup_permanent_service.changed
when: backup_permanent_service.changed

View File

@ -8,8 +8,7 @@
- name: Enable and start systemd backup permanent timer
systemd:
name: backup-permanent.timer
enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}"
enabled: "{{ 'yes' if wal_g_backup_permanent_enable else 'no' }}"
masked: no
state: started
state: "{{ 'started' if wal_g_backup_permanent_enable else 'stopped' }}"
daemon_reload: yes
when: not backup_permanent_timer.changed

View File

@ -19,5 +19,4 @@
enabled: no
masked: no
daemon_reload: yes
when: not backup_retention_service.changed
when: backup_retention_service.changed

View File

@ -8,8 +8,7 @@
- name: Enable and start systemd backup retention timer
systemd:
name: backup-retention.timer
enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}"
enabled: "{{ 'yes' if wal_g_backup_retention_enable else 'no' }}"
masked: no
state: started
state: "{{ 'started' if wal_g_backup_retention_enable else 'stopped' }}"
daemon_reload: yes
when: not backup_retention_timer.changed

View File

@ -17,40 +17,22 @@
- name: "Include install WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: pg.yaml
when: wal_g_pg
- name: "Include backup job with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_job.yaml
when:
- wal_g_pg
- name: "Include backup job timer with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_job_timer.yaml
when:
- wal_g_pg
- wal_g_backup_schedule is defined
- wal_g_backup_schedule | length > 0
- name: "Include backup retention job with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_retention_job.yaml
when:
- wal_g_pg
- name: "Include backup retention job timer with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_retention_job_timer.yaml
when:
- wal_g_pg
- wal_g_backup_retention_schedule is defined
- wal_g_backup_retention_schedule | length > 0
- name: "Include permanent backup job with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_permanent_job.yaml
when:
- wal_g_pg
- name: "Include permanent backup job timer with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_permanent_job_timer.yaml
when:
- wal_g_pg
- wal_g_backup_permanent_schedule is defined
- wal_g_backup_permanent_schedule | length > 0
- name: "Include backup retention job with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_retention_job.yaml
- name: "Include backup retention job timer with WAL-G {{ wal_g_version }} for PostgreSQL"
include_tasks: backup_retention_job_timer.yaml

View File

@ -5,7 +5,7 @@ role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | j
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
{% 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 }} --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\"" ] || [ "${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 }} delete retain {{ wal_g_backup_retention_number }} --confirm --use-sentinel-time 2>&1 | tee -a /var/log/postgresql/backup-retention.log
{% 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 }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} delete 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\"" ] || [ "${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
{% 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 }} --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