Annotation of badi/public_scripts/parallelstarter/db_backup/generate_arglist, revision 1.1.1.1
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:
7: if [ -e "$ARGLIST_FILE" ]; then
8: rm "$ARGLIST_FILE"
9: fi
10:
11: while read dbinfo; do
12:
13: # ignore comment and empty lines
14: if [ $(echo "$dbinfo" | egrep -c "^[ \t]*#.*$") -gt 0 ]; then
15: continue
16: fi
17:
18: # ignore empty lines or malformed lines
19: if [ $(echo "$dbinfo" | sed 's/[^:]//g' | wc -m) -lt 4 ]; then
20: continue
21: fi
22:
23: curhost="`echo $(echo "$dbinfo" | awk -F ':' '{print $1}')`"
24: curdb="`echo $(echo "$dbinfo" | awk -F ':' '{print $3}')`"
25: curuser="`echo $(echo "$dbinfo" | awk -F ':' '{print $4}')`"
26: curtype="`echo $(echo "$dbinfo" | awk -F ':' '{print $2}')`"
27: curpw="`echo $(echo "$dbinfo" | awk -F ':' '{print $5}')`"
28:
29: echo "-h $curhost -D $curdb -u $curuser -c $DBLIST -t $curtype" >> "$ARGLIST_FILE"
30:
31: # write .pgpass in case there is a PostgreSQL DB involved
32: if [ "$curtype" = "postgresql" ]; then
33: # see if password is already registered
34: if [ ! -e "$HOME/.pgpass" ]; then
35: touch "$HOME/.pgpass"
36: chmod 600 "$HOME/.pgpass"
37: fi
38: if [ $(grep -c "$curhost:$PGPORT:$curdb:$curuser" "$HOME/.pgpass") -eq 0 ]; then
39: # add the line to .pgpass
40: echo "$curhost:$PGPORT:$curdb:$curuser:$curpw" >> "$HOME/.pgpass"
41: elif [ $(grep -c "$curhost:$PGPORT:$curdb:$curuser:$curpw" "$HOME/.pgpass") -eq 0 ]; then
42: # the pw has changed; replace the password with new value
43: mv "$HOME/.pgpass" "$HOME/.pgpass.old"
44: touch "$HOME/.pgpass"
45: chmod 600 "$HOME/.pgpass"
46: grep -v "$curhost:$PGPORT:$curdb:$curuser" "$HOME/.pgpass.old" >> "$HOME/.pgpass"
47: echo "$curhost:$PGPORT:$curdb:$curuser:$curpw" >> "$HOME/.pgpass"
48: fi
49: fi
50:
51: done < "$DBLIST"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>