系统:CentOS5.11
Oracle版本:Oracle10g
# su - oracle
--切换至oracle用户,创建存放脚本及日志的文件夹
$ mkdir -p /home/oracle/rman/script/
$ mkdir -p /home/oracle/rman/log/
$ cd /home/oracle/rman/script/
--进入脚本目录,创建脚本文件
$ touch run_oraprd_level0.rcv
$ touch run_oraprd_level1.rcv
$ touch run_oraprd_level0.sh
$ touch run_oraprd_level1.sh
$ vim run_oraprd_level0.rcv
--编辑脚本文件
run{
BACKUP INCREMENTAL LEVEL=0 DATABASE;
sql 'alter system archive log current';
backup archivelog all;
backup current controlfile;
}
$ vim run_oraprd_level0.sh
export ORACLE_SID=orcl
export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
cmd_file=/home/oracle/rman/script/run_oraprd_level0.rcv
log_file=/home/oracle/rman/log/'LEVEL0_backup_'$(date '+%Y%m%d').log
/opt/oracle/product/10.2.0/db_1/bin/rman target / cmdfile=$cmd_file log=$log_file
date >> $log_file
$ vim run_oraprd_level1.rcv
run{
BACKUP INCREMENTAL LEVEL=1 CUMULATIVE DATABASE;
sql 'alter system archive log current';
backup archivelog all;
backup current controlfile;
}
$ vim run_oraprd_level1.sh
export ORACLE_SID=orcl
export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
cmd_file=/home/oracle/rman/script/run_oraprd_level1.rcv
log_file=/home/oracle/rman/log/'LEVEL1_backup_'$(date '+%Y%m%d').log
/opt/oracle/product/10.2.0/db_1/bin/rman target / cmdfile=$cmd_file log=$log_file
date >> $log_file
$ chmod +x run_oraprd_level0.sh
--给脚本文件添加“可执行”的权限,下同
$ chmod +x run_oraprd_level1.sh
$ crontab -e
--添加计划任务
0 2 * * 0 /home/oracle/rman/script/run_oraprd_level0.sh
--即:每周日的凌晨2点0分,执行脚本run_oraprd_level0.sh
0 2 * * 1 /home/oracle/rman/script/run_oraprd_level1.sh
--即:每周一的凌晨2点0分,执行脚本run_oraprd_level1.sh
0 2 * * 2 /home/oracle/rman/script/run_oraprd_level1.sh
0 2 * * 3 /home/oracle/rman/script/run_oraprd_level1.sh
0 2 * * 4 /home/oracle/rman/script/run_oraprd_level1.sh
0 2 * * 5 /home/oracle/rman/script/run_oraprd_level1.sh
0 2 * * 6 /home/oracle/rman/script/run_oraprd_level1.sh
完成!
可测试下脚本文件是否能正常执行
$ sh /home/oracle/rman/script/run_oraprd_level0.sh
该备份文件在以下路径(不同的oracle数据库版本的路径可能不同):
/opt/oracle/fast_recovery_area/ORCL/backupset/
删除的方法见:Oracle数据库 之 删除RMAN备份