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

Benjamin Renard commited on 2018-01-30 16:45:15
Showing 1 changed files, with 12 additions and 1 deletions.

... ...
@@ -20,6 +20,7 @@
20 20
 #
21 21
 
22 22
 PG_USER=postgres
23
+PG_MASTER_USER=""
23 24
 PSQL_BIN=/usr/bin/psql
24 25
 PG_MAIN=/var/lib/postgresql/9.1/main
25 26
 if [ -f /etc/debian_version ]
... ...
@@ -48,6 +49,7 @@ Usage : $0 [-d] [-h] [options]
48 49
                                 $PG_MAIN)
49 50
 	-r recovery_conf	Specify Postgres recovery configuration file path
50 51
 				(Default : [PG_MAIN]/$RECOVERY_CONF_FILENAME)
52
+	-U pg_master_user	Specify Postgres user to use on master (Default : user from recovery.conf file)
51 53
 	-p pg_port		Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT)
52 54
 	-D dbname		Specify DB name on Postgres master/slave to connect on (Default : PG_USER)
53 55
 	-d			Debug mode
... ...
@@ -56,7 +58,7 @@ EOF
56 58
 	exit 0
57 59
 }
58 60
 
59
-while getopts "hu:b:m:r:p:D:d" OPTION
61
+while getopts "hu:b:m:r:U:p:D:d" OPTION
60 62
 do
61 63
 	case $OPTION in
62 64
 		u)
... ...
@@ -71,6 +73,9 @@ do
71 73
 		r)
72 74
 			RECOVERY_CONF=$OPTARG
73 75
 		;;
76
+		U)
77
+			PG_MASTER_USER=$OPTARG
78
+		;;
74 79
 		p)
75 80
 			PG_DEFAULT_PORT=$OPTARG
76 81
 		;;
... ...
@@ -188,6 +193,11 @@ then
188 193
 		debug "Master port : $M_PORT"
189 194
 	fi
190 195
 
196
+	if [ -n "$PG_MASTER_USER" ]
197
+	then
198
+		debug "Master user provided by command-line, use it : $PG_MASTER_USER"
199
+		M_USER="$PG_MASTER_USER"
200
+	else
191 201
 		M_USER=$( echo "$MASTER_CONN_INFOS"|sed 's/^.*user= *\([^ ]*\) *.*$/\1/' )
192 202
 		if [ ! -n "$M_USER" ]
193 203
 		then
... ...
@@ -196,6 +206,7 @@ then
196 206
 		else
197 207
 			debug "Master user : $M_USER"
198 208
 		fi
209
+	fi
199 210
 	
200 211
 	# Get current xlog file from master
201 212
 	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" )"
202 213