diff options
author | Paul B <paul@bonaud.fr> | 2018-12-28 15:30:13 +0100 |
---|---|---|
committer | Paul Bonaud <paul.bonaud@fretlink.com> | 2018-12-28 18:23:19 +0100 |
commit | c95984df57136048002f0d60c6469d9bbbdd1e0a (patch) | |
tree | ec16b304ef816d5ab65fd4217bbb8748ffad94fe /templates/standby-clone.sh.j2 | |
parent | 8371771c8e9b8a2f2a6a4d81a142ddc805e198b4 (diff) | |
download | ansible-postgresql-role-c95984df57136048002f0d60c6469d9bbbdd1e0a.tar.gz ansible-postgresql-role-c95984df57136048002f0d60c6469d9bbbdd1e0a.tar.zst ansible-postgresql-role-c95984df57136048002f0d60c6469d9bbbdd1e0a.zip |
standby: rsync from barman is optional if SSH access is already here
Diffstat (limited to 'templates/standby-clone.sh.j2')
-rwxr-xr-x | templates/standby-clone.sh.j2 | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/templates/standby-clone.sh.j2 b/templates/standby-clone.sh.j2 index 3486342..16a6930 100755 --- a/templates/standby-clone.sh.j2 +++ b/templates/standby-clone.sh.j2 | |||
@@ -1,6 +1,8 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # {{ ansible_managed }} | 2 | # {{ ansible_managed }} |
3 | 3 | ||
4 | set -eo pipefail | ||
5 | |||
4 | BARMAN_DATABASE=$1 | 6 | BARMAN_DATABASE=$1 |
5 | BARMAN_BACKUP_VERSION=$2 | 7 | BARMAN_BACKUP_VERSION=$2 |
6 | 8 | ||
@@ -17,7 +19,7 @@ echo "accept key if necessary" | |||
17 | sudo -u postgres ssh barman@{{ postgres_barman_server }} echo "" | 19 | sudo -u postgres ssh barman@{{ postgres_barman_server }} echo "" |
18 | 20 | ||
19 | echo Stopping PostgreSQL | 21 | echo Stopping PostgreSQL |
20 | pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} stop | 22 | pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} stop || true |
21 | 23 | ||
22 | echo Cleaning up old cluster directory | 24 | echo Cleaning up old cluster directory |
23 | sudo -u postgres mv /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}{,_$BACKUP_DATE} | 25 | sudo -u postgres mv /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}{,_$BACKUP_DATE} |
@@ -28,8 +30,10 @@ sudo -u postgres mkdir -p /var/lib/postgresql/{{ postgres_version }}/{{ postgres | |||
28 | echo Get previous backup from backups server | 30 | echo Get previous backup from backups server |
29 | sudo -u postgres \ | 31 | sudo -u postgres \ |
30 | time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete \ | 32 | time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete \ |
33 | {% if postgres_barman_rsync_enabled|default(false) -%} | ||
31 | --password-file=/var/lib/postgresql/.rsync_pass \ | 34 | --password-file=/var/lib/postgresql/.rsync_pass \ |
32 | rsync://barman@{{ postgres_barman_server }}/backups/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \ | 35 | {%- endif %} |
36 | {% if postgres_barman_rsync_enabled|default(false) -%}rsync://{%- endif -%}barman@{{ postgres_barman_server }}{%- if postgres_barman_rsync_enabled|default(false) -%}/backups{%- else -%}:~{%- endif -%}/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \ | ||
33 | /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/ | 37 | /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/ |
34 | 38 | ||
35 | echo Restoring .conf and server certificate | 39 | echo Restoring .conf and server certificate |