[原创]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.查询归档目录:
  sql>show parameter db_recovery;
  2.查看归档是否打开:
  sql>archive log list;
  或
  sql>select log_mode from v$database;
  3.开启归档模式:
  sql>shutdown immediate;
  sql>startup mount;
  sql>alter database archivelog;
  sql>alter database open;
  4.更改归档路径:
  sql>alter system set log_archive_dest='/data/oracle/app/oracle/fast_recovery_area' scope=spfile;;
  sql>shutdown immediate;
  sql>startup;
================================================================================================================
一、备份:
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;
================================================================================================================

  

posted @ 2018-02-04 17:12  wsjhk  阅读(807)  评论(0编辑  收藏  举报