rman脚本(修改具体地址和实例名)
################################################################## ## rman_backup.sh ## ################################################################## #!/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/11.2.1/db_1 export ORACLE_HOME RMAN=$ORACLE_HOME/bin/rman export RMAN ORACLE_SID=orcl 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 " 88fly@163.com < $RMAN_LOG_FILE exit $RSTAT
删除归档日志脚本
Linux 平台:
0 2 * * * /u01/del_archive.sh > /u01/del_archive.log
[oracle@hfcc-svr-newccsdb1 ~]$ more /home/oracle/scripts/del_archive.sh
#!/usr/bin/ksh # create by tianlesoftware export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1 export ORACLE_SID=dave export SHELL_DIR=/u01 del_seq=`ls /u01/archivelog/|head -1|cut -f2 -d_` echo $del_seq $ORACLE_HOME/bin/sqlplus -s "sys/oracle@dave_st as sysdba" <<eof >/home/oracle/scripts/max_sn.log set head off; set feedback; select max(sequence#) from v\$log_history; exit; eof max_sn=`cat /home/oracle/scripts/max_sn.log|awk '{print $1}'|grep ^[0-9]` max_sn=`expr $max_sn - 5` echo $max_sn while [ $del_seq -lt $max_sn ] do rm /u01/archivelog/1_"$del_seq"_746065660.dbf del_seq=`expr $del_seq + 1` echo $del_seq done
注意:归档日志文件名称编码根据具体情况而定(746065660 根据情况改)
或者用脚本:
del_arc.sh
find /u01/backups -mtime +10 -name "*.dbf" -exec rm -rf {} \;
转载请注明:梦绘设计 » 数据库 » ramn备份脚本和归档日志删除脚本
版权声明
本站《作品展示》类文章均为原创,转载必须注明出处,技术分享类文章部分来源于网络,版权归原作者所有,若侵权请留言。