#!/bin/bash
#backup location:
# Begin ###################################
export ORACLE_HOME=/u01/app/oracle/11.2.0/ebs
export ORACLE_SID=EBSDB
unset PERLBIN
unset PERL5LIB
# End ###################################
BKPLOC=/BKP/DailyBKP
#Number Of Channels:
CHS=24
#Number of Days to keep Archives:
ARCHDAYS=2
#Number Of Bakcups to Keep:
BKPDAYS=2
##############################################################
##############################################################
##############################################################
##############################################################
LOC=$BKPLOC/$(date +%d_%h_%Y-%a)/$(date +%H.%M)
RMANCONF=$LOC/rman.conf
RMANOLDCONF=$LOC/rmanold.conf
RMANLOG=$LOC/rman.log
CTL=$LOC/controlfile$ORACLE_SID.ctl
CTLAUTO=$LOC/%F
#configure controlfile autobackup format for device type disk to '$CTLAUTO';
CTLTRC=$LOC/control$ORACLE_SID.txt
PARFILE=$LOC/init$ORACLE_SID.ora
###############################################
set -e
#####open log in new terminal
log=$1
if [[ -n "$log" ]]; then
gnome-terminal -e "tail -1000f $RMANLOG" &
fi
#######################
#check if backup dir is exist or no
[[ -d $LOC ]] || mkdir -p $LOC
touch $RMANLOG
####################
#delete old backup
if [ "$(ls -tdR $BKPLOC/*/* |wc -l)" -gt "$BKPDAYS" ]; then
ls -tdR $BKPLOC/*/* | awk "NR>$BKPDAYS" | xargs rm -rf &
rmdir $BKPLOC/* 2> /dev/null &
fi
############################
/u01/app/oracle/11.2.0/ebs/bin/rman target / <<EOF >> ${RMANLOG} 2>&1 &
run {
CONFIGURE COMPRESSION ALGORITHM 'MEDIUM';
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT ='$LOC/%d_full_%s_%p';
CONFIGURE DEVICE TYPE DISK PARALLELISM $CHS BACKUP TYPE TO compressed backupset;
CONFIGURE RETENTION POLICY TO REDUNDANCY $BKPDAYS;
delete noprompt ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-$ARCHDAYS';
#delete noprompt force ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-$ARCHDAYS';
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt expired backup;
delete noprompt expired backupset;
delete noprompt obsolete;
sql "alter database backup controlfile to trace as ''$CTLTRC'' ";
sql "create pfile=''$PARFILE''from spfile";
sql 'alter system switch logfile';
backup current controlfile;
backup full database plus archivelog;
sql 'alter system archive log current';
CONFIGURE CHANNEL DEVICE TYPE DISK CLEAR;
CONFIGURE DEVICE TYPE DISK CLEAR;
CONFIGURE COMPRESSION ALGORITHM CLEAR;
CONFIGURE RETENTION POLICY CLEAR;
CONFIGURE CONTROLFILE AUTOBACKUP clear;
host 'echo -e "\e[1;31mRMAN Script Completed..\e[0m"';
}
EOF
/usr/local/bin/sendEmail -f mtalmasri@gmail.com -s 10.100.75.123 -t mtalmasri@gmail.com -u "EBS Daily Backup" -o tls=no -o message-file=$RMANLOG
##########
No comments:
Post a Comment