# Level 0 Backup # FSPRD Friday 18:00 Hrs.
00 18 * * 6 nohup /home/oracle/scripts/backupscripts/backup_script_v5.ksh FSPRD 0 8 "/backups" "zafrullakhan001@gmail.com" >> /tmp/FSPRD_nohup_rmanrun.log 1>&2 &
# Level 1 Backup # FSPRD Monday, Tuesday, Wednesday, Thursday, Saturday, Sunday 18:00 Hrs.
00 18 * * 1,2,3,4,5,0 nohup /home/oracle/scripts/backupscripts/backup_script_v5.ksh FSPRD 1 8 "/backups" "zafrullakhan001@gmail.com" >> /tmp/FSPRD_nohup_rmanrun_l1.log 1>&2 &
RMAN Backup Script Starts
#!/bin/ksh
#############################################################################
# RMAN Backup Script
# Author : Zafrulla Khan Oracle / Mysql / SQL Server / PostgreSQL / MangoDB DBA.
# Description: RMAN Backup Script which acts as both for Level 0 and Level 1
# Scheduled to Run L0 Backups on Saturdays
# Scheduled to Run L1 Backups (Incr) Every Week-days
# Email will help to know the status of the RMAN Backup Script like Success / Failure
#############################################################################
set -xv
export DB_NAME=$1;
export BKP_LEVEL=$2;
export PARALLEL=$3;
export FOLDER_PATH=$4;
export DBA_EMAIL="$5";
export PROCESS_NUMBER=$$;
mkdir -p "${FOLDER_PATH}/rman/${DB_NAME}/BACKUPS/LOGS/";
ORACLE_HOSTNAME=pldandbd1; 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/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_LEVEL${BKP_LEVEL}_`date +%d%m%Y`.log"
TRACEFILE="${FOLDER_PATH}/rman/$DB_NAME/BACKUPS/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_LEVEL${BKP_LEVEL}_TRACE_`date +%d%m%Y`.trc"
TIMETRACKER="${FOLDER_PATH}/rman/$DB_NAME/BACKUPS/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_TIME_TRACK_L${BKP_LEVEL}_`date +%d%m%Y`.log"
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'" trace=$TRACEFILE log=$LOGFILE <<EOF
run {
sql "begin dbms_backup_restore.refreshagedfiles; end;";
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '&4/rman/&1/BACKUPS/&1_snapshot_ctrl_file.ctl';
configure controlfile autobackup off;
crosscheck backup;
crosscheck archivelog all;
CONFIGURE DEVICE TYPE DISK PARALLELISM &3 BACKUP TYPE TO BACKUPSET;
sql 'alter system archive log current';
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '&4/rman/&1/BACKUPS/&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 controlfile autobackup on;
}
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/backupscripts/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 Archive Log BACKUP FAILED FOR $DB_NAME ${LOG_DATE}" -r noreply@clientxyz.com ${DBA_EMAIL} < $TIMETRACKER
else
mailx -s "RMAN Archive Log BACKUP SUCCESS FOR $DB_NAME ${LOG_DATE}" -r noreply@clientxyz.com ${DBA_EMAIL} < $TIMETRACKER
fi
exit
Script Ends.
00 18 * * 6 nohup /home/oracle/scripts/backupscripts/backup_script_v5.ksh FSPRD 0 8 "/backups" "zafrullakhan001@gmail.com" >> /tmp/FSPRD_nohup_rmanrun.log 1>&2 &
# Level 1 Backup # FSPRD Monday, Tuesday, Wednesday, Thursday, Saturday, Sunday 18:00 Hrs.
00 18 * * 1,2,3,4,5,0 nohup /home/oracle/scripts/backupscripts/backup_script_v5.ksh FSPRD 1 8 "/backups" "zafrullakhan001@gmail.com" >> /tmp/FSPRD_nohup_rmanrun_l1.log 1>&2 &
RMAN Backup Script Starts
#!/bin/ksh
#############################################################################
# RMAN Backup Script
# Author : Zafrulla Khan Oracle / Mysql / SQL Server / PostgreSQL / MangoDB DBA.
# Description: RMAN Backup Script which acts as both for Level 0 and Level 1
# Scheduled to Run L0 Backups on Saturdays
# Scheduled to Run L1 Backups (Incr) Every Week-days
# Email will help to know the status of the RMAN Backup Script like Success / Failure
#############################################################################
set -xv
export DB_NAME=$1;
export BKP_LEVEL=$2;
export PARALLEL=$3;
export FOLDER_PATH=$4;
export DBA_EMAIL="$5";
export PROCESS_NUMBER=$$;
mkdir -p "${FOLDER_PATH}/rman/${DB_NAME}/BACKUPS/LOGS/";
ORACLE_HOSTNAME=pldandbd1; 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/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_LEVEL${BKP_LEVEL}_`date +%d%m%Y`.log"
TRACEFILE="${FOLDER_PATH}/rman/$DB_NAME/BACKUPS/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_LEVEL${BKP_LEVEL}_TRACE_`date +%d%m%Y`.trc"
TIMETRACKER="${FOLDER_PATH}/rman/$DB_NAME/BACKUPS/LOGS/${ORACLE_UNQNAME}_${PROCESS_NUMBER}_TIME_TRACK_L${BKP_LEVEL}_`date +%d%m%Y`.log"
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'" trace=$TRACEFILE log=$LOGFILE <<EOF
run {
sql "begin dbms_backup_restore.refreshagedfiles; end;";
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '&4/rman/&1/BACKUPS/&1_snapshot_ctrl_file.ctl';
configure controlfile autobackup off;
crosscheck backup;
crosscheck archivelog all;
CONFIGURE DEVICE TYPE DISK PARALLELISM &3 BACKUP TYPE TO BACKUPSET;
sql 'alter system archive log current';
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '&4/rman/&1/BACKUPS/&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 controlfile autobackup on;
}
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/backupscripts/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 Archive Log BACKUP FAILED FOR $DB_NAME ${LOG_DATE}" -r noreply@clientxyz.com ${DBA_EMAIL} < $TIMETRACKER
else
mailx -s "RMAN Archive Log BACKUP SUCCESS FOR $DB_NAME ${LOG_DATE}" -r noreply@clientxyz.com ${DBA_EMAIL} < $TIMETRACKER
fi
exit
Script Ends.
No comments:
Post a Comment