Oracle PRE-Production RMAN Backup Script for both L0 and L1 backups with MD5SUM checksum
Advantages.
1) Helps in tracking the backups date-time as per the backup folders.
2) help to check the MD5 check sum of the files when restorations from the tape backups.
# LEVEL 0 BACKUPS (Friday)
59 19 * * 5 nohup /home/oracle/scripts/backups/backup_script_v7.ksh FSDEV 0 4 "/backups" "zafrullakhan001@gmail.com" 1>&2 >> /tmp/FSDEV_nohup_rmanrun.log &
00 15 * * 5 nohup /home/oracle/scripts/backups/backup_script_v7.ksh FSTST 0 4 "/backups" "zafrullakhan001@gmail.com" 1>&2 >> /tmp/FSTST_nohup_rmanrun.log &
59 23 * * 5 nohup /home/oracle/scripts/backups/backup_script_v7.ksh FSUAT 0 4 "/backups" "zafrullakhan001@gmail.com" 1>&2 >> /tmp/FSUAT_nohup_rmanrun.log &
# LEVEL 1 BACKUPS ( Monday and Wednesday )
59 20 * * 1,3 nohup /home/oracle/scripts/backups/backup_script_v7.ksh FSDEV 1 4 "/backups" "zafrullakhan001@gmail.com" 1>&2 >> /tmp/FSDEV_nohup_rmanrun.log &
00 17 * * 1,3 nohup /home/oracle/scripts/backups/backup_script_v7.ksh FSTST 1 4 "/backups" "zafrullakhan001@gmail.com" 1>&2 >> /tmp/FSTST_nohup_rmanrun.log &
59 22 * * 1,3 nohup /home/oracle/scripts/backups/backup_script_v7.ksh FSUAT 1 4 "/backups" "zafrullakhan001@gmail.com" 1>&2 >> /tmp/FSUAT_nohup_rmanrun.log &
#!/bin/ksh
set -xv
#########################################################
## Author: zafrullakhan001@gmail.com
## Version: 7.0:
#########################################################
### Initialize Variables Begin ####
export DB_NAME=$1;
export BKP_LEVEL=$2;
export PARALLEL=$3;
export FOLDER_PATH=$4;
export DBA_EMAIL="$5";
export PROCESS_NUMBER=$$;
export DATE_FOLDERS="$(date +%F-%H:%M:%S)-L${BKP_LEVEL}";
mkdir -p "${FOLDER_PATH}/rman/${DB_NAME}/BACKUPS/$DATE_FOLDERS/LOGS/";
ORACLE_HOSTNAME=${hostname}; export ORACLE_HOSTNAME
ORACLE_UNQNAME=$DB_NAME; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export ORACLE_HOME
ORACLE_SID=$DB_NAME; export ORACLE_SID
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
LOG_DATE=`date +%d%m%Y`
LOGFILE="${FOLDER_PATH}/rman/$DB_NAME/BACKUPS/$DATE_FOLDERS/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_LEVEL${BKP_LEVEL}_`date +%d%m%Y`.log"
TRACEFILE="${FOLDER_PATH}/rman/$DB_NAME/BACKUPS/$DATE_FOLDERS/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_LEVEL${BKP_LEVEL}_TRACE_`date +%d%m%Y`.trc"
TIMETRACKER="${FOLDER_PATH}/rman/$DB_NAME/BACKUPS/$DATE_FOLDERS/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_TIME_TRACK_L${BKP_LEVEL}_`date +%d%m%Y`.log"
### Initialize Variables End ####
### Check if oracle is running and accepting connection ####
check_stat=$(ps -ef|grep -i ${DB_NAME}|grep pmon|wc -l);
oracle_num=$(expr $check_stat);
if [ $oracle_num -lt 1 ]
then
exit 0
fi
#*************************************************************
# Test to see if Oracle is accepting connections
#*************************************************************
$ORACLE_HOME/bin/sqlplus -s / as sysdba<<! > /tmp/check_$ORACLE_SID.ora
select * from v\$database;
exit
!
#*************************************************************
# If not, exit and e-mail . . .
#*************************************************************
check_stat=$(cat /tmp/check_$ORACLE_SID.ora|grep -i ORA-|wc -l);
oracle_num=$(expr $check_stat);
if [ $oracle_num -ne 0 ]
then
cat /tmp/check_$ORACLE_SID.ora|mailx -s "$ORACLE_SID is down! RMAN Can not proceed for taking Backup" $DBA_EMAIL;
exit 16
fi
### End Oracle Connection Tet ####
echo -e " ${ORACLE_UNQNAME} LEVEL ${BKP_LEVEL} BACKUP START AND END TIME DETAILS" > $TIMETRACKER
echo "====================================================" >> $TIMETRACKER
date >>$TIMETRACKER
rman target / catalog RMANCAT/<password>@RMANDB USING $DB_NAME $BKP_LEVEL $PARALLEL "'$FOLDER_PATH'" "'$DATE_FOLDERS'" trace=$TRACEFILE log=$LOGFILE <<EOF
run {
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '&4/rman/&1/BACKUPS/&5/&1_snapshot_ctrl_file.ctl';
configure controlfile autobackup off;
crosscheck backup;
crosscheck archivelog all;
CONFIGURE DEVICE TYPE DISK PARALLELISM &3 BACKUP TYPE TO BACKUPSET;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '&4/rman/&1/BACKUPS/&5/L&2_%T_%d_%s_%p_%U';
backup incremental level &2 device type disk as compressed backupset database tag = 'weekly0';
sql 'alter system archive log current';
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '&4/rman/&1/BACKUPS/&5/L&2_ARCH_%T_%d_%s_%p_%U';
backup device type disk as compressed backupset archivelog all delete input tag L&2_ARCHIVE_LOGS;
delete noprompt obsolete device type disk;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '&4/rman/&1/BACKUPS/&5/L&2_CNTL_%T_%d_%s_%p_%U';
backup current controlfile tag L&2_CNT_FILE_BKP;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '&4/rman/&1/BACKUPS/&5/L&2_SPFILE_%T_%d_%s_%p_%U';
sql "begin dbms_backup_restore.refreshagedfiles; end;";
backup spfile tag L&2_SP_FILE_BKP;
}
EOF
date >> $TIMETRACKER
echo -e "\n====================================================\n\n" >> $TIMETRACKER
echo -e "\n HISTORICAL RMAN BACKUP DETAILS " >> $TIMETRACKER
echo -e "====================================================\n" >> $TIMETRACKER
sqlplus -s \"/ as sysdba\" @/home/oracle/scripts/backups/rman_backup_info.sql >> $TIMETRACKER
echo -e "\n====================================================\n\n" >> $TIMETRACKER
echo -e " ORA- ERROR DETAILS If ANY? " >> $TIMETRACKER
echo -e "====================================================\n" >> $TIMETRACKER
cat $TRACEFILE | grep ORA- >> $TIMETRACKER
echo -e "====================================================\n\n" >> $TIMETRACKER
echo -e " FEW LINES of LOG FILE " >> $TIMETRACKER
echo -e "====================================================\n" >> $TIMETRACKER
tail -20 $TRACEFILE >> $TIMETRACKER
echo -e "====================================================\n\n" >> $TIMETRACKER
error_count=$(cat $TRACEFILE | grep ORA- | wc -l);
if [ $error_count -gt 0 ]; then
mailx -s "RMAN Level ${BKP_LEVEL} BACKUP FAILED FOR $DB_NAME ${LOG_DATE}" -r noreply@clientxyz.com ${DBA_EMAIL} < $TIMETRACKER
else
mailx -s "RMAN Level ${BKP_LEVEL} BACKUP SUCCESS FOR $DB_NAME ${LOG_DATE}" -r noreply@clientxyz.com "${DBA_EMAIL}" < $TIMETRACKER
nohup find ${FOLDER_PATH}/rman/${DB_NAME}/BACKUPS/$DATE_FOLDERS/ -type f|xargs md5sum >> ${FOLDER_PATH}/rman/${DB_NAME}/BACKUPS/$DATE_FOLDERS/MD5SUM.txt &
fi
exit
No comments:
Post a Comment