--- badi/public_scripts/parallelstarter/db_backup/generate_arglist 2011/07/18 11:49:04 1.1 +++ badi/public_scripts/parallelstarter/db_backup/generate_arglist 2012/09/06 20:23:54 1.2 @@ -4,6 +4,17 @@ # step through DBLIST and convert each line # into a set of command line args for db_backup + +# the default ports +function getdefault_dbport { + if [ "$DBTYPE" = "mysql" ]; then + echo -n "3306" + elif [ "$DBTYPE" = "postgresql" ]; then + echo -n "5432" + fi +} + + if [ -e "$ARGLIST_FILE" ]; then rm "$ARGLIST_FILE" fi @@ -20,13 +31,20 @@ while read dbinfo; do continue fi - curhost="`echo $(echo "$dbinfo" | awk -F ':' '{print $1}')`" - curdb="`echo $(echo "$dbinfo" | awk -F ':' '{print $3}')`" - curuser="`echo $(echo "$dbinfo" | awk -F ':' '{print $4}')`" - curtype="`echo $(echo "$dbinfo" | awk -F ':' '{print $2}')`" - curpw="`echo $(echo "$dbinfo" | awk -F ':' '{print $5}')`" - - echo "-h $curhost -D $curdb -u $curuser -c $DBLIST -t $curtype" >> "$ARGLIST_FILE" + curhost="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $1}')`" + curdb="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $3}')`" + curuser="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $4}')`" + curtype="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $2}')`" + curpw="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $5}')`" + + curport="$(echo "$curhost" | sed -e "s/.*:\([0-9]\{1,\}\) *$/\1/")" + if [ "$curhost" = "$curport" ]; then + curport="$(getdefault_dbport)" + else + # remove port information from host string + curhost="$(echo "$curhost" | sed -e "s/\(.*\):[0-9]\{1,\} *$/\1/")" + fi + echo "-h $curhost -p $curport -D $curdb -u $curuser -c $DBLIST -t $curtype" >> "$ARGLIST_FILE" # write .pgpass in case there is a PostgreSQL DB involved if [ "$curtype" = "postgresql" ]; then @@ -35,16 +53,16 @@ while read dbinfo; do touch "$HOME/.pgpass" chmod 600 "$HOME/.pgpass" fi - if [ $(grep -c "$curhost:$PGPORT:$curdb:$curuser" "$HOME/.pgpass") -eq 0 ]; then + if [ $(grep -c "$curhost:$curport:$curdb:$curuser" "$HOME/.pgpass") -eq 0 ]; then # add the line to .pgpass - echo "$curhost:$PGPORT:$curdb:$curuser:$curpw" >> "$HOME/.pgpass" - elif [ $(grep -c "$curhost:$PGPORT:$curdb:$curuser:$curpw" "$HOME/.pgpass") -eq 0 ]; then + echo "$curhost:$curport:$curdb:$curuser:$curpw" >> "$HOME/.pgpass" + elif [ $(grep -c "$curhost:$curport:$curdb:$curuser:$curpw" "$HOME/.pgpass") -eq 0 ]; then # the pw has changed; replace the password with new value mv "$HOME/.pgpass" "$HOME/.pgpass.old" touch "$HOME/.pgpass" chmod 600 "$HOME/.pgpass" - grep -v "$curhost:$PGPORT:$curdb:$curuser" "$HOME/.pgpass.old" >> "$HOME/.pgpass" - echo "$curhost:$PGPORT:$curdb:$curuser:$curpw" >> "$HOME/.pgpass" + grep -v "$curhost:$curport:$curdb:$curuser" "$HOME/.pgpass.old" >> "$HOME/.pgpass" + echo "$curhost:$curport:$curdb:$curuser:$curpw" >> "$HOME/.pgpass" fi fi