# This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Jack Parker on Thu Apr 27 13:46:54 1995 # # This archive contains: # pres_ext # LANG=""; export LANG PATH=/bin:/usr/bin:$PATH; export PATH echo x - pres_ext cat >pres_ext <<'@EOF' ############################################################################ # # pres_ext: PREServe EXTents. This is a shell script to generate an SQL # command file (suitable for dbimport) which preserves the # dbspace, first extent and (what we really wanted) next extent # info. # # pres_ext usage: pres_ext database [$TBCONFIG] # # Notes: It is advised that you check the output very carefully before running # it. Output is written to newschema.sql. Currently none of the # temporary files are removed - just so you can test. # # Not all awks were created equal and this script uses a lot of awk. # check to ensure that it does what its supposed to. # # This is offered to the world at large. No warranties expressed or implied. # If you run the SQL command and it trashes your database NMFP. The reason # for offering this is so that y'all can tell me what's wrong with it so # WE won't have problems with it. I therefore ask that you let me know # how it works and any problems you run into. I will make updates available. # # 4/27/95 JP. can have multiple dbspaces for the schema. Therefore # no longer accept it on the command line, read it out of the tbcheck output # # # Jack Parker jparker@hpbs2561.boi.hp.com ############################################################################ # JP 4/27/95 - removed dbspace from parameters if [ $# -lt 1 ] then echo "pres_ext usage: pres_ext database [$TBCONFIG]" exit -1 fi database=$1 if [ $# -eq 2 ] then TBCONFIG=$2 elif [ -z "$TBCONFIG" ] then echo "TBCONFIG is not set" exit -1 fi tbcnf=$INFORMIXDIR/etc/$TBCONFIG if [ ! -r "$tbcnf" ] then echo "Can't read $tbcnf" echo "file is not readable by this process." exit -1 fi echo "Setting page size..." pgsize=`grep BUFFSIZE $INFORMIXDIR/etc/$TBCONFIG | awk '{print $2}'` pgsize=`expr $pgsize / 1024` # this give you a sorted of each table and how many extents. # the awk file adds the duplicated tablename extents together. # the grep -v "WARNING" gets rid of the WARNING messages. rls=`grep Version $INFORMIXDIR/etc/OnLine-cr | awk '{print substr($3,1,1)}'` # 4/27/95 JP save tbcheck info to get dbspace out. echo "Getting table names and extent use..." tbcheck -pe > tbchk.out grep $database tbchk.out | sort | awk ' BEGIN { old_tab="XXXXXXXXXX" old_ext=0 } { # # check for "." vs ":", if ":" then is online 4.0 use tab[3] # perhaps check release_level instead? # Note: this fix is untested. # if ( rls > 4 ) { n=split($1,tab,".") tabname=tab[2] } else { n=split($1,tab,":") tabname=tab[3] } if (tabname != old_tab) { if (NR > 1) { print old_tab, old_ext } old_ext=0 } old_tab=tabname old_ext+=$3 } END { print old_tab, old_ext } ' rls=$rls | grep -v "WARNING" > extents # we still don't have nextsize. get it. echo "getting next extent size..." echo "select tabname, nextsize from informix.systables where tabid > 99" > tmp.sql isql -s $database tmp > nextsize rm -f tmp.sql ######################################################################## # 4/27/95 still need dbspace info, read the tbcheck.out info # it will have 'DBSpace Usage Report: dbspacename # followed by tables in that dbspace. Build these into extents4 # since I don't like serial i/o what we'll do is figure out what # line each dbspace starts on and then grep for tablenames # between them taking the first occurence of the tablename as # an indicator of what dbspace to put it into echo "getting dbspace names..." # 1 # Get the line numbers that the dbspaces occur on # stick into an array let idx=1 grep -n DBSpace tbchk.out | grep -v RESERVED | awk ' { n=split($1,dbsp,":") print dbsp[1], $4 }' | while read dbspc_info do dbln[idx]=`echo $dbspc_info | cut -d" " -f1` dbsp[idx]=`echo $dbspc_info | cut -d" " -f2` let "idx = $idx + 1" done # 2 # for each tablename... cat extents | awk '{print $1}' | sort -u | while read tabname do grep -n $tabname tbchk.out | read first # could get multiple lines here.... ln_no=`echo $first | awk -F: '{print $1}'` i=1 while [ $ln_no -gt ${dbln[$i]} -a $i -le ${#dbln[*]} ] do let "i=$i+1" done # answer is now ${dbsp[i-1]} let "i = $i - 1" echo $tabname ${dbsp[i]} done > spaces ######################################################################## echo "retrieving schema..." dbschema -d $database > $database.schm # the schema is in any old order - the extent files # are guaranteed not to match. We want to do serial I/O later on # so we need them in the same order. Make it so.... echo "putting together table, extent, and dbspace info..." grep "create" $database.schm |grep "table" | while read tabname do tab=`echo $tabname | awk '{ n=split($3,tab,".") print tab[2]}'` grep "^$tab " extents >> extents2 grep "^$tab " nextsize >> extents2 grep "^$tab " spaces >> extents2 # 4/27 change JP done # we now have a file with every THIRD line being the nextsize # and in the same order as the schema file. join these lines # so that we have "table first_ext next_ext" awk ' BEGIN { old_tabname = "" lnno=1} { tabname = $1 if ( lnno == 1 ) { ext=$2 } if ( lnno == 2 ) { old_ext = $2 } if ( lnno == 3 ) { spc=$2 print tabname, old_ext, ext, spc lnno = 0 } lnno += 1 } ' < extents2 > extents3 # now we read the schema - each time we run into the last line of # a CREATE TABLE we tack on the extent and dbspace info. #(sunos needs nawk here) echo "making a new schema..." awk ' { if ( $1 == "create" && $2 == "table" ) { n = split($3,tb,".") tbname = tb[2] exteof = getline extline < "extents3" n = split(extline, inline) if (inline[1] == tbname) { fxt = inline[2] nxt = inline[3] dbspace = inline[4] } else print "Wrong table ! " tbname inline[1] } if ( $1 == ");") print ") IN " dbspace " EXTENT SIZE " fxt*pgsize " NEXT SIZE " nxt*pgsize ";" else print $0 }' < $database.schm pgsize=$pgsize > newschema.sql # clean up # rm -f extents extents2 extents3 nextsize $database.schm tbchk.out spaces @EOF chmod 700 pres_ext exit 0