linux基于cron的rman自动增量备份脚本及设置

linux基于cron的rman自动增量备份脚本及设置

rman及catalog运行于linux,target数据库运行于windows,oracle版本一致,而且都是64位平台。

历史原因数据库运行于windows,但显然linux更适合于系统管理,因此此处rman暂时运行于混合环境。

备份策略

数据库用于OLTP系统,容量中等,全库接近400G,但有大约200G的数据是不变化只用于查询的,将其表空间置于read only模式,备份时可以忽略这些数据。其他200G左右的数据每天都在发生变化,如果系统需要回复,要尽可能的恢复到最新的数据。已经做了dataguard灾备

基于以上情况制定备份策略,每周日凌晨做0级备份,周一到周六做1级备份。

target数据库要打开块变化追踪机制,然后建立恢复目录

备份脚本


 1 #!/bin/bash
 2 
 3 set -e
 4 
 5 #############################################################
 6 # sunday incremental level 0
 7 # other day incremental level 1
 8 #
 9 # rman and catalog on oracle 10.2.0.4 64bits for debian amd64
10 # target on oracle 10.2.0.4 64bits for windows 2003 r2 sp2 x64 
11 #############################################################
12 
13 export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
14 rman_bin=$ORACLE_HOME/bin/rman
15 
16 weekday=`date +%a`
17 case "${weekday}" in
18 
19     "Sun")
20         inc_level=0
21         ;;
22     *)
23         inc_level=1
24         ;;
25 esac
26 
27 rman_user=rman_usr
28 rman_passwd=rman_usr
29 catalog_inst_name=catalogd
30 
31 target_sys_passwd=oracle
32 target_inst_name=db_test
33 
34 log_file=/var/log/rman/`date +%F`_${inc_level}.log
35 bak_file=d:\rman_bak\bak_%U
36 arc_file=d:\rman_bak\arc_%U
37 ctl_file=d:\rman_bak\ctl_%F
38 
39 $rman_bin log ${log_file} >> /dev/null 2>&1 <
40 
41 connect catalog ${rman_user}/${rman_passwd}@${catalog_inst_name};
42 connect target sys/${target_sys_passwd}@${target_inst_name};
43 
44 run {
45     configure backup optimization on;
46     configure archivelog deletion policy to applied on standby;
47     configure retention policy to redundancy 3;
48     configure controlfile autobackup on;
49     configure controlfile autobackup format for device type disk to ‘${ctl_file}‘;
50 
51     allocate channel ch1 device type disk;
52     backup incremental level ${inc_level} cumulative database format ‘${bak_file}‘ skip readonly plus archivelog format ‘${arc_file}‘;
53 
54     release channel ch1;
55 }
56 
57 crosscheck backup;
58 delete noprompt obsolete;
59 
60 delete noprompt archivelog all completed before ‘sysdate – 14′;
61 
62 exit;
63 EOF
64 
65 exit 0

rman操作日志记录于/var/log/rman目录下,需要在/var/log目录先新建rman子目录,不然rman会报错无法打开log文件。脚本很简单,就不解释了。

自动运行

打开/etc/crontab,编辑cron.daily所在的那行,将其第一个字段m(minute)改为0或其他小于60的数值,第二个字段h(hour)改为0,这样以来cron守护程序每天的0点稍后自动运行/etc/cron.daily目录下的脚本。然后将备份脚本拷贝到/etc/cron.daily目录下,注意为备份脚本添加可执行权限。

特别注意:crond或者直接说run-parts不会执行带有.sh扩展名的脚本,也就说/etc/cron.*/目录下的脚本不要带任何扩展名。

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

转载于:http://blog.itpub.net/17252115/viewspace-742419/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值