日期:2014-05-16  浏览次数:20352 次

rman实验之归档模式有备份,正常关机丢失控制文件的恢复

    在恢复控制文件之前,必须知道目标数据库的DBID。身为DBA的你,在接手数据库时,定要把数据库的DBID给备份出来!

    1)备份控制文件

RMAN> list backup of controlfile;


    2)测试数据

hr@ORCL> create table t (name varchar2(20));

Table created.

hr@ORCL> insert into t values('think');

1 row created.

hr@ORCL> commit;

Commit complete.


    3)模拟环境

sys@ORCL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ORCL> host rm -rf /u01/app/oracle/oradata/ORCL/controlfile/*

sys@ORCL> startup 
ORACLE instance started.

Total System Global Area  419430400 bytes
Fixed Size                  1219760 bytes
Variable Size             150995792 bytes
Database Buffers          264241152 bytes
Redo Buffers                2973696 bytes
ORA-00205: error in identifying control file, check alert log for more info

    由于控制文件丢失,肯定是启动不到mount状态了。

    4)修复控制文件

    因为nocatalog下,rman的备份信息及环境配置等都在控制文件里,而控制文件又丢失了,所以以前你对rman做的很多自定义设置都没有了,包括自动备份。

RMAN> set DBID=1316499950

executing command: SET DBID

RMAN> restore controlfile from '/u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_08_08/o1_mf_ncnnf_TAG20120808T101321_823lt24m_.bkp';

Starting restore at 08-AUG-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/ORCL/controlfile/o1_mf_823mrrdo_.ctl
output filename=/u01/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_823mrrrp_.ctl
Finished restore at 08-AUG-12

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1


    5)恢复数据库

    由于数据文件都在,只需要重新运用备份控制文件之后生成的那些重做日志文件即可

RMAN> recover database;


    6)resetlogs打开数据库

    由于通过备份的控制文件恢复,因此打开时必须指定resetlogs

RMAN> alter database open resetlogs;

database opened

RMAN> list incarnation of database;


List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1       1       ORCL     1316499950       PARENT  1          30-JUN-05
2       2       ORCL     1316499950       PARENT  446075     15-JUL-12
3       3       ORCL     1316499950       CURRENT 604802     08-AUG-12


    7)查询数据

hr@ORCL> select * from t;

NAME
--------------------
think

    ok,everything is perfect。