RMAN 增量备份 脚本
################################################################## ## rman_backup.sh ## ## created by cndba.cn ## ## 2016-1-11 ## ################################################################## #!/bin/ksh export BACKUP_DATE=`date +%d` RMAN_LOG_FILE=${0}.out TODAY=`date` USER=`id|cut -d "(" -f2|cut -d ")" -f1` echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1 export ORACLE_HOME RMAN=$ORACLE_HOME/bin/rman export RMAN ORACLE_SID=dave 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=1 ;; "Sun") BAK_LEVEL=0 ;; "*") 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 / msglog $RMAN_LOG_FILE append <<EOF run { allocate channel c1 type disk; allocate channel c2 type disk; allocate channel c3 type disk; allocate channel c4 type disk; backup incremental level= $BAK_LEVEL skip inaccessible filesperset 6 Database format='/u01/backup/dave_lev"$BAK_LEVEL"_%U_%T' tag='dave_lev"$BAK_LEVEL"'; sql 'alter system archive log current'; backup archivelog all tag='arc_bak' format='/u01/backup/arch_%U_%T' skip inaccessible filesperset 6 not backed up 1 times delete input; backup current controlfile tag='bak_ctlfile' format='/u01/backup/ctl_file_%U_%T'; backup spfile tag='spfile' format='/u01/backup/dave_spfile_%U_%T'; release channel c2; release channel c1; release channel c3; release channel c4; } allocate channel for maintenance device type disk; report obsolete; delete noprompt obsolete; crosscheck backup; delete noprompt expired backup; list backup summary; release channel; EOF " # Initiate the command string if [ "$CUSER" = "root" ] then echo "Root Command String: $RUN_STR" >> $RMAN_LOG_FILE su - $ORACLE_USER -c "$RUN_STR" >> $RMAN_LOG_FILE RSTAT=$? else echo "User Command String: $RUN_STR" >> $RMAN_LOG_FILE /bin/sh -c "$RUN_STR" >> $RMAN_LOG_FILE RSTAT=$? fi # --------------------------------------------------------------------------- # 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 /bin/mailx -s "RMAN Backup SID " ahdba@qq.com < $RMAN_LOG_FILE exit $RSTAT
转:http://www.cndba.cn/dave/article/163
文章可以转载,必须以链接形式标明出处。