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