View Single Post

   
  #3 (permalink)  
Old 04-20-2008, 03:59 PM
Pete
 
Posts: n/a
Default Re: Script to build script for cdr def repl statements

Thanks, Frank.

I've also written a script (shown below) that works by taking some
examples from a former DBA that worked on our system and adding to some
of his scripts. Only downside (if you call it that) was you have to
have some sort of "naming convention" for the replicates (so you know
what database to use for the replicate), in order to build the cdr
statements, then by chewing thru the output of '"cdr list repl brief
"replicate_name"' it will create the needed statements. All of our
replicates stick with a specific naming convention, and as long as
anybody who creates a replicate sticks to that convention... There is
probably some overkill here, but like I said, it appears to work and
output the correct statements/etc. Better than what we had before,
which was basically nothing.

#!/bin/ksh
#
# This script will recreate the cdr statements to rebuild all
replicates.
#
###
SERVER=`uname -n`
###
# output filenames
###
CR8_REPL="/tmp/cr8_${SERVER}_replications.sh"
START_REPL="/tmp/start_${SERVER}_replications.sh"
DTELINE=`date`
echo "############################################# " >${CR8_REPL}
echo "# File created by $0 on $DTELINE" >>${CR8_REPL}
echo "############################################# " >>${CR8_REPL}
echo "############################################# " >${START_REPL}
echo "# File created by $0 on $DTELINE" >>${START_REPL}
echo "############################################# " >>${START_REPL}
###
# first, run the cdr statements to display all replicates defined. Put
# output in a file.
######
# If debug is needed, before running script, from command line run:
# export DEBUG=1
# if above set, and you want to 'turn it off', run "unset DEBUG" from
cmd line
######
cd /tmp
if [ -n "${DEBUG}" ]; then # assumed file already created.
echo;
echo "DEBUG *** Using ${SERVER}_replicates.txt ...";
else # No debug, so create file from scratch..
rm ${SERVER}_replicates.txt
for i in `cdr list repl|grep -v REP|grep -v "\--"|awk '{print $1}'`
do
cdr list repl brief $i >> ${SERVER}_replicates.txt
done
fi;
###
# rip out anything NOT related to an actual replicate.
###
cat ${SERVER}_replicates.txt|grep -v "\-\-"|grep -v REPLI|grep -v
SELECT > ${SERVER}_replicates_raw.txt
###
# read above created file and build statements needed to rebuild all
replicates
# Note: Each "replicate" pair is in groups of 4 lines, so pull needed
info
# from each line, then after each group of 4 is read, build the
cdr
# statements.
###
LINE_NUM=0
cat ${SERVER}_replicates_raw.txt |
while read REPL_LINE
do
###
# increment line counter
###
LINE_NUM=$((LINE_NUM +1 ))
IFS=" "
set $REPL_LINE
###
# if LINE_NUM = 1, pull out REPL_NAME, main server (HERE, i.e
"servA"),
# and TABle name
###
if [ ${LINE_NUM} -eq 1 ];then
REPL_NAME=$1
HERE=$2
TAB=$4
fi
###
# if LINE_NUM = 2, pull out select statement SQL
###
if [ ${LINE_NUM} -eq 2 ];then
SQL=$1
fi
###
# if LINE_NUM = 3, pull out TARGet (i.e. "servB")
###
if [ ${LINE_NUM} -eq 3 ];then
TARG=$2
fi
###
# if LINE_NUM = 4, then build the replicate statement and reset
LINE_NUM
###
if [ ${LINE_NUM} -eq 4 ];then
LINE_NUM=0 # reset counter
###
# pull out database alias and create PREFIX for cdr statement
###
REP_NAME=`echo $REPL_NAME|awk -F"_" '{print $1}'`
case $REP_NAME in
"cust") PREFIX="custdb";;
"misc") PREFIX="miscdb";;
"ord") PREFIX="orderdb";;
*) PREFIX="UNKNOWN_DB";; # this will have to be looked
for
esac # in the output and adjusted!
###
# build cdr statements
###
if [ -n "${DEBUG}" ]; then # DEBUG mode, display to screen
T1="$PREFIX""@""$TARG"":root."${TAB};
T2="$PREFIX""@""$HERE"":root."${TAB};
SQL="select * from ${TAB}";
echo cdr def repl -c $TARG -C timestamp -S row -R -A $REPL_NAME
\\;
echo "\"$T1\"" "\"$SQL\"" \\;
echo "\"$T2\"" "\"$SQL\""\;
echo;
echo "cdr start command:";
echo "cdr start repl ${REPL_NAME}"
echo;
else
echo "#--- $REPL_NAME" >> ${CR8_REPL}
echo "echo $REPL_NAME" >> ${CR8_REPL}
T1="$PREFIX""@""$TARG"":root."${TAB};
T2="$PREFIX""@""$HERE"":root."${TAB};
SQL="select * from ${TAB}";
echo cdr def repl -c $TARG -C timestamp -S row -R -A $REPL_NAME
\\ >> ${CR8_REPL};
echo "\"$T1\"" "\"$SQL\"" \\ >> ${CR8_REPL};
echo "\"$T2\"" "\"$SQL\""\ >> ${CR8_REPL};
echo "cdr start repl ${REPL_NAME}">> ${START_REPL}
fi
fi
IFS="" # reset field separator
done


FRANK wrote:
> Pete,
>
> You can use a script language, e.g., PERL, to access syscdr:repdef,
> partdef tables and produce a script file that contains the cdr statements
> you want. Very straight forward.
>
> Frank
>
>
> On 12 Jan 2007 11:51:04 -0800, ole-racefan <pete.dickson.ats@gmail.com>
> wrote:
> >
> > Is there any scripts around that will chew thru current replicates and
> > create the cdr statements necessary to rebuild all replicates?
> >
> > I can write a script to check thru a "cdr list repl" list and rebuild
> > but I figured that should be a way to rebuild without inventing
> > something that already exists. I've been digging around for awhile
> > looking for one. All of our replicates are pretty much the same in that
> > they use timestamp and "select * from xxxx".
> >
> > OS: AIX 4.3.3 (yeah, don't bust my stones, I know it's a unsupported
> > version of AIX. Will be on 5.2 in a few weeks/months).
> > Informix Dynamic Server 2000 Version 9.21.UC5XF (yeah, same here.
> > Unfortunetly have to rely on a 3rd party VENDOR to get us upgraded to
> > 9.4. Then to 10).
> >
> > Pete
> >
> > _______________________________________________
> > Informix-list mailing list
> > Informix-list@iiug.org
> > http://www.iiug.org/mailman/listinfo/informix-list
> >

>
> ------=_Part_112081_17573367.1168899774828
> Content-Type: text/html; charset=ISO-8859-1
> X-Google-AttachSize: 1701
>
> Pete,<br><br>You can use&nbsp; a script language, e.g., PERL,&nbsp; to access syscdr:repdef, partdef&nbsp; tables and produce a script&nbsp; file that contains the cdr statements you want. Very straight forward.<br><br>Frank<br><br><br><div><span class="gmail_quote">
> On 12 Jan 2007 11:51:04 -0800, <b class="gmail_sendername">ole-racefan</b> &lt;<a href="mailtoete.dickson.ats@gmail.com">pete.dick son.ats@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> Is there any scripts around that will chew thru current replicates and<br>create the cdr statements necessary to rebuild all replicates?<br><br>I can write a script to check thru a &quot;cdr list repl&quot; list and rebuild
> <br>but I figured that should be a way to rebuild without inventing<br>something that already exists. I've been digging around for awhile<br>looking for one. All of our replicates are pretty much the same in that<br>they use timestamp and &quot;select * from xxxx&quot;.
> <br><br>OS: AIX 4.3.3 (yeah, don't bust my stones, I know it's a unsupported<br>version of AIX. Will be on 5.2 in a few weeks/months).<br>Informix Dynamic Server 2000 Version 9.21.UC5XF&nbsp;&nbsp;(yeah, same here.<br>Unfortunetly have to rely on a 3rd party VENDOR to get us upgraded to
> <br>9.4. Then to 10).<br><br>Pete<br><br>__________________________ _____________________<br>Informix-list mailing list<br><a href="mailto:Informix-list@iiug.org">Informix-list@iiug.org</a><br><a href="http://www.iiug.org/mailman/listinfo/informix-list">
> http://www.iiug.org/mailman/listinfo/informix-list</a><br></blockquote></div><br>
>
> ------=_Part_112081_17573367.1168899774828--


Reply With Quote