1、用oracle身份登陆
2、编写自动备份的脚本并清除归档日志
$ vi /home/oracle/backs.sh
#!/bin/sh
source /home/oracle/.bash_profile
cd $ORACLE_HOME/bin
rman target / nocatalog msglog=/home/oracle/rman_bk_`date '+%Y%m%d%H%M%S'`.log <
run{
REPORT OBSOLETE;
DELETE force NOPROMPT OBSOLETE;
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup incremental level=0 database tag 'level0' format '/home/oracle/dblevel0_%s_%T' ;
backup current controlfile tag 'ctl' format '/home/oracle/ctl_%s_%p_%t';
sql 'alter system archive log current';
crosscheck archivelog all;
backup filesperset 3 archivelog all tag 'arch' format '/home/oracle/oarch_%u_%s_%p' delete input;
release channel c1;
release channel c2;
release channel c3;
}
exit;
EOF
备注:
log日志文件名最后的格式如bk_年月日小时分钟秒.log
rman_bk_20120102101501.log
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)
3、设置RMAN自动运行保存数据库的脚本
vi /home/oracle/runback.sh
#!/bin/sh
source /home/oracle/backs.sh
4、设置RMAN自动备份在脚本的执行时间,这边的时间是每天的10点15分
crontab -e
3 10 * * * /home/oracle/runback.sh