diff --git a/defaults/main.yaml b/defaults/main.yaml index b08db73..c4eb42e 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -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: '' diff --git a/meta/main.yaml b/meta/main.yaml index 9cc0fe1..083d8c1 100644 --- a/meta/main.yaml +++ b/meta/main.yaml @@ -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: [] diff --git a/tasks/backup_job.yaml b/tasks/backup_job.yaml index 6cff2a5..52aae0d 100644 --- a/tasks/backup_job.yaml +++ b/tasks/backup_job.yaml @@ -19,4 +19,4 @@ enabled: no masked: no daemon_reload: yes - when: not backup_service.changed + when: backup_service.changed diff --git a/tasks/backup_job_timer.yaml b/tasks/backup_job_timer.yaml index 5e6bf4a..885cc2f 100644 --- a/tasks/backup_job_timer.yaml +++ b/tasks/backup_job_timer.yaml @@ -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 diff --git a/tasks/backup_permanent_job.yaml b/tasks/backup_permanent_job.yaml index d1e23cc..763ea04 100644 --- a/tasks/backup_permanent_job.yaml +++ b/tasks/backup_permanent_job.yaml @@ -19,4 +19,4 @@ enabled: no masked: no daemon_reload: yes - when: not backup_permanent_service.changed + when: backup_permanent_service.changed diff --git a/tasks/backup_permanent_job_timer.yaml b/tasks/backup_permanent_job_timer.yaml index bbca385..f476be1 100644 --- a/tasks/backup_permanent_job_timer.yaml +++ b/tasks/backup_permanent_job_timer.yaml @@ -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 diff --git a/tasks/backup_retention_job.yaml b/tasks/backup_retention_job.yaml index 6ec98b5..6014c23 100644 --- a/tasks/backup_retention_job.yaml +++ b/tasks/backup_retention_job.yaml @@ -19,5 +19,4 @@ enabled: no masked: no daemon_reload: yes - when: not backup_retention_service.changed - + when: backup_retention_service.changed diff --git a/tasks/backup_retention_job_timer.yaml b/tasks/backup_retention_job_timer.yaml index dae7580..83a0bc4 100644 --- a/tasks/backup_retention_job_timer.yaml +++ b/tasks/backup_retention_job_timer.yaml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index d600c96..98010cb 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 + diff --git a/templates/backup-permanent.sh.j2 b/templates/backup-permanent.sh.j2 index fec1948..8fbece6 100644 --- a/templates/backup-permanent.sh.j2 +++ b/templates/backup-permanent.sh.j2 @@ -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 diff --git a/templates/backup-retention.sh.j2 b/templates/backup-retention.sh.j2 index f113250..f0c7a9b 100644 --- a/templates/backup-retention.sh.j2 +++ b/templates/backup-retention.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\"" ] || [ "${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 diff --git a/templates/backup.sh.j2 b/templates/backup.sh.j2 index 617f5f3..85214e5 100644 --- a/templates/backup.sh.j2 +++ b/templates/backup.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\"" ] || [ "${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