Oracle script for apply standby database for Standard version(Not implement Dataguard) remote copy new archivlog from Primary database host to standby host (#compat 8i,9i,10g) for Implement Disaster not Enterprise License

** Myself
## Pre Step
#1) Install oracle software (oracle standard or enterprise edition)
#2) Assigne disk same as production system
#3) Transfer backup offline to standby host (not export or datapump) to same as location production system
#4) Create standby control file from production system and transfer to standby host same location of control file (same step as create standby database or dataguard)
#5) Set rcp or scp for trust file transfer
#6) Adjust Dynamic ENV  and Execute binary ENV for you want

#7) Put shell script to standby database host (DR) ,Please see below
#8) Sheduling this shell for executing by crontab every 1 or 5 mins (script will be transfer difference archivlog)
##Concept for processing
#1) Find archive directory
#2)  Find max sequence on standby db
#3) Find file transfer from primary db (newer archivelog)
#4) List file name transfer to standby db
#5) Transfer files from primary to standby db
#6) Recovery all transfer file (standby database will be apply new archivelog file from source system)

#--------------------------------------------------
#!/usr/bin/ksh
###### Dynamic ENV ##########
orauser=oraprd        #oracle user on os
oracle_sid=PRD        #oracle sid
lsnrctl_sid=LISTENER        #listener sid
ip_pri=192.168.10.30 ## (IP of Primary source database or VIP from Cluster  Primary source )
tlog=/tmp/transfer.log # log
###### Execute ENV ##########
orahome=/oracle/PRD/920_64
oraexe=/oracle/PRD/920_64/bin #Execute for oracle
###### Static ENV ##########
export tmpmax=/tmp/max.lst
export tmpquery=/tmp/query.lst
export tmptrans=/tmp/transfer.lst
export tmparch=/tmp/arch.lst
export tmparchdir=/tmp/archdir.lst
cat $tmparch |grep "Archive destination "|awk '{print $3}' > $tmparchdir
arch=`cat $tmparchdir`
###### Main program ############################################################
####### Find archive directory ###
su - $orauser << BOF
export ORACLE_SID=$oracle_sid
sqlplus "/ as sysdba" << EOF
spool $tmparch
archive log list
spool off
exit
EOF
BOF
############ Find max sequence on standby db ############S
su - $orauser << BOF
export ORACLE_SID=$oracle_sid
sqlplus "/ as sysdba" << EOF
spool $tmpmax
select max(sequence#)  from v\\\$log_history;
spool off
EOF
BOF
############ Find file transfer from primary db ############
export maxsequence=`head -5 $tmpmax|tail +5`
echo "export ORACLE_SID=$oracle_sid" > $tmpquery
echo "export ORACLE_HOME=$orahome" >> $tmpquery
echo "${oraexe}/sqlplus /nolog << EOF > $tmptrans" >> $tmpquery
echo "connect /as sysdba" >> $tmpquery
echo "select name from v\\\$archived_log where sequence# > $maxsequence;" >> $tmpquery
echo "exit" >> $tmpquery
echo "EOF" >> $tmpquery
su - $orauser << EOF
rcp -p $tmpquery $orauser@$ip_pri:$tmpquery
EOF
############ List file name transfer to standby db ############
su - $orauser << BOF
remsh $ip_pri "sh $tmpquery" << EOF
EOF
rcp -p $orauser@$ip_pri:$tmptrans $tmptrans
BOF
############ Transfer files from primary to standby db ##########
> $tmpquery
arch=`cat $tmparchdir`
cat $tmptrans|grep '^/'|while read line
do
    echo "rcp -p $orauser@$ip_pri:$line $arch" >> $tmpquery
done
su - $orauser << BOF
export ORACLE_SID=$oracle_sid
sh $tmpquery
echo "file : $line transfer finish" >> $tlog
############ Recovery all transfer file ############
sqlplus "/ as sysdba" << EOF
set autorecovery on
recover database using backup controlfile until cancel;
EOF
BOF
echo "Recovery database Finish" >> $tlog
echo "--------------------------------------------" >> $tlog

0 comments:

Loading