Pages

Wednesday, July 3, 2019

Script to backup and delete archivelog in Linux

#!/bin/ksh
#
if [[ $1 = "" ]]; then
    echo "*** "
    echo "*** No SID specified; specify ORACLE_SID as arg 1"
    echo "*** "
    exit
fi
PATH=$PATH:/usr/local/bin
export ORACLE_SID=$1
#export ARCH_DAYS=$2
ORAENV_ASK=NO
. /usr/local/bin/oraenv
export LIBPATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
TODAY=`date '+%m%d%y_%H_%M'`
SITE=`uname -n`
LOGDIR=/u99/ORCL/Archive/Logfile
ARCH_LOG=$LOGDIR/arch_$ORACLE_SID.$TODAY.log
DBA='someone@somedomain.com'
touch $ARCH_LOG
export TARGET_CONN='/'
export RMANOUT=/u99/ORCL/Archive/Logfile
$ORACLE_HOME/bin/rman target '/' <<EOF >> $ARCH_LOG
run {
CONFIGURE RETENTION POLICY TO REDUNDANCY 16;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u99/ORCL/Archive/%F';
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u99/ORCL/Archive/snapcf_PROD.f';
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;
CONFIGURE MAXSETSIZE TO 6000000000;
allocate channel c1 device type disk format '/u99/ORCL/Archive_%d_%s_%T_%c_%p';
allocate channel c2 device type disk format '/u99/ORCL/Archive_%d_%s_%T_%c_%p';
backup archivelog all delete input;
backup current controlfile format '/u99/ORCL/Archive_%d_%s_%T_CONTROL' tag "CNTRLFL" ;
release channel c1;
release channel c2;
}
EOF
if [ $? -ne 0 ]
then
 echo "FAILURE: Backup of the archivelogs for $ORACLE_SID started on $TODAY failed on `date '+%m/%d/%y %H:%M'`." >> $ARCH_LOG
 echo "Archivelogs will NOT be deleted, since they were never backed up." >> $ARCH_LOG
 /bin/mail -s "FAILURE Backup of the archivelogs to HOTBACK for $ORACLE_SID failed on `date '+%m/%d/%y %H:%M'`." $DBA <$ARCH_LOG
exit
else
 /bin/mail -s "SUCCESS Backup of the archivelogs to HOTBACK for $ORACLE_SID on `date '+%m/%d/%y %H:%M'`." $DBA <$ARCH_LOG
fi

exit

No comments:

Post a Comment