mirror of
https://git.lapiole.org/dani/ansible-roles.git
synced 2025-07-26 15:55:56 +02:00
Update to 2021-12-01 19:13
This commit is contained in:
5
roles/postgresql_server/templates/pg_hba.conf.j2
Normal file
5
roles/postgresql_server/templates/pg_hba.conf.j2
Normal file
@@ -0,0 +1,5 @@
|
||||
# {{ ansible_managed }}
|
||||
local all all peer
|
||||
host all all 127.0.0.1/32 md5
|
||||
host all all ::1/128 md5
|
||||
host all all 0.0.0.0/0 md5
|
6
roles/postgresql_server/templates/post-backup.sh.j2
Normal file
6
roles/postgresql_server/templates/post-backup.sh.j2
Normal file
@@ -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
|
16
roles/postgresql_server/templates/postgresql.conf.j2
Normal file
16
roles/postgresql_server/templates/postgresql.conf.j2
Normal file
@@ -0,0 +1,16 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
port = {{ pg_port }}
|
||||
|
||||
{% for key in pg_conf.keys() | list | sort %}
|
||||
{% if key == 'listen_addresses' %}
|
||||
listen_addresses = '{{ pg_conf[key] | join("','") }}'
|
||||
{% elif key in pg_pct_mem_directives and pg_conf[key] is search('%$') %}
|
||||
{{ key }} = {{ ((pg_conf[key] | regex_replace('%$', '') | int) * ansible_memtotal_mb * 0.01) | int }}MB
|
||||
{% elif pg_conf[key] is search(',|/') %}
|
||||
{{ key }} = '{{ pg_conf[key] }}'
|
||||
{% else %}
|
||||
{{ key }} = {{ pg_conf[key] }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
61
roles/postgresql_server/templates/pre-backup.sh.j2
Normal file
61
roles/postgresql_server/templates/pre-backup.sh.j2
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
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 %}
|
||||
echo "Dumping $DB to $DEST/$DB.{{ dump_ext }}.{{ comp_ext }}"
|
||||
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 }}
|
||||
echo "Dumping $DB schema to $DEST/$DB.schema.{{ 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 %}
|
||||
echo "Dumping $DB to $DEST/$DB.{{ dump_ext }}"
|
||||
su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dump {{ dump_options }} $DB" > $DEST/$DB.{{ dump_ext }}
|
||||
echo "Dumping $DB schema to $DEST/$DB.schema.sql"
|
||||
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 %}
|
||||
echo "Dumping globals to $DEST/pg_globals.sql.{{ comp_ext }}"
|
||||
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 }}
|
||||
echo "Dumping all schemas to $DEST/pg_schema.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 %}
|
||||
echo "Dumping globals to $DEST/pg_globals.sql"
|
||||
su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dumpall --globals-only" > $DEST/pg_globals.sql
|
||||
echo "Dumping all schemas to $DEST/pg_schema.sql"
|
||||
su - postgres -c "{{ (pg_version != 'default') | ternary('/usr/pgsql-' + pg_version | string,'') }}/bin/pg_dumpall --schema-only" > $DEST/pg_schema.sql
|
||||
{% endif %}
|
||||
|
||||
echo "Dumping config to $DEST"
|
||||
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/
|
Reference in New Issue
Block a user