#!/bin/sh for i in "$@" do case $i in --scope=*) SCOPE="${i#*=}" shift # past argument=value ;; --role=*) ROLE="${i#*=}" shift # past argument=value ;; --datadir=*) DATADIR="${i#*=}" shift # past argument=value ;; --connstring=*) CONNSTR="${i#*=}" shift # past argument=value ;; *) # unknown option ;; esac done # support both '-' and '/' as separator if [ $(echo $SCOPE | grep -- -) ] then VERSION=$(echo $SCOPE | sed -e 's/-.*//') CLUSTER=$(echo $SCOPE | sed -e 's/.*-//') else VERSION=$(echo $SCOPE | sed -e 's/\/.*//') CLUSTER=$(echo $SCOPE | sed -e 's/.*\///') fi if [ -f /etc/postgresql/$VERSION/$CLUSTER/postgresql.conf ] then pg_dropcluster $VERSION $CLUSTER fi pg_createcluster --start-conf=manual $VERSION $CLUSTER && rm -rf $DATADIR && pg_basebackup --pgdata $DATADIR -X stream --dbname=$CONNSTR exit $?