patroni/debian/pg_clonecluster_patroni
Michael Banck aa2d5bc588 * debian/pg_clonecluster_patroni: Always use explicit pg_basebackup version,
in case more than one major version of PostgreSQL is installed.
2020-05-08 15:35:07 +02:00

45 lines
972 B
Bash
Executable file

#!/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 --datadir=$DATADIR $VERSION $CLUSTER && rm -rf $DATADIR && /usr/lib/postgresql/$VERSION/bin/pg_basebackup --pgdata $DATADIR -X stream --dbname="$CONNSTR"
exit $?