Wednesday, April 17, 2013

Database backup Validation Shell Script

#!/usr/bin/ksh




if [ "$1" = "" ]

then

echo ""

echo " Please Enter the Oracle_SID"

echo " Exemple nohup ./validate_Db.sh STARPRD & "

echo " "

exit

fi



ORACLE_SID=$1





grep : /var/opt/oracle/oratab
cut -b-9
cut -s -d: -f1
grep -v '#'
grep -i $ORACLE_SID

if [ $? != 0 ]

then

echo " ---------------------------------------------------------"

echo " "

echo " $ORACLE_SID entry is not exist in the /var/opt/oracle/oratab"

echo " "

echo " ---------------------------------------------------------"

exit;

else

echo " ---------------------------------------------------------"

echo " "

echo " $ORACLE_SID entry exist in the /var/opt/oracle/oratab"

echo " "

echo " ---------------------------------------------------------"

fi





. /dsg/dbset $1



ls $ORACLE_HOME/dbs/init$ORACLE_SID.ora



echo " ---------------------------------------------------------"

echo " Verity the Software version "

echo " ---------------------------------------------------------"



VERSION_TR=`sqlplus << eof

eof`



echo " ---------------------------------------------------------"

echo " Existing Node Software Version"

echo $VERSION_TR
cut -f1 -d-
cut -f2 -d:
awk '{print $2}'

echo " ---------------------------------------------------------"





VER_TR=`echo $VERSION_TR
cut -f1 -d-
cut -f2 -d:
awk '{print $2}'`





VERSION_SR=`sqlplus "system/fox1@$ORACLE_SID" << EOF

eof`



echo " ---------------------------------------------------------"

echo "Source Node Software Version"

echo $VERSION_SR
cut -f1 -d-
cut -f2 -d:
awk '{print $2}'

echo " ---------------------------------------------------------"



VER_SR=`echo $VERSION_SR
cut -f1 -d-
cut -f2 -d:
awk '{print $2}'`



if [ "$VER_TR" == "$VER_SR" ]

then

echo " Software version is compitable for test "

else

echo "Software version is not compitable for test "

exit;

fi



echo " ---------------------------------------------------------"

echo " Shutdown the Existing Instance"

echo " ---------------------------------------------------------"



sqlplus / << !! > /dev/null

connect / as sysdba

select sysdate from dual;

shutdown abort

!!



echo " ---------------------------------------------------------"

echo " Env setting"

echo " ---------------------------------------------------------"

export NB_ORA_SERV=orion-g



echo " ---------------------------------------------------------"

echo " NB server = $NB_ORA_SERV"

echo " ---------------------------------------------------------"

echo " Database Net Backup Client location "

echo " ---------------------------------------------------------"



NB_CLIENT=`sqlplus -s "system/fox1@$ORACLE_SID" << EOF

set pages 0

set head OFF

set feed off

select HOST_NAME from v\\$instance ;

exit;

EOF`





export NB_ORA_CLIENT=$NB_CLIENT-g



echo " ---------------------------------------------------------"

echo " NB_ORA_CLIENT = $NB_ORA_CLIENT"

echo " ---------------------------------------------------------"



DB_ID=`sqlplus -s "cat10/backup@rec10g" << !!

set pages 0

set head OFF

set feed off

select DBID from RC_DATABASE

where name='$ORACLE_SID';

!!`



echo " ---------------------------------------------------------"

echo " DB_ID = $DB_ID"

echo " ---------------------------------------------------------"

rman <<- eof="">



connect target /

connect catalog cat10/backup@rec10g

set DBID=$DB_ID

STARTUP FORCE NOMOUNT;

run {

set until time "sysdate";

allocate channel ch1 type disk;

allocate channel ch2 type 'SBT_TAPE';

RESTORE SPFILE TO PFILE '$ORACLE_HOME/dbs/init$ORACLE_SID.ora';

}

eof





mkdir -p $ORACLE_HOME/dbs/$ORACLE_SID

chmod 777 $ORACLE_HOME/dbs/$ORACLE_SID



ls $ORACLE_HOME/dbs/$ORACLE_SID

if [ $? != 0 ]

then

echo " ---------------------------------------------------------"

echo " Database restore new location is not found"

echo " ---------------------------------------------------------"

exit;

else

echo " ---------------------------------------------------------"

echo " Database restore location is $ORACLE_HOME/dbs/$ORACLE_SID"

echo " ---------------------------------------------------------"



fi



ls $ORACLE_HOME/dbs/init$ORACLE_SID.ora



if [ $? != 0 ]

then

exit;

else

mv $ORACLE_HOME/dbs/init$ORACLE_SID.ora $ORACLE_HOME/dbs/initTemp.ora

touch $ORACLE_HOME/dbs/init$ORACLE_SID.ora

more $ORACLE_HOME/dbs/initTemp.ora
grep -i compatible >> $ORACLE_HOME/dbs/init$ORACLE_SID.ora

echo "db_name='$ORACLE_SID'" >> $ORACLE_HOME/dbs/init$ORACLE_SID.ora

echo "audit_file_dest='$ORACLE_HOME/dbs/$ORACLE_SID'" >> $ORACLE_HOME/dbs/init$ORACLE_SID.ora

echo "control_files='$ORACLE_HOME/dbs/$ORACLE_SID/control01.ctl'" >> $ORACLE_HOME/dbs/init$ORACLE_SID.ora

echo "db_block_size=8192" >> $ORACLE_HOME/dbs/init$ORACLE_SID.ora

echo "memory_target=500000000" >> $ORACLE_HOME/dbs/init$ORACLE_SID.ora

echo "undo_tablespace='UNDOTBS1'" >> $ORACLE_HOME/dbs/init$ORACLE_SID.ora

rm $ORACLE_HOME/dbs/initTemp.ora

fi



echo " Pfile created $ORACLE_HOME/dbs/init$ORACLE_SID.ora"

echo " ---------------------------------------------------------"



echo " Restart the DB"

echo " ---------------------------------------------------------"

sqlplus / << !! > /dev/null

connect / as sysdba

select sysdate from dual;

shutdown abort

startup nomount

!!



rman <<- eof="">

connect target /

connect catalog cat10/backup@rec10g

set DBID=$DB_ID

run {

set until time "sysdate";

allocate channel ch1 type disk;

allocate channel ch2 type 'SBT_TAPE';

RESTORE CONTROLFILE;

sql 'alter database mount';

restore database validate;

}



eof



No comments:

Post a Comment