这是我参与8月更文挑战的第19天,活动详情查看:8月更文挑战
1. 创建rman备份所需目录
oracle用户下创建,目录名可自定义,保证目录所在磁盘空间充足即可。
su – oracle
mkdir rmanbackup
mkdir scripts/log -p
2. 编写rman备份脚本
注意根据实际环境修改对应路径及数据库实例名:
全量备份脚本rmanbackup0.sh
#!/bin/sh
DATE=`date +%Y-%m-%d`
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl
$ORACLE_HOME/bin/rman cmdfile /home/oracle/scripts/backup0.rcv log=/home/oracle/scripts/log/rman_full_$DATE.log
增量备份脚本rmanbackup1.sh
#!/bin/sh
DATE=`date +%Y-%m-%d`
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl
$ORACLE_HOME/bin/rman cmdfile /home/oracle/scripts/backup1.rcv log=/home/oracle/scripts/log/rman_inc_$DATE.log
backup0.rcv
connect target /
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup incremental level 0 format '/rmanbackup/orcl_full_%U' database include current controlfile;
delete noprompt obsolete device type disk;
sql 'alter system archive log current';
backup format '/rmanbackup/orcl_arch_full_%U' archivelog all not backed up delete input;
crosscheck backup;
delete noprompt expired backup;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
backup1.rcv
connect target /
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup incremental level 1 format '/rmanbackup/orcl_inc_%U' database;
delete noprompt obsolete device type disk;
sql 'alter system archive log current';
backup format '/rmanbackup/orcl_arch_inc_%U' archivelog all not backed up delete input;
crosscheck backup;
delete noprompt expired backup;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
3. 修改备份保留策略
rman备份保留策略调整为保留2次全备(默认保留一次全备),oracle用户运行
rman target /
configure retention policy to redundancy 2;
show all;
4. 创建定时任务
备份策略为每周六全量备份,其他时间每天增量备份,保留2次全备。
Oracle用户下,授予脚本可执行权限
chmod u+x /home/oracle/scripts/rmanbackup1.sh
chmod u+x /home/oracle/scripts/rmanbackup0.sh
添加定时计划
crontab -e
添加如下内容:
0 23 * * 6 /home/oracle/scripts/rmanbackup0.sh
0 23 * * 0,1,2,3,4,5 /home/oracle/scripts/rmanbackup1.sh
crontab -l
5. rman备份监控
数据库中运行如下命令可查看数据库rman备份情况
crontab -e
添加如下内容:
0 23 * * 6 /home/oracle/scripts/rmanbackup0.sh
0 23 * * 0,1,2,3,4,5 /home/oracle/scripts/rmanbackup1.sh
crontab -l
status一列显示COMPLETED,即为备份成功。
若为其他状态可查询当日rman备份日志,查看备份异常原因: