Skip to content

Commit ee8d2f7

Browse files
committed
merge sj213 updates in the last version
2 parents 0e0f4db + 40dffe4 commit ee8d2f7

File tree

8 files changed

+53
-3
lines changed

8 files changed

+53
-3
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Role Variables
3232
- `postgresql_user_name`: System username to be used for PostgreSQL (default: `postgres`).
3333

3434
- `postgresql_version`: PostgreSQL version to install. On Debian-based platforms, the default is whatever version is
35-
pointed to by the `postgresql` metapackage). On RedHat-based platforms, the default is `10`.
35+
pointed to by the `postgresql` metapackage). On RedHat-based platforms, the default is `13`.
3636

3737
- `postgresql_flavor`: On Debian-based platforms, this specifies whether you want to use PostgreSQL packages from pgdg
3838
or the distribution's apt repositories. Possible values: `apt`, `pgdg` (default: `apt`).
@@ -99,6 +99,16 @@ Role Variables
9999
100100
- `postgresql_backup_post_command`: Arbitrary command to run after successful completion of a scheduled backup.
101101
102+
### Backups via pg_dumpall(1) ###
103+
104+
This is an alternative backup strategy that creates full dumps of the whole database cluster using pg_dumpall(1).
105+
106+
- `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.
107+
108+
- `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".
109+
110+
- `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.
111+
102112
Additional options pertaining to backups can be found in the [defaults file](defaults/main.yml).
103113
104114
Dependencies

defaults/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22

3-
postgresql_default_version: 10
3+
postgresql_default_version: 13
4+
postgresql_backup_active_dir: "{{ postgresql_backup_local_dir }}/active"
5+
postgresql_backup_mail_recipient: postgres
6+
postgresql_backup_rotate: true
47
postgresql_user_name: postgres
58

69
# Point-In-Time Recovery (PITR) backup options
@@ -30,3 +33,7 @@ postgresql_backup_command: >-
3033
--keep {{ postgresql_backup_keep | quote }}
3134
{{ '--pg-bin-dir ' ~ __postgresql_pgdg_bin_dir if ansible_os_family == 'RedHat' else '' }}
3235
--backup --clean-archive {{ postgresql_backup_dir | quote }}
36+
37+
postgresql_pgdump_cronspec: "00 18 * * 1-7"
38+
postgresql_pgdump_filespec: 'full.daily.`/bin/date +"\%u"`.sql'
39+

tasks/main.yml

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

95+
- include_tasks: pgdump.yml
96+
when: postgresql_pgdump_dir is defined
97+
9598
- name: Ensure PostgreSQL is running
9699
service:
97100
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+

tasks/redhat.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,18 @@
4242
# # here but alas there is no `startswith` test
4343
# loop: "{{ __postgresql_yum_repolist_result.results }}"
4444

45-
- name: Install PostgreSQL (RedHat)
45+
46+
- name: Install PostgreSQL (RedHat < 8)
47+
yum:
48+
name: postgresql{{ __postgresql_version_dotless }}-server
49+
when: ansible_distribution_major_version is version(8, '<')
50+
51+
# on RH-8 for installing the pgdg-version, the Appstream-repo must be disabled
52+
- name: Install PostgreSQL (RedHat >= 8)
4653
yum:
4754
name: postgresql{{ __postgresql_version_dotless }}-server
55+
disablerepo: AppStream
56+
when: ansible_distribution_major_version is version(8, '>=')
4857

4958
- name: Check for pgdata directory
5059
stat:

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)