Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cron role #275

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions roles/cron/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# defaults file for cron

cron_jobs: []
38 changes: 38 additions & 0 deletions roles/cron/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# tasks file for cron

- name: Add cron jobs
cron:
cron_file: "{{ item.file | default('') }}"
user: "{{ item.user | default('postgres') }}"
minute: "{{ item.minute | default('*') }}"
hour: "{{ item.hour | default('*') }}"
day: "{{ item.day | default('*') }}"
month: "{{ item.month | default('*') }}"
weekday: "{{ item.weekday | default('*') }}"
name: "{{ item.name }}"
disabled: "{{ item.disabled | default(False) }}"
state: "{{ item.state | default('present') }}"
job: "{{ item.job }}"
loop: "{{ cron_jobs }}"
when:
- cron_jobs is defined and cron_jobs | length > 0
- remove_postgres is undefined

- name: Uninstall cron jobs
cron:
cron_file: "{{ item.file | default('') }}"
user: "{{ item.user | default('postgres') }}"
minute: "{{ item.minute | default('*') }}"
hour: "{{ item.hour | default('*') }}"
day: "{{ item.day | default('*') }}"
month: "{{ item.month | default('*') }}"
weekday: "{{ item.weekday | default('*') }}"
name: "{{ item.name }}"
state: "absent"
job: "{{ item.job }}"
loop: "{{ cron_jobs }}"
when:
- cron_jobs is defined and cron_jobs | length > 0
- remove_postgres is defined and remove_postgres | bool
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the role must be added to the remove_cluster.yml playbook

tags: uninstall
14 changes: 0 additions & 14 deletions roles/pgbackrest/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,5 @@
# - "'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

...
33 changes: 30 additions & 3 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,36 @@ 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" }

cron_jobs: []
# - name: "PgBackerest: Full Backup"
# file: /etc/cron.d/pgbackrest
# user: "{{ patroni_superuser_username }}"
# minute: "30"
# hour: "6"
# day: "*"
# month: "*"
# weekday: "0"
# job: "if [ "$(psql -tAXc 'select pg_is_in_recovery()')" = "f" ]; then pgbackrest --type=full --stanza={{ pgbackrest_stanza }} backup; fi"
# - name: "PgBackerest: Diff Backup"
# file: /etc/cron.d/pgbackrest
# user: "{{ patroni_superuser_username }}"
# minute: "30"
# hour: "6"
# day: "*"
# month: "*"
# weekday: "1-6"
# job: "if [ "$(psql -tAXc 'select pg_is_in_recovery()')" = "f" ]; then pgbackrest --type=diff --stanza={{ pgbackrest_stanza }} backup; fi"
# Example for walg
# - name: "WAL-G: Create daily backup"
mrsrvman marked this conversation as resolved.
Show resolved Hide resolved
# user: "{{ patroni_superuser_username }}"
# file: /etc/cron.d/walg
# minute: "30"
# hour: "6"
# day: "*"
# month: "*"
# weekday: "*"
# job: "[ '200' = $(curl -s -o /dev/null -w '\\%{http_code}' http://{{ inventory_hostname }}:8008) ] && /usr/local/bin/wal-g backup-push"

# 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).
Expand Down