From a3e3a85683b25a1fc297bc875cd324797921f855 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 16 Nov 2020 12:00:07 +0100 Subject: [PATCH] Update to 2020-11-16 12:00 --- roles/postgresql_server/meta/main.yml | 1 + roles/postgresql_server/tasks/main.yml | 18 ++++---- .../postgresql_server/templates/post-backup.sh.j2 | 6 +++ roles/postgresql_server/templates/pre-backup.sh.j2 | 50 ++++++++++++++++++++++ roles/sssd_ldap_auth/tasks/main.yml | 2 +- 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 roles/postgresql_server/templates/post-backup.sh.j2 create mode 100644 roles/postgresql_server/templates/pre-backup.sh.j2 diff --git a/roles/postgresql_server/meta/main.yml b/roles/postgresql_server/meta/main.yml index 764e728..bb18099 100644 --- a/roles/postgresql_server/meta/main.yml +++ b/roles/postgresql_server/meta/main.yml @@ -2,3 +2,4 @@ dependencies: - role: repo_postgresql + - role: mkdir diff --git a/roles/postgresql_server/tasks/main.yml b/roles/postgresql_server/tasks/main.yml index 046853a..f105398 100644 --- a/roles/postgresql_server/tasks/main.yml +++ b/roles/postgresql_server/tasks/main.yml @@ -35,18 +35,18 @@ file: path=/home/lbkp/pgsql state=directory owner=postgres group=postgres mode=700 tags: pg -- name: Create pre and post backup hook dir - file: path={{ item }} state=directory mode=750 - with_items: - - /etc/backup/pre.d - - /etc/backup/post.d +- name: Remove old backup hooks + file: path={{ item }} state=absent + loop: + - /etc/backup/pre.d/postgresql_create_dumps.sh + - /etc/backup/post.d/postgresql_delete_dumps.sh tags: pg - name: Deploy backup scripts - template: src={{ item.script }}.j2 dest=/etc/backup/{{ item.hook }}.d/{{ item.script }} mode=755 - with_items: - - { script: 'postgresql_create_dumps.sh', hook: pre } - - { script: 'postgresql_delete_dumps.sh', hook: post } + template: src={{ item }}-backup.sh.j2 dest=/etc/backup/{{ item }}.d/postgresql.sh mode=755 + loop: + - pre + - post tags: pg - name: Handle PostgreSQL port diff --git a/roles/postgresql_server/templates/post-backup.sh.j2 b/roles/postgresql_server/templates/post-backup.sh.j2 new file mode 100644 index 0000000..570459b --- /dev/null +++ b/roles/postgresql_server/templates/post-backup.sh.j2 @@ -0,0 +1,6 @@ +#!/bin/bash -e + +{% if pg_remove_dump_after_backup %} +rm -f /home/lbkp/pgsql/*.sql* +{% endif %} +rm -f /home/lbkp/pgsql/*.conf diff --git a/roles/postgresql_server/templates/pre-backup.sh.j2 b/roles/postgresql_server/templates/pre-backup.sh.j2 new file mode 100644 index 0000000..f6963f1 --- /dev/null +++ b/roles/postgresql_server/templates/pre-backup.sh.j2 @@ -0,0 +1,50 @@ +#!/bin/bash -e + +DEST=/home/lbkp/pgsql + +{% if pg_dump_format == 'text' %} +{% set dump_options = '-Fp -Cc' %} +{% set dump_ext = 'sql' %} +{% elif pg_dump_format == 'custom' %} +{% set dump_options = '-Fc' %} +{% set dump_ext = 'sqlc' %} +{% else %} +{% set dump_options = '-F' + pg_dump_format %} +{% set dump_ext = 'dump' %} +{% endif %} + +for DB in $(su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/psql -d postgres -qtc 'SELECT datname from pg_database' | grep -vP '^\s+?template[01]$'") +do +{% if pg_compress_cmd %} +{% if pg_compress_cmd is search('p?xz') %} +{% set comp_ext = 'xz' %} +{% elif pg_compress_cmd is search('p?bzip2') %} +{% set comp_ext = 'bz2' %} +{% elif pg_compress_cmd is search('(pi)?gz') %} +{% set comp_ext = 'gz' %} +{% elif pg_compress_cmd is search('lzop') %} +{% set comp_ext = 'lzo' %} +{% elif pg_compress_cmd is search('lz4') %} +{% set comp_ext = 'lz4' %} +{% elif pg_compress_cmd is search('zst') %} +{% set comp_ext = 'zst' %} +{% else %} +{% set comp_ext = 'z' %} +{% endif %} + su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dump {{ dump_options }} $DB" | /bin/nice -n 10 {{ pg_compress_cmd }} > $DEST/$DB.{{ dump_ext }}.{{ comp_ext }} + su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dump --schema-only -Fp $DB" | /bin/nice -n 10 {{ pg_compress_cmd }} > $DEST/$DB.schema.{{ dump_ext }}.{{ comp_ext }} +{% else %} + su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dump {{ dump_options }} $DB" > $DEST/$DB.{{ dump_ext }} + su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dump --schema-only -Fp $DB" > $DEST/$DB.schema.sql +{% endif %} +done +{% if pg_compress_cmd %} +su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dumpall --globals-only" | /bin/nice -n 10 {{ pg_compress_cmd }} > $DEST/pg_globals.sql.{{ comp_ext }} +su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dumpall --schema-only" | /bin/nice -n 10 {{ pg_compress_cmd }} > $DEST/pg_schema.sql.{{ comp_ext }} +{% else %} +su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dumpall --globals-only" > $DEST/pg_globals.sql +su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dumpall --schema-only" > $DEST/pg_schema.sql +{% endif %} + +cp -a /var/lib/pgsql/{{ (pg_version != 'default') | ternary(pg_version | string + '/','') }}data/postgresql.conf $DEST/ +cp -a /var/lib/pgsql/{{ (pg_version != 'default') | ternary(pg_version | string + '/','') }}data/pg_hba.conf $DEST/ diff --git a/roles/sssd_ldap_auth/tasks/main.yml b/roles/sssd_ldap_auth/tasks/main.yml index d391225..30f7e65 100644 --- a/roles/sssd_ldap_auth/tasks/main.yml +++ b/roles/sssd_ldap_auth/tasks/main.yml @@ -4,7 +4,7 @@ - name: Deploy sssd config template: src=sssd.conf.j2 dest=/etc/sssd/sssd.conf owner=root group=root mode=0600 - when: sssd_config + register: sssd_config notify: restart sssd # On el8 for example, sssd is already installed and running on a default setup