[原创]Oracle 12c的备份和恢复策略

Posted wsjhk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[原创]Oracle 12c的备份和恢复策略相关的知识,希望对你有一定的参考价值。

Oracle 12c的备份和恢复策略(RMAN备份[开启归档/控制文件/数据文件/归档日志]):
备份策略:
	* 每半年做一个数据库的全备份(包括所有的数据和只读表空间) 
	* 每周做一次零级备份
	* 每天做一次一级备份 
*备份前设置rman的参数:configure controlfile autobackup on;(RMAN> show all;查看参数)
--crontab定时任务:
0 1 1 1,7 * oracle /bin/bash /data/oracle/backup/rman_bak_full.sh >>/tmp/rman_backup.log 2>&1
0 1 * * 0 oracle /bin/bash /data/oracle/backup/rman_bak_0.sh >>/tmp/rman_backup.log 2>&1
0 1 * * 1-6 oracle /bin/bash /data/oracle/backup/rman_bak_1.sh >>/tmp/rman_backup.log 2>&1
================================================================================================================
一、备份:
1)数据库全备份的脚本:
#cat /data/oracle/backup/rman_bak_full.sh
#!/bin/bash

export ORACLE_SID=bieeocrl
export ORACLE_BASE=/data/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT=‘YYYY-MM-DD HH24:MI:SS‘

curr_t=`date +%Y%m%d%H%M%S`
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘Start FULL Backup at ‘`date +%Y-%m-%d:%H:%M:%S` | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log

rman target / nocatalog log /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log append<<EOF_RMAN
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full tag ‘dbfull‘ format ‘/data/oracle/backup/bieeocrl/full_bak_%U_%s_%T‘ as compressed backupset database include current controlfile;
sql ‘alter system archive log current‘;
backup archivelog all delete input tag=‘arch_bak‘ format ‘/data/oracle/backup/bieeocrl/arch_%U_%s_%T‘;
backup current controlfile tag=‘ctl_bak‘format ‘/data/oracle/backup/bieeocrl/full_control_%U_%s_%T‘;
backup spfile tag=‘spfile_bak‘ format ‘/data/oracle/backup/bieeocrl/spfile_%U_%s_%T‘;#参数文件备份可选
release channel c1;
release channel c2;
release channel c3;
}
EOF_RMAN
2)零级备份的脚本:
#cat /data/oracle/backup/rman_bak_0.sh
#!/bin/bash

export ORACLE_SID=bieeocrl
export ORACLE_BASE=/data/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT=‘YYYY-MM-DD HH24:MI:SS‘

curr_t=`date +%Y%m%d%H%M%S`
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘Start level 0 Backup at ‘`date +%Y-%m-%d:%H:%M:%S` | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log

rman target / nocatalog log "/data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log" append<<EOF_RMAN
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup incremental level 0 tag ‘db0‘ format ‘/data/oracle/backup/bieeocrl/db0_%U_%s_%T‘ as compressed backupset database;
sql ‘alter system archive log current‘;
backup archivelog all delete input tag=‘arch_bak‘ format ‘/data/oracle/backup/bieeocrl/arch0_%U_%s_%T‘;
backup current controlfile tag=‘ctl_bak‘format ‘/data/oracle/backup/bieeocrl/db0_control_%U_%s_%T‘;
backup spfile tag=‘spfile_bak‘ format ‘/data/oracle/backup/bieeocrl/spfile0_%U_%s_%T‘;#参数文件备份可选
release channel c1;
release channel c2;
release channel c3;
}
EOF_RMAN
3)一级备份的脚本:
#cat /data/oracle/backup/rman_bak_1.sh
#!/bin/bash

export ORACLE_SID=bieeocrl
export ORACLE_BASE=/data/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT=‘YYYY-MM-DD HH24:MI:SS‘

curr_t=`date +%Y%m%d%H%M%S`
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘Start level 1 Backup at ‘`date +%Y-%m-%d:%H:%M:%S` | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log

rman target / nocatalog log /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log append<<EOF_RMAN
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup incremental level 1 tag ‘db1‘ format ‘/data/oracle/backup/bieeocrl/db1_%U_%s_%T‘ as compressed backupset database;
sql ‘alter system archive log current‘;
backup archivelog all delete input tag=‘arch_bak‘ format ‘/data/oracle/backup/bieeocrl/arch1_%U_%s_%T‘;
backup current controlfile tag=‘ctl_bak‘format ‘/data/oracle/backup/bieeocrl/db1_control_%U_%s_%T‘;
backup spfile tag=‘spfile_bak‘ format ‘/data/oracle/backup/bieeocrl/spfile1_%U_%s_%T‘;#参数文件备份可选
release channel c1;
release channel c2;
release channel c3;
}
EOF_RMAN
如果按照以上oracle备份策略,则每天的所需要备份的数据量只有一天的改变量。而做恢复时最多要恢复一个零级备份+六个一级备份。
================================================================================================================
二、恢复数据库的过程:
1)rman target / nocatalog
2)RMAN> startup nomount;
3)RMAN> restore spfile from ‘/data/oracle/backup/bieeocrl/db0_%U_%s_%T‘;
4)RMAN> shutdown immediate;
5)RMAN> startup nomount;
6)RMAN> restore controlfile from ‘/data/oracle/backup/bieeocrl/db0_control_%U_%s_%T‘;
7)RMAN> alter database mount;
8)RMAN> catalog start with ‘/data/oracle/backup/bieeocrl/arch0_%U_%s_%T‘;
9)RMAN> run{
allocate channel ch1 type disk;
restore database;
recover database;
release channel ch1;
}
10)RMAN> alter database open resetlogs;
11)RMAN> shutdown immediate;
12)RMAN> startup;
================================================================================================================

  

以上是关于[原创]Oracle 12c的备份和恢复策略的主要内容,如果未能解决你的问题,请参考以下文章

12c RMAN 表级恢复

技术指南:在Oracle Database 11g和12c中使用恢复目录的关键技术及相关热门认证推荐

Oracle 12C rman

案例:Oracle dul数据挖掘 非常规对ORACLE 12C CDB数据库进行恢复

oracle11g和12c有啥区别?

Oracle数据库备份恢复基础讲解_超越OCP精通Oracle视频教程培训12