From c95984df57136048002f0d60c6469d9bbbdd1e0a Mon Sep 17 00:00:00 2001 From: Paul B Date: Fri, 28 Dec 2018 15:30:13 +0100 Subject: standby: rsync from barman is optional if SSH access is already here --- defaults/main.yml | 1 + tasks/postgres-standby-barman.yml | 1 + templates/standby-clone.sh.j2 | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 59db662..190ce5f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,6 +6,7 @@ postgres_clusters: [] # postgres_log_dir: ~ # postgres_pgbadger_server: ~ postgres_backup_enabled: false +postgres_barman_rsync_enabled: false #------------------------------------------------------------# #------------ Postgresql Configuration defaults -------------# #- WARNING: defaults can change with major version upgrades -# diff --git a/tasks/postgres-standby-barman.yml b/tasks/postgres-standby-barman.yml index 793b942..65e87a6 100644 --- a/tasks/postgres-standby-barman.yml +++ b/tasks/postgres-standby-barman.yml @@ -10,3 +10,4 @@ group: postgres mode: 0400 no_log: True + when: postgres_barman_rsync_enabled 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 @@ #!/bin/bash # {{ ansible_managed }} +set -eo pipefail + BARMAN_DATABASE=$1 BARMAN_BACKUP_VERSION=$2 @@ -17,7 +19,7 @@ echo "accept key if necessary" sudo -u postgres ssh barman@{{ postgres_barman_server }} echo "" echo Stopping PostgreSQL -pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} stop +pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} stop || true echo Cleaning up old cluster directory 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 echo Get previous backup from backups server sudo -u postgres \ time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete \ +{% if postgres_barman_rsync_enabled|default(false) -%} --password-file=/var/lib/postgresql/.rsync_pass \ - rsync://barman@{{ postgres_barman_server }}/backups/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \ +{%- endif %} + {% 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/ \ /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/ echo Restoring .conf and server certificate -- cgit v1.2.3