ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 增备脚本

增备脚本

原创 Linux操作系统 作者:oralau 时间:2009-04-27 00:18:29 0 删除 编辑


创建备份目录

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/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 全备脚本
下一篇: 完全恢复
请登录后发表评论 登录
全部评论

注册时间:2009-02-17

  • 博文量
    38
  • 访问量
    36529