YD_顯示RMAN備份資訊及日誌

lusklusklusk發表於2016-11-09
vi rman_backup_all.sh

#!/bin/ksh
export LANG=en_US
BACKUP_DATE=`date +%d`
RMAN_LOG_FILE=rman_$BACKUP_DATE.out
TODAY=`date`
echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_HOME
RMAN=$ORACLE_HOME/bin/rman
export RMAN
ORACLE_SID=BIDB
export ORACLE_SID
ORACLE_USER=oracle
export ORACLE_USER
echo "ORACLE_SID: $ORACLE_SID">>$RMAN_LOG_FILE
echo "ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE
echo "ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE
echo "==========================================">>$RMAN_LOG_FILE
echo "BACKUP DATABASE BEGIN......">>$RMAN_LOG_FILE
echo "                   ">>$RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
WEEK_DAILY=`date +%a`
case  "$WEEK_DAILY" in

       "Mon")

            BAK_LEVEL=1

            ;;

       "Tue")

            BAK_LEVEL=1

            ;;

       "Wed")

            BAK_LEVEL=1

            ;;

       "Thu")

            BAK_LEVEL=1

            ;;

       "Fri")

            BAK_LEVEL=1

            ;;

       "Sat")

            BAK_LEVEL=0

            ;;

       "Sun")

            BAK_LEVEL=1

            ;;

       "*")

BAK_LEVEL=error
esac


export BAK_LEVEL=$BAK_LEVEL
echo "Today is : $WEEK_DAILY  incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE
RUN_STR="
BAK_LEVEL=$BAK_LEVEL
export BAK_LEVEL
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN nocatalog TARGET / >>$RMAN_LOG_FILE<<eof
run
{
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
backup  incremental level= $BAK_LEVEL Database format='/u01/rman_backup/BIDB_lev"$BAK_LEVEL"_%U' tag='BIDB_lev"$BAK_LEVEL"' plus archivelog format='/u01/rman_backup/BIDB_arch_%U' tag='arc_bak' delete all input;
release channel ch2;
release channel ch1;
}

allocate channel for maintenance device type disk;
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
release channel;
EOF
"


 # Initiate the command string
    echo "User Command String: $RUN_STR" >> $RMAN_LOG_FILE
    /bin/sh -c "$RUN_STR" >> $RMAN_LOG_FILE
    RSTAT=$?

# ---------------------------------------------------------------------------

# Log the completion of this script.

# ---------------------------------------------------------------------------

if [ "$RSTAT" = "0" ]
then
    LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
cat $RMAN_LOG_FILE|mailx  -s "BIDB 192.168.130.24 RMAN Backup " XX@YY.com
exit $RSTAT








[oracle@DB001~]$contron -l
10 1 * * * sh /backup/script/rman_backup_all.sh


</eof

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2128116/,如需轉載,請註明出處,否則將追究法律責任。

相關文章