當前控制檔案全部丟失恢復

orclwujian發表於2015-04-28

當前控制檔案全部丟失恢復實驗、
(該情況模擬所有線上控制檔案丟失,正常情況下控制檔案有多份放在不同的磁碟上,如果損壞當前的控制檔案,可以將其他線上控制檔案CP過去就行了)
先給資料庫做個全備
[orcl@gitiracb ~]$ rman target/

Recovery Manager: Release 11.2.0.3.0 - Production on Tue Apr 28 14:53:33 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1405653344)

RMAN> run{
         allocate channel c1 type disk;
         allocate channel c2 type disk;
         backup incremental level 0 tag 'db0' format '/backup/db0%d_%s_%p_%t'
         database skip inaccessible;
         sql 'alter system archive log current';
         backup format '/backup/arch%d_%s_%p_%t'
         archivelog all delete input;
         backup format '/backup/ctl%d_%s_%p_%t' current controlfile;
         release channel c1;
         release channel c2;
         }

之後再到資料庫裡建立一些資料
SQL> create table test as select * from dba_objects where rownum<=2000;

Table created.

SQL> select count(*) from test;

  COUNT(*)
----------
      2000
查詢線上控制檔案所在目錄
SQL> set linesize100;
SQL> show parameter control_files;

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
control_files                        string                 /home/orcl/app/oradata/orcl/co
                                                            ntrol01.ctl, /home/orcl/app/fa
                                                            st_recovery_area/orcl/control0
                                                            2.ctl
可以看到有兩個線上控制檔案
我們用rm掉兩個控制檔案
我可以在alter檔案中看到下面的錯誤
Errors in file /home/orcl/app/diag/rdbms/orcl/orcl/trace/orcl_m001_11273.trc:
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/home/orcl/app/oradata/orcl/control01.ctl'
ORA-27041: unable to open file

關閉資料庫
SQL> shutdown immediate;
Database closed.
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/home/orcl/app/oradata/orcl/control01.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
嘗試用abort關閉
SQL> shutdown abort;
ORACLE instance shut down.
成功關閉
嘗試startup開啟資料庫
SQL> startup;
ORACLE instance started.

Total System Global Area 3373858816 bytes
Fixed Size                  2233040 bytes
Variable Size            1845497136 bytes
Database Buffers         1509949440 bytes
Redo Buffers               16179200 bytes
ORA-00205: error in identifying control file, check alert log for more info
無法開啟,只能從之前的備份中恢復控制檔案,並執行不完全恢復

RMAN> restore controlfile from '/backup/ctlORCL_26_1_878223591';

Starting restore at 28-APR-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=98 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/orcl/app/oradata/orcl/control01.ctl
output file name=/home/orcl/app/fast_recovery_area/orcl/control02.ctl
Finished restore at 28-APR-15
利用備份恢復控制檔案
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1
無法open控制檔案是用之前的備份還原的,與當前資料庫的物理結構和SCN號不一致,需restore資料庫,再用歸檔日誌recover database;
RMAN> restore database;
RMAN> recover database;  

RMAN> alter database open resetlogs;
database opened

SQL> select count(*) from test;

  COUNT(*)
----------
      2000

可以看到資料正常



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29989552/viewspace-1609027/,如需轉載,請註明出處,否則將追究法律責任。

相關文章