linux 下 rman自动备份

第一步:准备目录 

以root用户执行:

mkdir /backup_rman
chown -R oracle:oinstall  /backup_rman

#chown -R oracle:oinstall  /data_sda5

chmod 755 /backup_rman

第二步:备份脚本程序的编写

切换到oralce,新建一个目录来放rman脚本

su - oracle
cd ..

mkdir rman_shell
cd rman_shell

touch rman_backup.sh
chmod 755 rman_backup.sh

以下是rman_backup.sh内容:(手动分配channel只能在run{}中或maintenance配置)

#!/bin/sh
# backup oracle use rman
# by taowang2016 on 2013-03-21

source /home/oracle/.bash_profile

#define rman log format
rq=` date +"20%y-%m-%d--%H:%M:%S" `
rman_log=/home/oracle

find /backup_rman/ -mtime 1 | tee /backup_rman/level0_backup.log  | xargs rm -rf

rman target / log=$rman_log/backupall_${rq}.log <<eof
run{
   allocate channel d1 type disk;
   allocate channel d2 type disk;
   
   backup incremental level 0 format '/backup_rman/0full_%d_%s_%T.bak'
    tag='level 0' database plus archivelog;
   
   backup current controlfile format '/backup_rman/ctl_%d_%s_%T.bak';
   
   allocate channel d3 type disk;
   backup archivelog all format '/data_sda5/0arc_%d_%s_%T.bak' delete input;
   
   release channel d1;
   release channel d2;
   release channel d3;
   }
   
   crosscheck backup;
   delete noprompt expired backup;
   crosscheck archivelog all;
   delete noprompt expired archivelog all;
   exit
   eof

exit 0  

 

 

第三步:添加crontab计划任务

使用oracle用户添加例行任务:
crontab -e
新打开的窗口中添加一下内容:(这里rman_backup.sh的位置要根据实际情况填写)
0 24 * * * /home/oracle/bin/rman_backup.sh
(*/3 * * * * /home/oracle/bin/rman_backup.sh)
注,括号内的可以是做测试的时候用的,每三分钟执行一次备份,例为每天凌晨24点执行备份

第四步:执行验证:
1、crontab成功执行验证:
在root下执行tail -f /var/log/cron,监控cron日志来确保crontab的成功执行:

Aug 31 00:20:06 model crontab[6380]: (oracle) BEGIN EDIT (oracle)
Aug 31 00:20:48 model crontab[6380]: (oracle) REPLACE (oracle)
Aug 31 00:20:48 model crontab[6380]: (oracle) END EDIT (oracle)
Aug 31 00:21:01 model crond[26958]: (oracle) RELOAD (cron/oracle)
Aug 31 00:21:01 model crond[6412]: (oracle) CMD (/home/oracle/bin/rman_backup.sh)
Aug 31 00:24:01 model crond[6621]: (oracle) CMD (/home/oracle/bin/rman_backup.sh)

2、查看rman是否执行,并且执行成功
a.可在rman执行的时候执行ps -ef | grep rman | grep -v grep来查看rman进程是否成功启动
b.查看/backup_rman目录中是否有备份生成的文件:

$ oracle@model /backup_rman> ls
rman_20120831_CTL_0mnjvu15_1_1     rman_full_20120831_0injvtrq_1_1
rman_20120831_CTL_0vnjvu57_1_1     rman_full_20120831_0jnjvtvs_1_1
rman_20120831_SPFILE_0nnjvu18_1_1  rman_full_20120831_0knjvu0c_1_1
rman_20120831_SPFILE_10njvu5a_1_1  rman_full_20120831_0lnjvu13_1_1
rman_full_201208310021.log         rman_full_20120831_0onjvu1a_1_1
rman_full_201208310024.log         rman_full_20120831_0pnjvu1e_1_1
rman_full_20120831_0dnjvtrg_1_1    rman_full_20120831_0qnjvu1e_1_1
rman_full_20120831_0enjvtrg_1_1    rman_full_20120831_0rnjvu1i_1_1
rman_full_20120831_0fnjvtrg_1_1    rman_full_20120831_0snjvu4s_1_1
rman_full_20120831_0gnjvtrp_1_1    rman_full_20120831_0tnjvu52_1_1
rman_full_20120831_0hnjvtrp_1_1    rman_full_20120831_0unjvu55_1_1

验证结果:rman自动备份任务执行成功!

同时可参考以下文章:
http://blog.sina.com.cn/s/blog_67be3b45010180wy.html
http://blog.sina.com.cn/s/blog_7012bd080100lybe.html

http://www.2cto.com/os/201109/106291.html
http://www.oschina.net/question/565065_70713

http://xjsunjie.blog.51cto.com/blog/999372/823478

posted @ 2013-03-21 18:05  taowang2016  阅读(762)  评论(0编辑  收藏  举报