# start pg_restore and copy over everything # Updated by Mike Gore, 6Dec 2010 added --disable-triggers # http://us.generation-nt.com/answer/bug-579768-pg-upgradecluster-disable-triggers-help-197808691.html my @restore_argv = ($pg_restore, '-h', $newsocket, '-p', $newinfo{'port'},'--disable-triggers', '--data-only', '-d', $db);
#!/bin/bash # TMP=/tmp/$$.tmp SCRIPT=/tmp/$$.script trap 'cleanup' 0 1 2 3 15 cleanup() { rm -f "$TMP" "$SCRIPT" } count_comma() { awk ' BEGIN { count=0; quote=0} { for (i=1;i<=length($0);i++) { if(substr($0,i,1)=="\"") { quote=!quote; continue}; if(substr($0,i,1)=="," && quote==0) {count++;} } } END {print count} ' $1 } echo \#=========================================================== >>"$SCRIPT" echo \# USERS >>"$SCRIPT" OUR_USERS=`egrep "^[A-Za-z0-9-]+:" /etc/passwd | cut -d: -f1 | sort -u` # TMP file for groups for NAME in $OUR_USERS do # echo NAME=$NAME # Get every line that has NAME in it - cut the group name PUID=`egrep "^$NAME:" /etc/passwd | cut -d: -f3` PGID=`egrep "^$NAME:" /etc/passwd | cut -d: -f4` PHOME=`grep "^$NAME:" /etc/passwd | cut -d: -f6` if [ -n $PUID -a $PUID -gt 500 -a $PUID -lt 2000 ]; then SPASS=`grep "^$NAME:" /etc/shadow | cut -d: -f2` echo useradd -m -d $PHOME -u $PUID -p \'"$SPASS"\' "$NAME" >>"$SCRIPT" fi done echo \#=========================================================== >>"$SCRIPT" echo \# GROUPS >>"$SCRIPT" OUR_GROUPS=`egrep "^[A-Za-z0-9-]+:" /etc/group | cut -d: -f1 | sort -u` #echo "$OUR_GROUPS" #Build script to create all users for NAME in $OUR_GROUPS do PGID=`egrep "^$NAME:" /etc/group | cut -d: -f3` # Count # of group members PGIDS=`egrep "^$NAME:" /etc/group | cut -d: -f4- | count_comma` # echo PGIDS=$PGIDS # echo PGID=$PGID if [ -n $PGID -a $PGID -gt 500 -a $PGID -lt 2000 ]; then if [ -n $PGIDS -a $PGIDS -gt 1 ]; then egrep "^$NAME:" /etc/group >>"$SCRIPT" fi fi done cat $SCRIPT cleanup