增备脚本


创建备份目录

mkdir    -p   /mnt/oradata/ordrbak
chown  -R   oracle:dba  /mnt/oradata/ordrbak
chmod  -R   /mnt/oradata/ordrbak

设定控制文件自动备份
configure controlfile autobackup on;

打开数据库跟踪选项(10g以后版本)
登陆sqlplus,打开块跟踪
SQL> alter database enable block change tracking using file '+DISKGROUP1/ora/datafile/ora_block_track.log';
查看块跟踪状态
set linesize 1000;
col filename format a30;
SQL> select filename,status,bytes from v$block_change_tracking;
关闭块跟踪
SQL> alter database disable block change tracking;


配置备份策略
要求
星期天做 0 级
星期一,二,四,五,六做 2 级
星期三 做1 级
必须有两个可用备份;能够恢复到7天以内的任何时刻

configure retention policy to redundancy 2;
configure retention policy to recovery window of 7 days;

设定定时运行任务crontab  -e编辑

30 3 * * 0-6 /opt/oracle/dbmon/rmanbak/startrman.sh

编辑选择备份类型脚本startrman.sh

 

. /home/oracle/.bash_profile
SH_HOME=/home/oracle/.bash_profile
export SH_HOME
DATE=`date +"%Y%m%d"`
week=`date +"%w"`

#-----------------------------------------------------------------------
#Confirm whether the oracle is runing
#-----------------------------------------------------------------------
ps -ef|grep dbw0_$ORACLE_SID |grep -v grep >>/dev/null

#-----------------------------------------------------------------------
#Begin to backup
#-----------------------------------------------------------------------
if [ $? -eq 0 ]; then
   if [ $week = "0" ] ; then
      rman target / @$SH_HOME/level0back.sql log=$SH_HOME/logs/rmanlevel0back`date +"%Y%m%d"`.log
   elif  [ $week = "3" ] ; then
      rman target / @$SH_HOME/level1back.sql log=$SH_HOME/logs/rmanlevel1back`date +"%Y%m%d"`.log 
   else 
      rman target / @$SH_HOME/level2back.sql log=$SH_HOME/logs/rmanlevel2back`date +"%Y%m%d"`.log
   fi
fi


编辑level0back.sql 脚本

run{                                                                                                              
allocate channel ch00 type  disk   maxpiecesize=1000m;                                                                            
allocate channel ch01 type  disk   maxpiecesize=1000m;                                                                            
allocate channel ch02 type  disk   maxpiecesize=1000m;                                                                            
backup incremental level 0  database include current controlfile format '/mnt/oradata/ordrbak/orderlevel0back_%d_%T_%s_%p' filesperset  3  plus
archivelog format '/mnt/oradata/ordrbak/orderarch_%d_%T_%s_%p' delete all input;                                           
release channel ch00;                                                                                               
release channel ch01;                                                                                                               
release channel ch02;
delete  noprompt  obsolete; 
}

编辑level1back.sql 脚本

run{                                                                                                              
allocate channel ch00 type  disk   maxpiecesize=1000m;                                                                            
allocate channel ch01 type  disk   maxpiecesize=1000m;                                                                            
allocate channel ch02 type  disk   maxpiecesize=1000m;                                                                            
backup incremental level 1 database include current controlfile format '/mnt/oradata/ordrbak/orderlevel1back_%d_%T_%s_%p' filesperset  3  plus
archivelog format '/mnt/oradata/ordrbak/orderarch_%d_%T_%s_%p' delete all input;                                           
release channel ch00;                                                                                               
release channel ch01;                                                                                                               
release channel ch02;
delete  noprompt  obsolete; 
}

编辑level2back.sql 脚本

run{                                                                                                              
allocate channel ch00 type  disk   maxpiecesize=1000m;                                                                            
allocate channel ch01 type  disk   maxpiecesize=1000m;                                                                            
allocate channel ch02 type  disk   maxpiecesize=1000m;                                                                            
backup incremental level 2 database include current controlfile format '/mnt/oradata/ordrbak/orderlevel2back_%d_%T_%s_%p' filesperset  3  plus
archivelog format '/mnt/oradata/ordrbak/orderarch_%d_%T_%s_%p' delete all input;                                           
release channel ch00;                                                                                               
release channel ch01;                                                                                                               
release channel ch02;
delete  noprompt  obsolete; 
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20844861/viewspace-591877/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20844861/viewspace-591877/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值