当前位置:  数据库>oracle

RMAN自动备份和磁带机备份SHELL脚本

    来源: 互联网  发布时间:2017-04-08

    本文导语: (1)远程TELNET备份数据到磁带机的SHLL脚本 lgmfis:/u01/Oracle/CIC/BACKUP ] cat TAPE_BACKUP.sh: ${OK=0} ${FAIL=1} ${CANCEL=3}: ${MM=`date +%m`}: ${DD=`date +%d`}: ${YY=`date +%Y`}: ${DEVFILn='/dev/rmt/0cn'}: ${FLOG=/u01/oracle/CIC/LOG/TAPE_bk_${MM}${DD}.log}: ${FLST=/u01/oracle/CIC/LOG/TAPE...

(1)远程TELNET备份数据到磁带机的SHLL脚本

lgmfis:/u01/Oracle/CIC/BACKUP ] cat TAPE_BACKUP.sh
: ${OK=0} ${FAIL=1} ${CANCEL=3}
: ${MM=`date +%m`}
: ${DD=`date +%d`}
: ${YY=`date +%Y`}
: ${DEVFILn='/dev/rmt/0cn'}
: ${FLOG=/u01/oracle/CIC/LOG/TAPE_bk_${MM}${DD}.log}
: ${FLST=/u01/oracle/CIC/LOG/TAPE_bk_${MM}${DD}.lst}
: ${HOST=`uname -n`}
. /u01/oracle/CIC/BACKUP/common.sh
START_YMD=`date +%Y%m%d`
START_HMS=`date +%H%M%S`
echo "  $HOST TAPE Backup start at $START_YMD $START_HMS    "     >> $FLOG
#chkdate=`get_before_date ${YY}${MM}${DD}`
#tmpdate=`expr substr $chkdate 5 5`
/usr/bin/mt -f ${DEVFILn} rewind














if [ $? -eq 0 ]
then
   echo "## Tape Check : Success/n"                          >> $FLOG
   echo "## Tape Check : Success/n"
else
   echo "## Tape Check : Error(Insert tape into Device)/n"   >> $FLOG
   echo "## Tape Check : Error(Insert tape into Device)/n"





   exit ${FAIL}
fi

echo "## Step 1 : FULL Backup                 ###"        >> $FLOG

cd /

find fz02/RMANBK/lgmfis/*${MM}${DD}* -print|sort -rn +1|head -9| cpio -ocv -H od

c -C 30720 -O $DEVFILn | tee -a $FLST

find u08/EXP_BK/FZLFMES/*${MM}${DD}.* -print | cpio -ocv -H odc -C 30720 -O $DEV

FILn | tee -a $FLST


mt -f $DEVFILn offline
echo "## Step 1 : FULL Backup    End             ###"        >> $FLOG

echo "please insert the secound tape"
Getyn "Was the secound tape insert? (y/n)"

echo "## Step 2 : lgmfis db file & EXP Backup                 ###"        >> $FL

OG

/usr/bin/mt -f ${DEVFILn} rewind
cd /

find fz02/RMANBK/lgmfis/*${YY}${MM}${DD}* -print|sort -n +1|head -7| cpio -ocv -

H odc -C 30720 -O $DEVFILn | tee -a $FLST
#find u08/EXP_BK/lgmfis/*${MM}${DD}.* -print | cpio -ocv -H odc -C 30720 -O $DEV

FILn | tee -a $FLST

echo "## Step 2 : lgmfis db file & EXP Backup    END             ###"        >>

$FLOG

mt -f $DEVFILn offline
echo "please insert the third tape"
Getyn "Was the third tape insert? (y/n)"

/usr/bin/mt -f ${DEVFILn} rewind
cd /

echo "## Step 3 : lgmfis arch & FZLFMES DATAFILE & ARCH & export Backup

        ###"        >> $FLOG
find fz01/RMANBK/FZLFMES/*${MM}${DD}* -print | cpio -ocv -H odc -C 30720 -O $DEV

FILn | tee -a $FLST
find fz02/RMANBK/lgmfis/*${MM}${DD}* -print|sort -rn +1|sed -n '10,11p;11q'| cpi

o -ocv -H odc -C 30720 -O $DEVFILn | tee -a $FLST
echo "## Step 3 : lgmfis arch & FZLFMES DATAFILE & ARCH & export Backup   End

 ###"   >> $FLOG

mt -f $DEVFILn offline

echo "please insert the fourth tape"
Getyn "Was the fourth tape insert? (y/n)"

/usr/bin/mt -f ${DEVFILn} rewind
cd /

echo "## Step 4 : lgmfis arch & FZLFMES DATAFILE & ARCH & export Backup

        ###"        >> $FLOG
find u08/EXP_BK/lgmfis/*${MM}${DD}.* -print | cpio -ocv -H odc -C 30720 -O $DEVF

ILn | tee -a $FLST
find u08/RMANBK/lgmfis/*${MM}${DD}* -print | cpio -ocv -H odc -C 30720 -O $DEVFI

Ln | tee -a $FLST
echo "## Step 4 : lgmfis arch & FZLFMES DATAFILE & ARCH & export Backup   End

 ###"   >> $FLOG

cd /


(2)自动RMAN脚本:

[lgmfisu:root] /u01/oracle/CIC/BACKUP> cat DB_FULL_lgmfis.sh
MM=`date +%m`
DD=`date +%d`
YY=`date +%y`


RMAN_LOG_FILE=/u01/oracle/CIC/LOG/FULL_HOT_lgmfis_${YY}${MM}${DD}.log

ORACLE_HOME=/u01/app/oracle/product/9.2.0
export ORACLE_HOME

ORACLE_SID=lgmfis
export ORACLE_SID
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
#find /fz02/RMANBK/lgmfis -mtime +0 -exec rm {} /;
find /u08/RMANBK/lgmfis -mtime +0 -exec rm {} /;
rm -f /fz02/RMANBK/lgmfis/db_full*







/u01/app/oracle/product/9.2.0/bin/rman target / nocatalog msglog $RMAN_LOG_FILE
append


mt -f $DEVFILn offline
END_YMD=`date +%Y%m%d`
END_HMS=`date +%H%M%S`

echo "  $HOST  TAPE Backup Successfully Ended At $END_YMD $END_HMS    "     >> $

FLOG

 

另外个文件:COMMON.SH

[lgmfisu:root] /u01/oracle/CIC/BACKUP> cat common.sh
get_before_date()
{
 Y=`expr substr $1 1 4`
 M=`expr substr $1 5 2`
 D=`expr substr $1 7 2`
 YY=`expr $Y - 1`
 MM=`expr $M - 1`
 DD=`expr $D - 1`
 MM=`printf "%02d" $MM`
 DD=`printf "%02d" $DD`
 dd=$Y$MM
 dad=`get_mon_days $dd`
 be_date=$Y$M$DD
 if [ $D -eq 01 ]
 then
 if [ $M -ne 01 ]
 then
 be_date=$Y$MM$dad
 fi
 if [ $M -eq 01 ]
                then
                        be_date=$YY"1231"
                fi
   fi
        echo $be_date
























}


Getyn() {
       while echo "/n$* (y/n)? /c"
               do read yn
                        case "$yn" in
                                [Yy] )  return $OK      ;;
                                [Nn] )  ConfirmYn "cancel The Job ?" ;;
                                  *  ) echo "Please enter y or n"  ;;
                        esac
                done
 }









ConfirmYn() {
       while echo "/n$* (y/n)? /c"
               do read yn
                        case "$yn" in
                                [Nn] ) return $OK       ;;
                                [Yy] ) echo "/n The Job is canceled."
                                       sleep 3
                                       exit $CANCEL     ;;
                                  *  ) echo "Please enter y or n"  ;;
                        esac
                done
}











    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • rman配置及rman常用命令操作
  • Oracle相关:Rman Crosscheck删除失效归档
  • rman恢复方案和oracle异机恢复
  • Oracle RMAN快速入门指南


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3