aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates/standby-clone.sh.j2
diff options
context:
space:
mode:
authorPaul B <paul.bonaud@capitainetrain.com>2018-08-31 11:49:09 +0200
committerPaul B <paul.bonaud@capitainetrain.com>2018-08-31 12:00:24 +0200
commitd0bc90e08c29e881c388c6803ed9c49dff1f1776 (patch)
treee5f633a7461f3d339ef89758fc7bb3f1b91563d3 /templates/standby-clone.sh.j2
downloadansible-postgresql-role-1.0.0.tar.gz
ansible-postgresql-role-1.0.0.tar.zst
ansible-postgresql-role-1.0.0.zip
Initial commit open sourcing Postgresql Ansible role1.0.0
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