Add -U parameter to provide user to use on master host

This commit is contained in:
Benjamin Renard 2018-01-30 17:45:15 +01:00
parent 4efda74bf6
commit 690811ccfb

View file

@ -20,6 +20,7 @@
#
PG_USER=postgres
PG_MASTER_USER=""
PSQL_BIN=/usr/bin/psql
PG_MAIN=/var/lib/postgresql/9.1/main
if [ -f /etc/debian_version ]
@ -48,6 +49,7 @@ Usage : $0 [-d] [-h] [options]
$PG_MAIN)
-r recovery_conf Specify Postgres recovery configuration file path
(Default : [PG_MAIN]/$RECOVERY_CONF_FILENAME)
-U pg_master_user Specify Postgres user to use on master (Default : user from recovery.conf file)
-p pg_port Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT)
-D dbname Specify DB name on Postgres master/slave to connect on (Default : PG_USER)
-d Debug mode
@ -56,7 +58,7 @@ EOF
exit 0
}
while getopts "hu:b:m:r:p:D:d" OPTION
while getopts "hu:b:m:r:U:p:D:d" OPTION
do
case $OPTION in
u)
@ -71,6 +73,9 @@ do
r)
RECOVERY_CONF=$OPTARG
;;
U)
PG_MASTER_USER=$OPTARG
;;
p)
PG_DEFAULT_PORT=$OPTARG
;;
@ -188,6 +193,11 @@ then
debug "Master port : $M_PORT"
fi
if [ -n "$PG_MASTER_USER" ]
then
debug "Master user provided by command-line, use it : $PG_MASTER_USER"
M_USER="$PG_MASTER_USER"
else
M_USER=$( echo "$MASTER_CONN_INFOS"|sed 's/^.*user= *\([^ ]*\) *.*$/\1/' )
if [ ! -n "$M_USER" ]
then
@ -196,6 +206,7 @@ then
else
debug "Master user : $M_USER"
fi
fi
# Get current xlog file from master
M_CUR_XLOG="$( echo 'SELECT pg_current_xlog_location()'|su - $PG_USER -c "$PSQL_BIN -U $M_USER -h $M_HOST -p $M_PORT -d $PG_DB -t -P format=unaligned" )"