aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates/standby-barman-clone.sh.j2
diff options
context:
space:
mode:
Diffstat (limited to 'templates/standby-barman-clone.sh.j2')
-rwxr-xr-xtemplates/standby-barman-clone.sh.j245
1 files changed, 45 insertions, 0 deletions
diff --git a/templates/standby-barman-clone.sh.j2 b/templates/standby-barman-clone.sh.j2
new file mode 100755
index 0000000..2db44b6
--- /dev/null
+++ b/templates/standby-barman-clone.sh.j2
@@ -0,0 +1,45 @@
1#!/bin/bash
2# {{ ansible_managed }}
3
4set -eo pipefail
5
6BARMAN_DATABASE=$1
7BARMAN_BACKUP_VERSION=$2
8
9if [[ -z $BARMAN_DATABASE || -z $BARMAN_BACKUP_VERSION ]]
10then
11 echo "Usage : $0 BARMAN_DATABASE BARMAN_BACKUP_VERSION" >&2
12 echo " Example: $0 25kv 20161118T002405" >&2
13 exit 1
14fi
15
16BACKUP_DATE=`date +%s`
17
18echo "accept key if necessary"
19sudo -u postgres ssh barman@{{ postgres_barman_server }} echo ""
20
21echo Stopping PostgreSQL
22pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} stop || true
23
24echo Cleaning up old cluster directory
25sudo -u postgres mv /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}{,_$BACKUP_DATE}
26
27echo Creating new directory
28sudo -u postgres mkdir -p /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}
29
30echo Get previous backup from backups server
31sudo -u postgres \
32 time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete {{ rsync_options }} \
33 {{ barman_remote_url }}/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \
34 /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/
35
36echo Restoring .conf and server certificate
37sudo -u postgres cp -a /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}_$BACKUP_DATE/{*.conf,server.crt,server.key} /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/
38
39echo Ensure rights are correcly set
40chown -R postgres:postgres /var/lib/postgresql/{{ postgres_version }}/
41chmod 0700 /var/lib/postgresql/{{ postgres_version }}/
42chmod -R o-rwx /var/lib/postgresql/{{ postgres_version }}/
43
44echo Starting PostgreSQL
45sudo pg_ctlcluster {{ postgres_version }} {{ postgres_cluster_name }} start