aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--defaults/main.yml1
-rw-r--r--tasks/postgres-standby-barman.yml1
-rwxr-xr-xtemplates/standby-clone.sh.j28
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: []
6# postgres_log_dir: ~ 6# postgres_log_dir: ~
7# postgres_pgbadger_server: ~ 7# postgres_pgbadger_server: ~
8postgres_backup_enabled: false 8postgres_backup_enabled: false
9postgres_barman_rsync_enabled: false
9#------------------------------------------------------------# 10#------------------------------------------------------------#
10#------------ Postgresql Configuration defaults -------------# 11#------------ Postgresql Configuration defaults -------------#
11#- WARNING: defaults can change with major version upgrades -# 12#- 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 @@
10 group: postgres 10 group: postgres
11 mode: 0400 11 mode: 0400
12 no_log: True 12 no_log: True
13 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 @@
1#!/bin/bash 1#!/bin/bash
2# {{ ansible_managed }} 2# {{ ansible_managed }}
3 3
4set -eo pipefail
5
4BARMAN_DATABASE=$1 6BARMAN_DATABASE=$1
5BARMAN_BACKUP_VERSION=$2 7BARMAN_BACKUP_VERSION=$2
6 8
@@ -17,7 +19,7 @@ echo "accept key if necessary"
17sudo -u postgres ssh barman@{{ postgres_barman_server }} echo "" 19sudo -u postgres ssh barman@{{ postgres_barman_server }} echo ""
18 20
19echo Stopping PostgreSQL 21echo Stopping PostgreSQL
20pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} stop 22pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} stop || true
21 23
22echo Cleaning up old cluster directory 24echo Cleaning up old cluster directory
23sudo -u postgres mv /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}{,_$BACKUP_DATE} 25sudo -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
28echo Get previous backup from backups server 30echo Get previous backup from backups server
29sudo -u postgres \ 31sudo -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
35echo Restoring .conf and server certificate 39echo Restoring .conf and server certificate