1
0
Fork 0

Use vars and templates for PostgreSQL backups

This commit is contained in:
Alex Kotov 2020-07-05 14:57:15 +05:00
parent bedc5cf081
commit 79b1a4b1ff
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
7 changed files with 13 additions and 11 deletions

View file

@ -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"

View file

@ -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 {} \;"

View file

@ -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 |

View file

@ -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

View file

@ -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
View 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
View 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 {} \;"