RMAN配置自动增量备份

#!/bin/bash
 
set -e

 #############################################################
  # sunday incremental level 0
  # other day incremental level 1
 #
 
 #############################################################
 
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
rman_bin=$ORACLE_HOME/bin/rman
 
 weekday=`date +%a`
 case "${weekday}" in
 
     "Sun")
         inc_level=0
         ;;

     "Wed")
         inc_level=1
         ;;

     *)
         inc_level=1
         ;;
 esac
 
 rman_user=sys
 rman_passwd=oracle
 catalog_inst_name=orcl
 
 target_sys_passwd=oracle
 target_inst_name=orcl
 
 log_file=/home/oracle/tmp/backup/log/`date +%F`_${inc_level}.log
 bak_file=/home/oracle/tmp/backup/bkfile/'bak_%T_%U'
 arc_file=/home/oracle/tmp/backup/bkfile/'arc_%T_%U'
 ctl_file=/home/oracle/tmp/backup/bkfile/'ctl_%F'
 
 $rman_bin log ${log_file} >> /dev/null 2>&1 <<EOF
 
 connect catalog ${rman_user}/${rman_passwd}@${catalog_inst_name};
 connect target sys/${target_sys_passwd}@${target_inst_name};
 
 run {
     configure backup optimization on;
     configure archivelog deletion policy to applied on standby;
     configure retention policy to redundancy 3;
     configure controlfile autobackup on;
     configure controlfile autobackup format for device type disk to '${ctl_file}';
 
     allocate channel ch1 device type disk;
     backup incremental level ${inc_level} cumulative database format '${bak_file}' skip readonly plus archivelog format '${arc_file}';
 
     release channel ch1;
 }
 
 crosscheck backup;
 delete noprompt obsolete;
 
 delete noprompt archivelog all completed before 'sysdate - 14';

 
 exit;
 EOF
 
 exit 0

******

用cron创建定时执行任务,默认情况下,cron为开机自动启动的
 执行 crontab –e 添加以下语句:
00 01 * * * sh /u01/backup/backup.sh
保存退出

 

posted @ 2013-05-29 16:47  andybox  阅读(222)  评论(0编辑  收藏  举报