忘了从哪看到的了,一直在用,觉得还行。
/orabak/scrript 脚本所在目录
/orabak/log rman使用log目录
/orabak/md 数据文件备份目录
/orabak/ctl 控制文件备份目录
/orabak/arch 归档备份目录
备份策略:
每天凌晨2:30备份,周日0级,周四1级,其他时间2级,最多恢复7天的内的状态
rman target /
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
*在NOCATLOG下模式,控制文件默认保存7天的备份集信息。所以如果制定的备份策略大于7天,则需要修改初始化参数CONTROL_FILE_RECORD_KEEP_TIME,使得CONTROL_FILE_RECORD_KEEP_TIME的值不小于备份策略的天数
0级备份文件rman_level0.rcv
connect target /
run{
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/orabak/ctl/ctl_%F';
ALLOCATE CHANNEL CH1 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
ALLOCATE CHANNEL CH2 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
ALLOCATE CHANNEL CH3 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
BACKUP INCREMENTAL LEVEL 0 TAG 'level 0' DATABASE
PLUS ARCHIVELOG FORMAT '/orabak/arch/arch%T_%U' DELETE ALL INPUT ;
RELEASE CHANNEL CH1;
RELEASE CHANNEL CH2;
RELEASE CHANNEL CH3;
}
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUPSET;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE ;
1级备份文件rman_level1.rcv
connect target /
run{
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/orabak/ctl/ctl_%F';
ALLOCATE CHANNEL CH1 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
ALLOCATE CHANNEL CH2 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
ALLOCATE CHANNEL CH3 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
BACKUP INCREMENTAL LEVEL 1 TAG 'level 1' DATABASE
PLUS ARCHIVELOG FORMAT '/orabak/arch/arch%T_%U' DELETE ALL INPUT ;
RELEASE CHANNEL CH1;
RELEASE CHANNEL CH2;
RELEASE CHANNEL CH3;
}
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUPSET;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE ;
2级备份文件rman_level2.rcv
connect target /
run{
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/orabak/ctl/ctl_%F';
ALLOCATE CHANNEL CH1 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
ALLOCATE CHANNEL CH2 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
ALLOCATE CHANNEL CH3 DEVICE TYPE DISK FORMAT '/orabak/md/md_%T_%U' maxpiecesize 4g;
BACKUP INCREMENTAL LEVEL 2 TAG 'level 2' DATABASE
PLUS ARCHIVELOG FORMAT '/orabak/arch/arch%T_%U' DELETE ALL INPUT ;
RELEASE CHANNEL CH1;
RELEASE CHANNEL CH2;
RELEASE CHANNEL CH3;
}
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUPSET;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE ;
备份脚本文件rman_bak.sh
#!/bin/bash
RUN_USER="oracle"
rq=`date "+%Y%m%d"`
fname="*$rq*"
if [ "$LOGNAME" != "$RUN_USER" ]; then
echo "Please run this script as $RUN_USER " >> /orabak/logs/$rq.log
exit 1
fi
cd $HOME
. .bash_profile
weekname=`date +%A`
case "$weekname" in
Sunday)
echo -n "Today is $weekname,Back oracle Level 0" >> /orabak/log/oracle.log
date "+ %Y-%m-%d %T Start to backup DateBase" >> /orabak/log/oracle.log
rman cmdfile=/orabak/script/rman_level0.rcv msglog=/orabak/log/$rq.log
date "+ %Y-%m-%d %T RMAN BACKUP finished " >> /orabak/log/oracle.log
;;
Thursday)
echo -n "Today is $weekname,Back oracle Level 1" >> /orabak/log/oracle.log
date "+ %Y-%m-%d %T Start to backup DateBase" >> /orabak/log/oracle.log
rman cmdfile=/orabak/script/rman_level1.rcv msglog=/orabak/log/$rq.log
date "+ %Y-%m-%d %T RMAN BACKUP finished " >> /orabak/log/oracle.log
;;
*)
echo -n "Today is $weekname,Back oracle Level 2" >> /orabak/log/oracle.log
date "+ %Y-%m-%d %T Start to backup DateBase" >> /orabak/log/oracle.log
rman cmdfile=/orabak/script/rman_level2.rcv msglog=/orabak/log/$rq.log
date "+ %Y-%m-%d %T RMAN BACKUP finished " >> /orabak/log/oracle.log
;;
esac
使用crontab定时执行rman_bak.sh
crontab -e
添加以下内容
30 02 * * * (/orabak/script/rman_bak.sh > /orabak/log/oracle 2>&1)