Annotation of badi/public_scripts/parallelstarter/db_backup/generate_arglist, revision 1.2

1.1       adi         1: # Prepare db_backup to be run with parallelstarter:
                      2: # generate arglist from password file
                      3: 
                      4: # step through DBLIST and convert each line 
                      5: # into a set of command line args for db_backup
                      6: 
1.2     ! adi         7: 
        !             8: # the default ports
        !             9: function getdefault_dbport { 
        !            10:        if [ "$DBTYPE" = "mysql" ]; then
        !            11:                echo -n "3306"
        !            12:        elif [ "$DBTYPE" = "postgresql" ]; then
        !            13:                echo -n "5432"
        !            14:        fi
        !            15: }
        !            16: 
        !            17: 
1.1       adi        18: if [ -e "$ARGLIST_FILE" ]; then
                     19:        rm "$ARGLIST_FILE"
                     20: fi
                     21: 
                     22: while read dbinfo; do
                     23: 
                     24:        # ignore comment and empty lines
                     25:        if [ $(echo "$dbinfo" | egrep -c "^[ \t]*#.*$") -gt 0 ]; then
                     26:               continue
                     27:        fi
                     28:        
                     29:        # ignore empty lines or malformed lines
                     30:        if [ $(echo "$dbinfo" | sed 's/[^:]//g' | wc -m) -lt 4 ]; then
                     31:                continue
                     32:        fi
                     33: 
1.2     ! adi        34:        curhost="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $1}')`"
        !            35:     curdb="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $3}')`"
        !            36:     curuser="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $4}')`"
        !            37:     curtype="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $2}')`"
        !            38:        curpw="`echo $(echo "$dbinfo" | awk -F ' : ' '{print $5}')`"
1.1       adi        39: 
1.2     ! adi        40:        curport="$(echo "$curhost" | sed -e "s/.*:\([0-9]\{1,\}\) *$/\1/")"
        !            41:        if [ "$curhost" = "$curport" ]; then
        !            42:                curport="$(getdefault_dbport)"
        !            43:        else
        !            44:                # remove port information from host string
        !            45:                curhost="$(echo "$curhost" | sed -e "s/\(.*\):[0-9]\{1,\} *$/\1/")"             
        !            46:        fi
        !            47:        echo "-h $curhost -p $curport -D $curdb -u $curuser -c $DBLIST -t $curtype" >> "$ARGLIST_FILE"
1.1       adi        48:        
                     49:        # write .pgpass in case there is a PostgreSQL DB involved
                     50:        if [ "$curtype" = "postgresql" ]; then
                     51:                # see if password is already registered
                     52:                if [ ! -e "$HOME/.pgpass" ]; then
                     53:                        touch "$HOME/.pgpass"
                     54:                        chmod 600 "$HOME/.pgpass"
                     55:                fi
1.2     ! adi        56:                if [ $(grep -c "$curhost:$curport:$curdb:$curuser" "$HOME/.pgpass") -eq 0 ]; then
1.1       adi        57:                        # add the line to .pgpass
1.2     ! adi        58:                        echo "$curhost:$curport:$curdb:$curuser:$curpw" >> "$HOME/.pgpass"
        !            59:                elif [ $(grep -c "$curhost:$curport:$curdb:$curuser:$curpw" "$HOME/.pgpass") -eq 0 ]; then
1.1       adi        60:                        # the pw has changed; replace the password with new value
                     61:                        mv "$HOME/.pgpass" "$HOME/.pgpass.old"
                     62:                        touch "$HOME/.pgpass"
                     63:                        chmod 600 "$HOME/.pgpass"
1.2     ! adi        64:                        grep -v "$curhost:$curport:$curdb:$curuser" "$HOME/.pgpass.old" >> "$HOME/.pgpass"
        !            65:                        echo "$curhost:$curport:$curdb:$curuser:$curpw" >> "$HOME/.pgpass"
1.1       adi        66:                fi
                     67:        fi
                     68: 
                     69: done < "$DBLIST"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>