Backup for Netbackup/Dataprotector with Split mirror Storage EVA (Business Copy Snapclone) for backup oracle production database with SSSU command (Not oracle agent for split Storage)

** Myself
For Netbackup or Dataprotector with Split mirror Storage EVA (Business Copy  Snapclone) for backup oracle production database with SSSU
Pre Step
 
1) Put freeze script for database  to DB host
### Modify oracle user,SID and archivelog path
2) Put unfreeze script for database to DB host
### Modify oracle user,SID and archivelog path
3) Pre script for before split storage will call freeze and split storage then unfreeze dataabase and mount backup disk to Backup Host ( Insert in Backup spec or Policy for Prescript)
### Modify EVA LUN Host Source,Target,password,Lun ID,VDISK,Raw disk,VG,LV,FS
4) Post script  after backup for unmount backup disk  to Backup Host( Insert in Backup spec or Policy for post script)
### Modify EVA LUN Host Target,password,Lun ID,VDISK,Raw disk,VG,LV,FS
1) Freeze DB
####### Script generate by Lek  version 16/07/07 #########
##### Environment #######
orauser=oracle        #oracle User
oracle_sid[0]=ORCLDB    #oracle sid
backcontrol_tmp[0]="/tmp/back_${oracle_sid[0]}_controlfile.ctl" #Backup controlfile on temp directory
backcontrol_srg[0]="/data/oracle/archive/ORCLDB/back_${oracle_sid[0]}_controlfile.ctl" #Backup controlfile on storage
export timer=`date +%Y%m%d`
###### Dynamic Execute ENV ##########
tmp_query=/opt/BC/log/freeze.sql
tmp_log=/opt/BC/log/freeze.log
log=/opt/BC/log/freeze${timer}.log #log freeze db
#############################################################
###### Read information tablespace for freeze ###
i=0
> $tmp_query
    while (( i <  ${#oracle_sid[*]} ))
    do
        echo "su - ${orauser}   << BOF 2>&1" >> $tmp_query
        echo "export ORACLE_SID=${oracle_sid[$i]}" >> $tmp_query
        echo "sqlplus /nolog << EOF 2>&1" >> $tmp_query
        echo "connect / as sysdba" >> $tmp_query
        echo "set head off" >> $tmp_query
        echo "set feedback off" >> $tmp_query
        echo "set trimspool on" >> $tmp_query
        echo "set pagesize 0" >> $tmp_query
        echo "set line 1000" >> $tmp_query
        echo "spool switch.lst" >> $tmp_query
        echo "select 'alter system switch logfile;' from v\\\\\\\\\\\$log;" >> $tmp_query
        echo "spool off" >> $tmp_query
        echo "!cat switch.lst |grep -v "SQL"|grep -v "AL" > switch.sql" >> $tmp_query
        echo "spool tbs.lst" >> $tmp_query
        echo "alter system checkpoint;" >> $tmp_query
        echo "@switch.sql" >> $tmp_query
        echo "---- Freeze All tablespace except Temp ---" >> $tmp_query
        echo "select 'alter tablespace '||name||' begin backup;'  from v\\\\\\\\\\\$tablespace where name <> 'TEMP';" >> $tmp_query
        echo "spool off" >> $tmp_query
        echo "!cat tbs.lst | grep -v \"SQL>\" > tbs.sql" >> $tmp_query
        echo "@tbs.sql" >> $tmp_query
        echo "---- Backup controlfile ---" >> $tmp_query
        echo "alter database backup controlfile to '${backcontrol_tmp[$i]}' reuse;" >> $tmp_query
        echo "!cp -p $backcontrol_tmp ${backcontrol_srg[$i]}" >> $tmp_query
        echo "exit" >> $tmp_query
        echo "EOF" >> $tmp_query
        echo "rm tbs.lst tbs.sql switch.lst switch.sql" >> $tmp_query
        echo "BOF" >> $tmp_query
        (( i = i + 1 ))
    done
sh $tmp_query > $tmp_log
echo "Start Begin backup # `date`" >> $log
echo "---------------------------------------------------------" >> $log
a=`tail +38 ${tmp_log}|wc|cut -d " " -f 1`
(( a = a - 4 ))
tail +38 ${tmp_log} |head -$a >> $log
cat $log > $tmp_log
sed -e 's/SQL>//g' $tmp_log > $log
date >> $log
echo "Finish Begin backup # `date`" >> $log
echo "---------------------------------------------------------" >> $log
2) Unfreeze DB
####### Script generate by Lek  version 16/07/07 #########
##### Environment #######
orauser=oracle        #oracle User
oracle_sid[0]=ORCLDB    #oracle sid
export timer=`date +%Y%m%d`
###### Dynamic Execute ENV ##########
tmp_query=/opt/BC/log/unfreeze.sql
tmp_log=/opt/BC/log/unfreeze.log
log=/opt/BC/log/unfreeze${timer}.log #log unfreeze db
#############################################################
###### Read information tablespace for unfreeze ###
i=0
> $tmp_query
    while (( i <  ${#oracle_sid[*]} ))
    do
        echo "su - ${orauser}   << BOF 2>&1" >> $tmp_query
        echo "export ORACLE_SID=${oracle_sid[$i]}" >> $tmp_query
        echo "sqlplus /nolog << EOF 2>&1" >> $tmp_query
        echo "connect / as sysdba" >> $tmp_query
        echo "set head off" >> $tmp_query
        echo "spool tbs.lst" >> $tmp_query
        echo "set feedback off" >> $tmp_query
        echo "set trimspool on" >> $tmp_query
        echo "set pagesize 0" >> $tmp_query
        echo "set line 1000" >> $tmp_query
        echo "---- Unfreeze All tablespace except Temp ---" >> $tmp_query
        echo "select 'alter tablespace '||name||' end backup;'  from v\\\\\\\\\\\$tablespace where name <> 'TEMP';" >> $tmp_query
        echo "spool off" >> $tmp_query
        echo "!cat tbs.lst | grep -v \"SQL>\" > tbs.sql" >> $tmp_query
        echo "@tbs.sql" >> $tmp_query
        echo "exit" >> $tmp_query
        echo "EOF" >> $tmp_query
        echo "rm tbs.lst tbs.sql" >> $tmp_query
        echo "BOF" >> $tmp_query
        (( i = i + 1 ))
    done
sh $tmp_query > $tmp_log
echo "Start End backup # `date`" >> $log
echo "---------------------------------------------------------" >> $log
a=`tail +38 ${tmp_log}|wc|cut -d " " -f 1`
(( a = a - 4 ))
tail +38 ${tmp_log} |head -$a >> $log
cat $log > $tmp_log
sed -e 's/SQL>//g' $tmp_log > $log
echo "Finish End backup # `date`" >> $log
echo "---------------------------------------------------------" >> $log
3) Pre_to_backhost
####### Script generate by Lek  version 16/07/07 #########
##### Environment #######
###### Device of Raw and File  #####
RDSK=/dev/rdsk/
DSK=/dev/dsk/
###### VG;VGCHGID;VGIMPORT######
#VGCHGID and VGIMPORT is 4 pv path for 1 physical disk ######
VG[0]=vgorasw_copy
VG[1]=vgoraarch_copy
VG[2]=vgoradata_copy
VGCHGID[0]="${RDSK}c6t5d1 ${RDSK}c8t5d1 ${RDSK}c10t5d1 ${RDSK}c12t5d1"
VGCHGID[1]="${RDSK}c6t5d2 ${RDSK}c8t5d2 ${RDSK}c10t5d2 ${RDSK}c12t5d2"
VGCHGID[2]="${RDSK}c6t5d3 ${RDSK}c6t5d4 ${RDSK}c6t5d5 ${RDSK}c6t5d6 ${RDSK}c6t5d7 ${RDSK}c6t6d0 ${RDSK}c8t5d3 ${RDSK}c8t5d4 ${RDSK}c8t5d5 ${RDSK}c8t5d6 ${RDSK}c8t5d7 ${RDSK}c8t6d0 ${RDSK}c10t5d3 ${RDSK}c10t5d4 ${RDSK}c10t5d5 ${RDSK}c10t5d6 ${RDSK}c10t5d7 ${RDSK}c10t6d0 ${RDSK}c12t5d3 ${RDSK}c12t5d4 ${RDSK}c12t5d5 ${RDSK}c12t5d6 ${RDSK}c12t5d7 ${RDSK}c12t6d0"
VGIMPORT[0]="${DSK}c6t5d1 ${DSK}c8t5d1 ${DSK}c10t5d1 ${DSK}c12t5d1"
VGIMPORT[1]="${DSK}c6t5d2 ${DSK}c8t5d2 ${DSK}c10t5d2 ${DSK}c12t5d2"
VGIMPORT[2]="${DSK}c6t5d3 ${DSK}c6t5d4 ${DSK}c6t5d5 ${DSK}c6t5d6 ${DSK}c6t5d7 ${DSK}c6t6d0 ${DSK}c8t5d3 ${DSK}c8t5d4 ${DSK}c8t5d5 ${DSK}c8t5d6 ${DSK}c8t5d7 ${DSK}c8t6d0 ${DSK}c10t5d3 ${DSK}c10t5d4 ${DSK}c10t5d5 ${DSK}c10t5d6 ${DSK}c10t5d7 ${DSK}c10t6d0 ${DSK}c12t5d3 ${DSK}c12t5d4 ${DSK}c12t5d5 ${DSK}c12t5d6 ${DSK}c12t5d7 ${DSK}c12t6d0"
######  LV; FS; VG Map File System######
LV[0]=/dev/vgorasw_copy/lvorasw; FS[0]=/app/oracle_copy; VGMAP[0]="1 lvorasw"
LV[1]=/dev/vgoraarch_copy/lvoraarch; FS[1]=/data/oracle/archive/ORCLDB_copy; VGMAP[1]="1 lvoraarch"
LV[2]=/dev/vgoradata_copy/lvoradata; FS[2]=/data/oracle/oradata/ORCLDB_copy; VGMAP[2]="1 lvoradata"
###### VDisk Source;  VDisk Target;  LUN Number ######
VDS[0]=fc_disk_oraapp; VDT[0]=fata_disk_oraapp_copy; LUN[0]=41
VDS[1]=fc_disk_oraarch; VDT[1]=fata_disk_oraarch_copy; LUN[1]=42
VDS[2]=fc_disk_oradata1; VDT[2]=fata_disk_oradata1_copy; LUN[2]=43
VDS[3]=fc_disk_oradata2; VDT[3]=fata_disk_oradata2_copy; LUN[3]=44
VDS[4]=fc_disk_oradata3; VDT[4]=fata_disk_oradata3_copy; LUN[4]=45
VDS[5]=fc_disk_oradata4; VDT[5]=fata_disk_oradata4_copy; LUN[5]=46
VDS[6]=fc_disk_oradata5; VDT[6]=fata_disk_oradata5_copy; LUN[6]=47
VDS[7]=fc_disk_oradata6; VDT[7]=fata_disk_oradata6_copy; LUN[7]=48
###### EVA LUN Host Source  ######
export ELS='"\\Hosts\HP\\Cluster\\dbserv\'
###### EVA VDISK Host Source  ######
export EVS='"\\Virtual Disks\'
###### EVA LUN Host Target ######
export ELTD='"\\Hosts\\HP \\Cluster\\backserv\'
export ELTC='"\\Hosts\\HP \\Cluster\\backserv"'
###### EVA VDISK Host Target ######
export EVT='"\\Virtual Disks\'
###### EVA Clone Disk group name and raid ######
export EVA_CLONE_NAME='"\\Disk Groups\FATA Disk Group"'
export EVA_CLONE_RAID=vraid5
###### Virtual Host of Cluster Oracle package and Remote shell ######
export REMOTE_SHELL=/usr/bin/remsh
export VH=10.1.221.135
###### SMA Information ######
export SMA_IP=192.168.32.7
export SMA_U=storageadmin
export SMA_P=password
export SMA_SYS=KCS_EVA4000
export BC_HOME=/opt/BC
export SSSU=${BC_HOME}/bin/sssu
export LOG_DIR=${BC_HOME}/log
export LOG_FILE=${LOG_DIR}/pre_to_dbserv_backup`date +%y%m%d%`.log
###### DB Script ######
export DBSTART_SCRIPT=${BC_HOME}/bin/freezeORCLDB.sh
export DBSTOP_SCRIPT=${BC_HOME}/bin/unfreezeORCLDB.sh
#########################################################################
#====================================================================
#
# FUNCTION: checkBC
#
#====================================================================
checkBC()
{   
        i=0
        while (( i < ${#LV[*]} ))
        do
                var1=$(bdf |grep ${LV[${i}]} |wc -l)   
        if [ $var1 != 0 ]
            then
            /usr/sbin/fuser -ck ${FS[${i}]}
            /usr/sbin/umount ${FS[${i}]}
                    echo "${FS[${i}]} has not unmounted that BC will force unmount."
        else
             echo "${FS[${i}]} has unmounted" >> $LOG_FILE 2>> $LOG_FILE
            fi
                (( i = i + 1 ))
        done
}
#====================================================================
#
# FUNCTION: checkLVMTAB
#
#====================================================================
checkLVMTAB()
{   
    i=0
    while (( i <  ${#VG[*]} ))
    do
        var1=$(strings /etc/lvmtab |grep ${VG[${i}]} |wc -l)
        if [ $var1 != 0 ]
        then
            /usr/sbin/vgchange -a n ${VG[${i}]}
            /usr/sbin/vgexport ${VG[${i}]}
            echo "${VG[${i}]} has not exported that BC will force exported."
        else
             echo "${VG[${i}]} has exported" >> $LOG_FILE 2>> $LOG_FILE
        fi
        (( i = i + 1 ))
    done
}
#====================================================================
#
# FUNCTION: clearBC
#
#====================================================================
clearBC()
{   
    echo "SELECT MANAGER ${SMA_IP} USERNAME=${SMA_U} PASSWORD=${SMA_P}" >> tmpBC.log
    echo "SELECT SYSTEM "${SMA_SYS}"  " >> tmpBC.log
    i=0
    while (( i <  ${#LUN[*]} ))
    do
        echo "DELETE LUN "${ELTD}${LUN[${i}]}\" >> tmpBC.log
        (( i = i + 1 ))
    done
    i=0
    while (( i <  ${#VDT[*]} ))
    do
        echo "DELETE VDISK "${EVS}\\${VDT[${i}]}\\ACTIVE"\" WAIT_FOR_COMPLETION"  >> tmpBC.log
        (( i = i + 1 ))
    done
    echo "\n\n ###### Clear BC in progess ######"
    $SSSU "file tmpBC.log"
    rm tmpBC.log
}
#====================================================================
#
# FUNCTION: createBC
#
#====================================================================
createBC()
{
    echo "SELECT MANAGER ${SMA_IP} USERNAME=${SMA_U} PASSWORD=${SMA_P}" >> tmpBC.log
    echo "SELECT SYSTEM "${SMA_SYS}"  " >> tmpBC.log
    i=0
    while (( i <  ${#VDS[*]} ))
    do
        echo "ADD COPY "${VDT[${i}]}" VDISK="${EVS}\\${VDS[${i}]}\\ACTIVE"\" DISK_GROUP="${EVA_CLONE_NAME}" REDUNDANCY=${EVA_CLONE_RAID} " >> tmpBC.log
        (( i = i + 1 ))
    done
    i=0
    while (( i <  ${#LUN[*]} ))
    do
        echo "ADD LUN "${LUN[${i}]}" VDISK="${EVT}\\${VDT[${i}]}\\ACTIVE"\" HOST="${ELTC}" " >> tmpBC.log
        (( i = i + 1 ))
    done
    echo "exit" >> tmpBC.log
    echo "\n\n ###### Create BC in progess ######"
    $SSSU "file tmpBC.log"
    rm tmpBC.log
}
#====================================================================
#
# FUNCTION: ImportVG
#
#====================================================================
ImportVG()
{
    echo "-------------start scan disk and create device files" >> $LOG_FILE 2>> $LOG_FILE
    /usr/sbin/ioscan -fnC disk
    /usr/sbin/insf -eC disk
    i=0
    echo "-------------start make node and vgchange id " >> $LOG_FILE 2>> $LOG_FILE
    while (( i <  ${#VG[*]} ))
    do
        mkdir /dev/${VG[${i}]}
        /usr/sbin/mknod /dev/${VG[${i}]}/group c 64 0x${LUN[${i}]}0000
        /usr/sbin/vgchgid ${VGCHGID[${i}]}
        (( i = i + 1 ))
    done
    echo "-------------start create map file" >> $LOG_FILE 2>> $LOG_FILE
    i=0
    while (( i <  ${#VGMAP[*]} ))
    do
        echo ${VGMAP[${i}]} > /tmp/${VG[${i}]}.map
        cat /tmp/${VG[${i}]}.map
        (( i = i + 1 ))
    done
    echo "-------------start vgimport from map file" >> $LOG_FILE 2>> $LOG_FILE
    i=0
    while (( i <  ${#VGMAP[*]} ))
    do
        /usr/sbin/vgimport -m /tmp/${VG[${i}]}.map  ${VG[${i}]}  ${VGIMPORT[${i}]}
        (( i = i + 1 ))
    done
}
#====================================================================
#
# FUNCTION: mountBC
#
#====================================================================
mountBC()
{
    echo "-------------start activate vg " >> $LOG_FILE 2>> $LOG_FILE
    i=0
    while (( i <  ${#VG[*]} ))
    do
        /usr/sbin/vgchange -a y ${VG[${i}]}
        (( i = i + 1 ))
    done
    echo ">>>>>>>>>>>>>>>>>>>>"
    echo "-------------start fsck" >> $LOG_FILE 2>> $LOG_FILE
    i=0
    while (( i <  ${#LV[*]} ))
    do
        /usr/sbin/fsck -F vxfs ${LV[${i}]}
        (( i = i + 1 ))
    done
    echo "-------------start mount" >> $LOG_FILE 2>> $LOG_FILE
    i=0
    while (( i <  ${#LV[*]} ))
    do
        /usr/sbin/mount ${LV[${i}]} ${FS[${i}]}
        (( i = i + 1 ))
    done
}
#====================================================================
#
# MAIN PROGRAM:
#
#
#====================================================================
echo "#######################################################" >> $LOG_FILE 2>> $LOG_FILE
echo "#######################################################" >> $LOG_FILE 2>> $LOG_FILE
echo "#######################################################" >> $LOG_FILE 2>> $LOG_FILE
echo "\n\nStart Pre backup `date`\n\n" >> $LOG_FILE 2>> $LOG_FILE
### Check bdf & Kill Process & Umount File System
echo "\n\n###### Check bdf ######\n\n" >> $LOG_FILE 2>> $LOG_FILE
checkBC >> $LOG_FILE 2>> $LOG_FILE
echo ""
echo "Check bdf Passed" >> $LOG_FILE 2>> $LOG_FILE
### Check lvmtab
echo "\n\n###### Check lvmtab ######\n\n" >> $LOG_FILE 2>> $LOG_FILE
checkLVMTAB >> $LOG_FILE 2>> $LOG_FILE
echo ""
echo "Check lvmtab Passed" >> $LOG_FILE 2>> $LOG_FILE
### Clear BC
echo "\n\n###### Start Clear BC ######\n\n" >> $LOG_FILE 2>> $LOG_FILE
clearBC >> $LOG_FILE 2>> $LOG_FILE
### Freeze DB or Shutdown DB
echo "Start Freeze DB or Shutdown DB : `date`" >> $LOG_FILE 2>> $LOG_FILE
${REMOTE_SHELL} ${VH} -n ${DBSTART_SCRIPT} >> $LOG_FILE 2>> $LOG_FILE
echo ""
echo " Finish  Freeze DB or Shutdown DB : `date`" >> $LOG_FILE 2>> $LOG_FILE
### Create BC
echo "\n\n###### Start Create BC ######\n\n" >> $LOG_FILE 2>> $LOG_FILE
createBC >> $LOG_FILE 2>> $LOG_FILE
### Unfreeze DB or Startup DB
echo "Start Unfreeze DB or Startup DB : `date`" >> $LOG_FILE 2>> $LOG_FILE
${REMOTE_SHELL} ${VH} -n ${DBSTOP_SCRIPT} >> $LOG_FILE 2>> $LOG_FILE
echo ""
echo " Finish  Unfreeze DB or Startup DB : `date`" >> $LOG_FILE 2>> $LOG_FILE
### Import VG
echo "\n\n###### Start Import VG ######\n\n" >> $LOG_FILE 2>> $LOG_FILE
ImportVG >> $LOG_FILE 2>> $LOG_FILE
### Mount
echo "\n\n###### Start Mount ######\n\n" >> $LOG_FILE 2>> $LOG_FILE
mountBC >> $LOG_FILE 2>> $LOG_FILE
echo "\n\n###### Finish Pre Backup : `date` ######" >> $LOG_FILE 2>> $LOG_FILE
4) Post_to_backhost
####### Script generate by Lek  version 16/07/07 #########
##### Environment #######
###### VG######
VG[0]=vgorasw_copy
VG[1]=vgoraarch_copy
VG[2]=vgoradata_copy
###### FS ######
LV[0]=/dev/vgorasw_copy/lvorasw; FS[0]=/app/oracle_copy;
LV[1]=/dev/vgoraarch_copy/lvoraarch; FS[1]=/data/oracle/archive/ORCLDB_copy;
LV[2]=/dev/vgoradata_copy/lvoradata; FS[2]=/data/oracle/oradata/ORCLDB_copy;
###### SMA Information ######
export BC_HOME=/opt/BC
export SSSU=${BC_HOME}/bin/sssu
export LOG_DIR=${BC_HOME}/log
export LOG_FILE=${LOG_DIR}/post_to_dbserv_backup`date +%y%m%d`.log
#########################################################################
#====================================================================
#
# FUNCTION: umountBC
#
#====================================================================
umountBC()
{   
    echo "###### Kill Process & Umount File System #####" >> $LOG_FILE 2>> $LOG_FILE
    i=0
        while (( i < ${#FS[*]} ))
        do
        /usr/sbin/fuser -ck ${FS[${i}]}
        /usr/sbin/umount ${FS[${i}]}
        echo "${FS[${i}]} has unmounted" >> $LOG_FILE 2>> $LOG_FILE
                (( i = i + 1 ))
        done
}
#====================================================================
#
# FUNCTION: exportvgBC
#
#====================================================================
exportvgBC()
{   
    echo "strings /etc/lvmtab" >>  $LOG_FILE 2>> $LOG_FILE
    i=0
    while (( i <  ${#VG[*]} ))
    do
        /usr/sbin/vgchange -a n ${VG[${i}]}
        /usr/sbin/vgexport ${VG[${i}]}
        echo "${VG[${i}]} has exported" >> $LOG_FILE 2>> $LOG_FILE
        (( i = i + 1 ))
    done
}
#====================================================================
#
# MAIN PROGRAM:
#
#
#====================================================================
echo "#######################################################" >> $LOG_FILE 2>> $LOG_FILE
echo "#######################################################" >> $LOG_FILE 2>> $LOG_FILE
echo "#######################################################" >> $LOG_FILE 2>> $LOG_FILE
echo "\n\nStart Post backup `date`\n\n" >> $LOG_FILE 2>> $LOG_FILE
sleep 300
### Unmount & Export VG
umountBC >> $LOG_FILE 2>> $LOG_FILE
exportvgBC >> $LOG_FILE 2>> $LOG_FILE
echo "\n\n###### Finish Post Backup : `date` ######" >> $LOG_FILE 2>> $LOG_FILE

0 comments:

Loading