Skip to content

Commit

Permalink
WAL-G: Perform weekly full backup and retain 4 full backups
Browse files Browse the repository at this point in the history
In this commit, we have made important changes to the backup and retention strategy. We have transitioned from using the 'wal-g delete before FIND_FULL' command to 'wal-g delete retain'. This change was made to ensure a more robust and predictable backup retention policy. With 'wal-g delete retain', we explicitly specify the number of full backups to retain, which provides better control over the backup history.

Furthermore, we have introduced a new configuration option, 'WALG_DELTA_MAX_STEPS', which is set to '6'. This option determines the maximum number of delta backups that can be retained between full backups. By limiting the number of data backups, we can optimize storage utilization and ensure efficient backup management.

Additionally, we have added logging to capture the results of both backup creation and deletion. This logging will help us monitor the success and effectiveness of the backup and retention process, allowing us to quickly identify any issues or anomalies.
  • Loading branch information
vitabaks committed Jul 9, 2023
1 parent 9490a96 commit cf84295
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ wal_g_json: # config https://github.com/wal-g/wal-g#configuration
- { option: "AWS_SECRET_ACCESS_KEY", value: "{{ AWS_SECRET_ACCESS_KEY | default('') }}" } # define values or pass via --extra-vars
- { option: "WALG_S3_PREFIX", value: "{{ WALG_S3_PREFIX | default('') }}" } # define values or pass via --extra-vars
- { option: "WALG_COMPRESSION_METHOD", value: "brotli" } # or "lz4", "lzma", "zstd"
- { option: "WALG_DELTA_MAX_STEPS", value: "6" } # determines how many delta backups can be between full backups
- { option: "PGDATA", value: "{{ postgresql_data_dir }}" }
- { option: "PGHOST", value: "{{ postgresql_unix_socket_dir }}" }
- { option: "PGPORT", value: "{{ postgresql_port }}" }
Expand All @@ -431,16 +432,16 @@ wal_g_cron_jobs:
day: "*"
month: "*"
weekday: "*"
job: "[ $(curl -s -o /dev/null -w '%{http_code}' http://{{ inventory_hostname }}:{{ patroni_restapi_port }}) = '200' ] && wal-g backup-push {{ postgresql_data_dir }}"
- name: "WAL-G: Delete old backups" # older than 30 days (by default). Change according to your company's backup retention policy.
job: "[ $(curl -s -o /dev/null -w '%{http_code}' http://{{ inventory_hostname }}:{{ patroni_restapi_port }}) = '200' ] && wal-g backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"
- name: "WAL-G: Delete old backups" # retain 4 full backups (adjust according to your company's backup retention policy)
user: "postgres"
file: /etc/cron.d/walg
minute: "30"
hour: "6"
day: "*"
month: "*"
weekday: "*"
job: "[ $(curl -s -o /dev/null -w '%{http_code}' http://{{ inventory_hostname }}:{{ patroni_restapi_port }}) = '200' ] && wal-g delete before FIND_FULL $(date -d '-30 days' '+%FT%TZ') --confirm"
job: "[ $(curl -s -o /dev/null -w '%{http_code}' http://{{ inventory_hostname }}:{{ patroni_restapi_port }}) = '200' ] && wal-g delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"

# pgBackRest
pgbackrest_install: false # or 'true'
Expand Down

0 comments on commit cf84295

Please sign in to comment.