码迷,mamicode.com
首页 > 数据库 > 详细

Oracle Rman备份脚本与自动删除重复备份文件

时间:2015-05-26 14:29:42      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:oracle   rman   

#!/bin/sh
source /home/oracle/.bash_profile


if [ -z $1 ]
then
  echo "Please Input a number,Usage: 0|1|2"
  exit
else
  RMAN_LEVEL=$1
fi


export ORACLE_SID=xxxx
export TODAY=`date '+%Y%m%d'`
export RMAN_DIR=/backup/archivelog/rman/$ORACLE_SID/$TODAY-$RMAN_LEVEL




mkdir -p $RMAN_DIR
cd $RMAN_DIR
LogFile=ora_rman_bk_$ORACLE_SID-L$RMAN_LEVEL-`date '+%Y%m%d'`.log


# rman backup 
rman target /  msglog=$RMAN_DIR/$LogFile<<EOF
delete noprompt obsolete; 
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$RMAN_DIR/cf%F';
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset incremental level $RMAN_LEVEL filesperset 3 tag 'dbL$RMAN_LEVEL' format '$RMAN_DIR/ora_o_%d_%t%s%p%u'
 database skip readonly include current controlfile;
sql 'alter system archive log current' ;
backup(archivelog all format '$RMAN_DIR/ora_a_%d_%t%s%p%u' delete input);
release channel c1;
release channel c2;
}


list backup;
exit;
EOF


#mail backup log
mail -s "$ORACLE_SID rman L$RMAN_LEVEL backup log $TODAY"  email_name@126.com < $RMAN_DIR
/$LogFile



顺便提一嘴:

delete noprompt obsolete与delete obsolete区别

noprompt :是不用提示,在shell脚本中不需要对发起的delete命令进行“yes or no”的确认。



在crontab 中设置如下:
0 4 * * 5 sh /backup/scripts/oracle/oracle_rman_bak.sh 0 > /backup/archivelog/logs/rman.log 2>&1
0 4 * * 2 sh /backup/scripts/oracle/oracle_rman_bak.sh 1 > /backup/archivelog/logs/rman.log 2>&1

进行一周一次增量与0级备份。

Oracle Rman备份脚本与自动删除重复备份文件

标签:oracle   rman   

原文地址:http://blog.csdn.net/zhangbiaobiaobiao/article/details/46006463

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!