catalog損壞情況下的資料庫恢復例項

rainbowbridg發表於2007-08-08

catalog損壞情況下的資料庫恢復例項

一.環境描述

1.執行環境:HP小型機,HPUX作業系統,Oracle 9.2.0.1,OpenView Data Protector備份管理軟體,ESL9000帶庫。

資料庫全備指令碼:

run {

allocate channel 'dev_0' type 'sbt_tape'

parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=oratest,OB2BARLIST=test2oratest)';

backup incremental level filesperset 1

format 'test2oratest.dbf'

database

include current controlfile;

sql 'alter system archive log current';

}

歸檔日誌備份指令碼:

run {

allocate channel 'dev_0' type 'sbt_tape'

parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=oratest,

OB2BARLIST=test2oratestarchivelog)';

backup incremental level filesperset 1

format 'test2oratestarchivelog.dbf'

archivelog all delete input;

}

2.故障描述:Oracle資料庫(測試庫)執行在歸檔模式下。正常情況下,備份管理軟體呼叫Oracle RMAN進行全庫和歸檔日誌備份。備份檔案儲存在ESL9000磁帶庫上。由於磁碟陣列故障,造成目標資料庫控制檔案和資料檔案全部損壞;同時,存放catalog的資料庫也被損壞。

由於catalog損壞,RMAN無法透過catalog找到備份集,restore無法成功。由於沒有控制檔案,資料庫僅能啟動到nomount狀態下。

二.背景知識

在Oracle 816 以後的版本中,Oracle提供了一個包:DBMS_BACKUP_RESTORE。 DBMS_BACKUP_RESTORE 包是由dbmsbkrs.sql 和 prvtbkrs.plb 這兩個指令碼建立的。 catproc.sql 指令碼執行後會呼叫這兩個包。所以每個資料庫都有的這個包作為Oracle伺服器和作業系統之間IO操作的介面,由RMAN直接呼叫。我們可以在資料庫nomount 情況下呼叫這些包 ,來達到資料庫恢復的目的。

三.恢復步驟

1.查詢備份集

備份集可以在Data Protector的internal database中或日誌記錄中找到。具體內容(根據需要做了剪裁)如下:

SBT-25032 (?) 10/08/04 10:42:54 [Normal] From: "oratest" Time: 10/08/04 10:42:54

Starting OB2BAR Backup: 05 test2:test2oratest<539001683:1>.dbf // Oracle8

SBT-25032 (?) 10/08/04 10:46:14 [Normal] From: "oratest" Time: 10/08/04 10:46:14

Completed OB2BAR Backup: 05 test2:test2oratest<539001683:1>.dbf // Oracle8

SBT-25032 (?) 10/08/04 10:46:22 [Normal] From: "oratest" Time: 10/08/04 10:46:22

Starting OB2BAR Backup: 05 test2:test2oratest<539001979:1>.dbf // Oracle8

SBT-25032 (?) 10/08/04 11:02:45 [Normal] From: "oratest" Time: 10/08/04 11:02:45

Completed OB2BAR Backup: 05 test2:test2oratest<539001979:1>.dbf // Oracle8

SBT-28813 (?) 10/08/04 11:34:57 [Normal] From: "oratest" Time: 10/08/04 11:34:57

Starting OB2BAR Backup: 05 test2:test2oratestarchivelog<539004793:1>.dbf // Oracle8

SBT-28813 (?) 10/08/04 11:35:17 [Normal] From: "oratest" Time: 10/08/04 11:35:17

Completed OB2BAR Backup: 05 test2:test2oratestarchivelog<539004793:1>.dbf // Oracle8

。。。

SBT-28813 (?) 10/08/04 11:41:57 [Normal] From: "oratest" Time: 10/08/04 11:41:57

Starting OB2BAR Backup: 05 test2:test2oratestarchivelog<539005316:1>.dbf // Oracle8

SBT-28813 (?) 10/08/04 11:42:08 [Normal] From: "oratest" Time: 10/08/04 11:42:08

Completed OB2BAR Backup: 05 test2:test2oratestarchivelog<539005316:1>.dbf // Oracle8

SBT-28813 (?) 10/08/04 11:42:13 [Normal] From: "oratest" Time: 10/08/04 11:42:13

Starting OB2BAR Backup: 05 test2:test2oratestarchivelog<539005332:1>.dbf // Oracle8

SBT-28813 (?) 10/08/04 11:42:16 [Normal] From: "oratest" Time: 10/08/04 11:42:16

Completed OB2BAR Backup: 05 test2:test2oratestarchivelog<539005332:1>.dbf // Oracle8

從上述內容可以看到儲存在帶庫上的全備的備份集檔案為:

test2:test2oratest<539001683:1>.dbf

test2:test2oratest<539001979:1>.dbf

Archivelog的備份集檔案為:

test2:test2oratestarchivelog<539004793:1>.dbf

。。。

test2:test2oratestarchivelog<539005316:1>.dbf

test2:test2oratestarchivelog<539005332:1>.dbf

2.恢復控制檔案

test2:/backup/test$sqlplus /nolog

SQL*Plus: Release 9.2.0.1.0 - Production on Sat Oct 9 14:30:54 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> connect / as sysdba

Connected.

SQL>startup nomount
SQL>DECLARE

2 devtype varchar2(256);

3 done boolean;

4 BEGIN

5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape',

ident=>'T1',params=>'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=oratest,OB2BARLIST=test2oratest)');

6 sys.dbms_backup_restore.restoreSetDatafile;

7 sys.dbms_backup_restore.restoreControlfileTo(

cfname=>'/backup/test/Control01.ctl');

8 sys.dbms_backup_restore.restoreBackupPiece(done=>done,

handle=>'test2oratest<539001979:1>.dbf', params=>null);

9 sys.dbms_backup_restore.deviceDeallocate;

10 END;

11 /

[Normal] From: "oratest" Time: 10/09/04 14:23:28

Starting OB2BAR Restore: 05 test2:test2oratest<539001979:1>.dbf // Oracle8

[Normal] From: "oratest" Time: 10/09/04 14:23:32

Completed OB2BAR Restore: 05 test2:test2oratest<539001979:1>.dbf // Oracle8

SQL>

由於RMAN做全庫備份的時候,最後備份控制檔案,應此可以從最後一個全備的備份集檔案中恢復控制檔案。恢復控制檔案時,需將資料庫啟動到nomount狀態。恢復的控制檔案應與init檔案中定義的控制檔案的路徑、檔名和數量相一致,否則無法把資料庫啟動到mount狀態。

下面介紹程式包的內容:

第五行 分配一個device channel ,"sbt_tape"說明是從磁帶上恢復。Params引數與Data Protector中RMAN備份指令碼中的引數一致。

第六行 初始化恢復過程,準備進行控制檔案或資料檔案恢復。

第七行 指出待恢復檔案和恢復檔案的儲存位置。本處說明是恢復控制檔案及存放存放控制檔案的路徑、檔名。

第八行 說明從哪個備份片中恢復

第九行 釋放裝置通道

3.恢復資料檔案

首先需要知道每個備份集中包含哪些資料檔案:

SQL>alter database mount;

SQL>select file# from v$backup_datafile where set_stamp=539001683;

FILE#

----------

2

0

2 rows selected.

SQL>

其中,set_stamp是備份集檔名中的時間戳;

0表示控制檔案;

2是資料檔案號。

檔案號對應的檔名可以在v$datafile中查到。

知道備份集中包含的資料檔案號和檔名,就可以恢復資料檔案了:

SQL>DECLARE

2 devtype varchar2(256);

3 done boolean;

4 BEGIN

5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape',

ident=>'T1',params=>'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=oratest,OB2BARLIST=test2oratest)');

6 sys.dbms_backup_restore.restoreSetDatafile;

7 sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>2,

toname=>'/backup/test/undotbsldb01.dbf');

8 sys.dbms_backup_restore.restoreBackupPiece(done=>done,

handle=>'test2:test2oratest<539001683:1>.dbf', params=>null);

9 sys.dbms_backup_restore.deviceDeallocate;

10 END;

11 /

[Normal] From: "oratest" Time: 10/09/04 14:20:10

Starting OB2BAR Restore: 05test2:test2oratest<539001683:1>.dbf // Oracle8

[Normal] From: "oratest" Time: 10/09/04 14:20:24

Completed OB2BAR Restore: 05 test2:test2oratest<539001683:1>.dbf // Oracle8

PL/SQL procedure successfully completed.

SQL>

重複上述操作,可以恢復所有資料檔案。恢復的資料檔案的儲存目錄可以不是原儲存目錄,因此,甚至可以在資料庫open狀態下從備份集中restore資料檔案。

4.恢復archive log檔案

SQL>DECLARE

2 devtype varchar2(256);

3 done boolean;

4 BEGIN

5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape',ident=>'T1',

params=>'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=oratest,

OB2BARLIST=test2oratestarchivelog)');

6 sys.dbms_backup_restore.restoreSetArchivedLog;

7 sys.dbms_backup_restore.restoreArchivedLogRange;

8 sys.dbms_backup_restore.restoreBackupPiece(done=>done,

handle=>'test2:test2oratestarchivelog<539005316:1>.dbf', params=>null);

9 sys.dbms_backup_restore.deviceDeallocate;

10 END;

11 /

[Normal] From: "oratest" Time: 10/09/04 14:40:13

Starting OB2BAR Restore: 05 test2:test2oratestarchivelog<539005316:1>.dbf // Oracle8

[Normal] From: "oratest" Time: 10/09/04 14:40:13

Completed OB2BAR Restore: 05 test2:test2oratestarchivelog<539005316:1>.dbf // Oracle8

SQL>

根據第一步中獲得的archive log備份集的檔名,恢復所有archive log.

5. Recover資料庫

SQL> recover database until cancel using backup controlfile;

ORA-00279: change 54285 generated at 10/08/2004 10:41:24 needed for thread 1

ORA-00289: suggestion : /backup/test/archive/1_24.dbf

ORA-00280: change 54285 for thread 1 is in sequence #24

Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00279: change 55331 generated at 10/08/2004 11:02:48 needed for thread 1

ORA-00289: suggestion : /backup/test/archive/1_25.dbf

ORA-00280: change 55331 for thread 1 is in sequence #25

ORA-00278: log file '/backup/test/archive/1_24.dbf' no longer needed for this recovery

Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00279: change 56789 generated at 10/08/2004 11:33:12 needed for thread 1

ORA-00289: suggestion : /backup/test/archive/1_26.dbf

ORA-00280: change 56789 for thread 1 is in sequence #26

ORA-00278: log file '/backup/test/archive/1_25.dbf' no longer needed for this recovery

Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00308: cannot open archived log '/backup/test/archive/1_26.dbf'

ORA-27037: unable to obtain file status

HP-UX Error: 2: No such file or directory

Additional information: 3

SQL> alter database open resetlogs;

Database altered.

SQL>

現在資料庫恢復已經完成了。由於online redo log也損壞了,資料庫僅恢復到最後一個歸檔的日誌檔案。

一個小技巧:在上一步恢復archive log時,archive log檔案可能非常多。如果不知道最早應該恢復到哪一個archive log檔案,可以先執行一次本步操作,系統會提示最先需要的archive log檔案,然後從最後的一個archive log備份集往前恢復直到該archive log檔案被恢復。示例如下:

SQL> recover database until cancel using backup controlfile;

ORA-00279: change 54285 generated at 10/08/2004 10:41:24 needed for thread 1

ORA-00289: suggestion : /backup/test/archive/1_24.dbf

ORA-00280: change 54285 for thread 1 is in sequence #24

Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00308: cannot open archived log '/backup/test/archive/1_24.dbf'

ORA-27037: unable to obtain file status

HP-UX Error: 2: No such file or directory

Additional information: 3

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below

ORA-01152: file 1 was not restored from a sufficiently old backup

ORA-01110: data file 1: '/backup/test/oradata/system01.dbf'

SQL>

顯然,第一個需要的archive log檔案是/backup/test/archive/1_24.dbf

五.小結

1. 只要儲存了完整的全庫備份和完整的歸檔日誌備份,即使控制檔案和恢復目錄全部損壞,資料庫還是可以恢復的。

2. 根據上面一條可以看出,無論備份時是否採用了恢復目錄,恢復目錄在資料庫恢復時,並不是必須的。

3. RMAN做的備份可以不用RMAN恢復。

4. HP Data Protector的備份指令碼在做全庫備份時,是一個一個備份資料檔案和日誌檔案並形成單獨的備份集。資料庫全備期間的日誌檔案必須儲存完整。

參考資料:
DBA工作備忘錄之三:rman備份,沒用catalog ,但控制檔案丟失,怎麼解決? Fenng

[@more@]

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

相關文章