Use vars and templates for PostgreSQL backups
This commit is contained in:
parent
bedc5cf081
commit
79b1a4b1ff
7 changed files with 13 additions and 11 deletions
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
sudo -u postgres sh -e -c "mkdir -p /var/lib/postgresql/backups/12/main && umask 077 && pg_dumpall | gzip > /var/lib/postgresql/backups/12/main/$(TZ=UTC date +"%Y_%m_%d_%H_%M_%S").gz"
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
sudo -u postgres sh -e -c "test -d /var/lib/postgresql/backups/12/main && find /var/lib/postgresql/backups/12/main -type f -mtime +35 -exec rm {} \;"
|
|
@ -17,6 +17,8 @@ common__certbot__cert_domains:
|
|||
common__certbot__post_hook: null
|
||||
common__certbot__pre_hook: null
|
||||
|
||||
postgresql_backups_dir: '/var/lib/postgresql/backups/12/main'
|
||||
|
||||
postgresql_users:
|
||||
- name: matrix_synapse
|
||||
password: !vault |
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
tasks:
|
||||
- name: Find PostgreSQL dumps
|
||||
find:
|
||||
paths: '/var/lib/postgresql/backups/12/main'
|
||||
paths: '{{ postgresql_backups_dir }}'
|
||||
register: postgresql_dumps
|
||||
|
||||
- name: Fetch PostgreSQL dumps
|
||||
|
|
|
@ -10,16 +10,16 @@
|
|||
- geerlingguy.postgresql
|
||||
tasks:
|
||||
- name: Create weekly Cron job for PostgreSQL backup
|
||||
copy:
|
||||
src: ../../files/pg_backup
|
||||
template:
|
||||
src: ../../templates/pg_backup
|
||||
dest: /etc/cron.weekly/pg_backup
|
||||
mode: 'u=rwx,g=rx,o=rx'
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: Create daily Cron job for PostgreSQL cleanup
|
||||
copy:
|
||||
src: ../../files/pg_cleanup
|
||||
template:
|
||||
src: ../../templates/pg_cleanup
|
||||
dest: /etc/cron.daily/pg_cleanup
|
||||
mode: 'u=rwx,g=rx,o=rx'
|
||||
owner: root
|
||||
|
|
3
templates/pg_backup
Normal file
3
templates/pg_backup
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
sudo -u postgres sh -e -c "mkdir -p {{ postgresql_backups_dir }} && umask 077 && pg_dumpall | gzip > {{ postgresql_backups_dir }}/$(TZ=UTC date +"%Y_%m_%d_%H_%M_%S").gz"
|
3
templates/pg_cleanup
Normal file
3
templates/pg_cleanup
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
sudo -u postgres sh -e -c "test -d {{ postgresql_backups_dir }} && find {{ postgresql_backups_dir }} -type f -mtime +35 -exec rm {} \;"
|
Reference in a new issue