From 3ff005b0b9ed828d3a5a5d2db2c5afd0bd0b56ea Mon Sep 17 00:00:00 2001 From: Hans Schou Date: Mon, 7 Nov 2022 13:38:27 +0100 Subject: [PATCH] Create crontab for pgbackrest --- roles/pgbackrest/tasks/main.yml | 15 +++++++++++++++ tags.md | 1 + vars/main.yml | 3 +++ 3 files changed, 19 insertions(+) diff --git a/roles/pgbackrest/tasks/main.yml b/roles/pgbackrest/tasks/main.yml index c04c614c2..3de3ee23e 100644 --- a/roles/pgbackrest/tasks/main.yml +++ b/roles/pgbackrest/tasks/main.yml @@ -121,4 +121,19 @@ # - "'postgres_cluster' in group_names" # tags: pgbackrest, pgbackrest_bootstrap_script +- name: Crontab pgbackrest + become: true + cron: + name: "{{ item.name | default('Backup') }}" + cron_file: /etc/cron.d/pgbackrest + job: "/usr/bin/pgbackrest --type={{ item.type }} --stanza={{ pgbackrest_stanza }} backup" + user: postgres + dow: "{{ item.dow }}" + hour: "{{ item.hour }}" + minute: "{{ item.minute }}" + ignore_errors: true + loop: "{{ pgbackrest_cron | flatten(1) }}" + when: pgbackrest_cron is defined and pgbackrest_cron | length > 0 + tags: pgbackrest_cron + ... diff --git a/tags.md b/tags.md index 390e8abb2..85f692c6f 100644 --- a/tags.md +++ b/tags.md @@ -92,5 +92,6 @@ - - pgbackrest_install - - pgbackrest_conf - - pgbackrest_ssh_keys +- - pgbackrest_cron - netdata diff --git a/vars/main.yml b/vars/main.yml index 2849d05b3..62f3e1669 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -351,6 +351,9 @@ pgbackrest_conf: pgbackrest_patroni_cluster_restore_command: '/usr/bin/pgbackrest --stanza={{ pgbackrest_stanza }} --delta restore' # restore from latest backup # '/usr/bin/pgbackrest --stanza={{ pgbackrest_stanza }} --type=time "--target=2020-06-01 11:00:00+03" --delta restore' # Point-in-Time Recovery (example) +pgbackrest_cron: [] +# - {name: "Full Backup", type: "full", hour: "06", minute: "30", dow: "0"} +# - {name: "Diff Backup", type: "diff", hour: "06", minute: "30", dow: "1-6"} # PITR mode (if patroni_cluster_bootstrap_method: "pgbackrest" or "wal-g"): # 1) The database cluster directory will be cleaned (for "wal-g") or overwritten (for "pgbackrest" --delta restore).