Skip to content

Commit 70bb3dc

Browse files
committed
Provide alternative backup strategy using pg_dumpall(1)
1 parent 9425bbe commit 70bb3dc

File tree

7 files changed

+38
-0
lines changed

7 files changed

+38
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ Role Variables
108108
109109
- `postgresql_backup_post_command`: Arbitrary command to run after successful completion of a scheduled backup.
110110
111+
### Backups via pg_dumpall(1) ###
112+
113+
This is an alternative backup strategy that creates full dumps of the whole database cluster using pg_dumpall(1).
114+
115+
- `postgresql_pgdump_dir`: If set, enables pg_dumpall(1)-backups. Set this to the directory where the dumps should be written. There is no distinction between local and archive directories; it is assumed that this directory is "safe enough" and has enough storage space available.
116+
117+
- `postgresql_pgdump_cronspec`: This specifies the first 5 fields of the crontab-entry that will be govern the pgdump-schedule. Defaults to "00 18 * * 1-7", which means "start the dump each day at 18:00".
118+
119+
- `postgresql_pgdump_filespec`: Controls the names of the dump files created. The default creates a file for each day of the week that will be overwritten after seven days.
120+
111121
Dependencies
112122
------------
113123

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ postgresql_backup_rotate: true
88
postgresql_user_name: postgres
99

1010
postgresql_archive_wal_rsync_args: '--ignore-existing -ptg --info=skip1'
11+
12+
postgresql_pgdump_cronspec: "00 18 * * 1-7"
13+
postgresql_pgdump_filespec: 'full.daily.`/bin/date +"\%u"`.sql'
14+

tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
- include_tasks: backup.yml
9191
when: postgresql_backup_dir is defined
9292

93+
- include_tasks: pgdump.yml
94+
when: postgresql_pgdump_dir is defined
95+
9396
- name: Ensure PostgreSQL is running
9497
service:
9598
name: "{{ postgresql_service_name }}"

tasks/pgdump.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
3+
- name: Create backup directory for pgdump
4+
file:
5+
owner: postgres
6+
group: postgres
7+
mode: 0750
8+
state: directory
9+
path: "{{ postgresql_pgdump_dir }}"
10+
11+
- name: Schedule pgdump backups via cron(8)
12+
template:
13+
src: local-pgdump.crontab
14+
dest: /etc/cron.d/local-pgdump
15+
owner: root
16+
group: root
17+
mode: 0644
18+

templates/local-pgdump.crontab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ postgresql_pgdump_cronspec }} {{ postgresql_user_name }} {{ postgresql_inst_dir_default }}/bin/pg_dumpall -c -f {{ postgresql_pgdump_dir }}/{{ postgresql_pgdump_filespec }}

vars/debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
postgresql_pgdata_default: /var/lib/postgresql/{{ postgresql_version }}/main
44
postgresql_conf_dir_default: /etc/postgresql/{{ postgresql_version }}/main
5+
postgresql_inst_dir_default: /usr/lib/postgresql/{{ postgresql_version }}
56
postgresql_service_name: postgresql

vars/redhat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
postgresql_pgdata_default: /var/lib/pgsql/{{ postgresql_version }}/data
44
postgresql_conf_dir_default: /var/lib/pgsql/{{ postgresql_version }}/data
5+
postgresql_inst_dir_default: /usr/pgsql-{{ postgresql_version }}
56
postgresql_service_name: postgresql-{{ postgresql_version }}

0 commit comments

Comments
 (0)