Oracle恢復實驗(四)

wallimn發表於2011-09-26
環境:Oracle10g、Red Hat 4,Oracle執行在歸檔模式。

場景:所有控制檔案和資料檔案丟失。

具體步驟:
1、主機斷電,導致資料檔案和所有控制檔案全部丟失
SQL> !rm -f /home/oracle/oracle/product/oradata/orcl/*.ctl

SQL> !rm -f /home/oracle/oracle/product/oradata/orcl/*.dbf

SQL> !ls /home/oracle/oracle/product/oradata/orcl
redo01.log redo02.log redo03.log

SQL> shutdown abort
ORACLE instance shut down.

2、嘗試開啟資料庫
SQL> startup
ORACLE instance started.

Total System Global Area 130023424 bytes
Fixed Size 1218100 bytes
Variable Size 62917068 bytes
Database Buffers 62914560 bytes
Redo Buffers 2973696 bytes
ORA-00205: error in identifying control file, check alert log for more info
提示找不到控制檔案

3、拷貝資料檔案和控制檔案
SQL> !cp /disk2/oracle/coldbak/*.ctl /home/oracle/oracle/product/oradata/orcl/

SQL> !cp /disk2/oracle/coldbak/*.dbf /home/oracle/oracle/product/oradata/orcl/

4、嘗試開啟資料庫
SQL> startup
ORACLE instance started.

Total System Global Area 130023424 bytes
Fixed Size 1218100 bytes
Variable Size 62917068 bytes
Database Buffers 62914560 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-00338: log 2 of thread 1 is more recent than control file
ORA-00312: online log 2 thread 1:
'/home/oracle/oracle/product/oradata/orcl/redo02.log'
提示控制檔案比較舊,記錄的日誌序號比redo日誌的小。

5、獲取重建控制檔案的指令碼
SQL> alter database backup controlfile to trace;

Database altered.
從udump目錄中找到指令碼。
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oracle/product/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oracle/product/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oracle/product/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oracle/product/oradata/orcl/system01.dbf',
'/home/oracle/oracle/product/oradata/orcl/undotbs01.dbf',
'/home/oracle/oracle/product/oradata/orcl/sysaux01.dbf',
'/home/oracle/oracle/product/oradata/orcl/users01.dbf'
CHARACTER SET AL32UTF8
;

6、重啟資料庫到nomount狀態、執行重建控制檔案指令碼
SQL> shutdown immediate

Database dismounted.
ORACLE instance shut down.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 130023424 bytes
Fixed Size 1218100 bytes
Variable Size 62917068 bytes
Database Buffers 62914560 bytes
Redo Buffers 2973696 bytes

7、嘗試開啟資料庫
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/home/oracle/oracle/product/oradata/orcl/system01.dbf'

8、介質恢復
SQL> recover database;
Media recovery complete.

9、開啟資料庫
SQL> alter database open;

Database altered.

SQL> conn scott/oracle
Connected.
SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
RECOVER_TEST TABLE
RECOVER_TEST2 TABLE

6 rows selected.

SQL> select count(*) from recover_test2;

COUNT(*)
----------
28672

相關文章