Netbackup+oracle db 異機恢復案例

djb1008發表於2010-10-15
 

本文主要就使用netbackup伺服器上的rman的備份集,在異機進行資料庫恢復進行詳細的操作說明.

 

  1. 環境描述

 

1.1 源資料庫資訊

 

Hostname: sstydb

Oracle_sid:sstydb

Oracle_version:10.2.0.4.0

DBID: 3469129877

Os:Linux  2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

安裝了netbackup client netbackup for oracle db,並在netbackup伺服器上定義了策略(並啟用)client

資料庫在netbackup伺服器進行了全庫和歸檔日誌的備份

rman備份集沒有使用catalog資料庫進行記錄(nocatalog方式)

netbackup伺服器上設定允許異機恢復.

 

1.2 目標庫資訊

 

Hostname:ttjkdb

Oracle_sid:sstydb

Oracle_version:10.2.0.4.0

Os:Linux  2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

安裝了oracle資料庫環境,沒有建立資料庫例項

安裝了netbackup client netbackup for oracle db,並在netbackup伺服器上定義了策略(並啟用)client

透過了sbttest,可以訪問netbackup的帶庫,rman可以訪問netbackup伺服器的介質

 

  1. 主要工作目標

 

        在目標伺服器(ttjkdb),使用rman工具和netbackup伺服器上源庫的rman備份集,進行資料庫的不完整恢復(無法獲得線上執行源庫的redo檔案),即在目標伺服器上測試源庫的災難性恢復.

 

  1. 異機恢復的主要操作步驟

 

3.1目標機上進行資料庫例項環境的準備工作

3.1.1編輯/home/oracle/.bash_profile檔案設定ORACLE_SID引數

$more /home/oracle/.bash_profile

…...

ORACLE_SID=sstydb:export ORACLE_SID

…...

 

3.1.2 編輯$ORACLE_HOME/dbs/init.ora檔案,設定例項引數

$more $ORACLE_HOME/dbs/initsstydb.ora

*.compatible='10.2.0.3.0'

*.control_files='/oradata/sstydb/control01.ctl','/oradata/sstydb/control02.ctl','/oradata/sstydb/control03.ctl'

*.core_dump_dest='/oracle/admin/sstydb/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=16

*.db_name='sstydb'

*.db_recovery_file_dest='/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=2147483648

*.job_queue_processes=10

*.log_archive_dest_1='LOCATION=/oradata/archivelog/'

*.open_cursors=300

*.pga_aggregate_target=384827392

*.processes=500

*.remote_login_passwordfile='EXCLUSIVE'

*.sessions=555

*.sga_target=1154482176

*.undo_management='AUTO'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/oracle/admin/sstydb/udump'

 

注意:

Db_name 一定要設定為源庫的資料庫名稱,dump的幾個目錄可以修改,歸檔日誌目錄和sga的設定可以修改

 

3.1.3 準備資料庫資料目錄和dump檔案目錄

本例中,目標資料庫與源資料庫的資料檔案的目錄和檔名稱完全相同

ttjkdb$mkdir /oradata/sstydb

ttjkdb$cd /oracle/admin

ttjkdb$mkdir sstydb

ttjkdb$cd sstydb

ttjkdb$mkdir adump bdump cdump udump

 

3.1.4 啟動資料庫例項到nomount狀態

Ttjkdb$export ORACLE_SID=sstydb

ttjkdb$sqlplus / as sysdba

SQL>startup nomount;

ORACLE instance started.

Total System Global Area 1157627904 bytes

Fixed Size                  2083432 bytes

Variable Size             301991320 bytes

Database Buffers          838860800 bytes

Redo Buffers               14692352 bytes

SQL> exit

資料庫例項啟動到nomount狀態,為後面的控制檔案的恢復做好了準備

 

3.2 目標庫伺服器上恢復控制檔案,啟動資料庫到mount狀態

 

3.2.1 控制檔案恢復的場景與約束

Oracle 官方文件中,關於restore controlfile的應用場景的描述,起到很好的指引作用,少走了很多彎路,如下:

 

 

  RESTORE CONTROLFILE; RESTORE CONTROLFILE FROM AUTOBACKUP; RESTORE CONTROLFILE …TO 'filename'; RESTORE CONTROLFILE… FROM 'media_handle' or TAG 'user_tag';
No catalog target started in NOMOUNT state Error.Must specify FROM AUTOBACKUP. First run SET DBID.Restores to CONTROL_FILES locations. First run SET DBID. Must specify FROM AUTOBACKUP.Restores only to filename. First run SET DBID.Restores from specified file(cannot restore from TAG).If TO 'filename' not used,restores to all CONTROL_FILES location.
NO catalog target mounted or open Error.Must use TO 'filename',where filename is not in CONTROL_FILE list. Error.Must use TO 'filename',where fileame is not in CONTROL_FILES list. Restores only to filename,where filename is not in CONTROL_FILES list. Restores form. specified file.If TO 'filename' not used,restores to all CONTROL_FILES locations.
Catalog,target started in NOMOUNT state Restores to CONTROL_FILES locations,RUN SET DBID only if DB_NAME not unique in catalog. Only use with catalog for testing purposes. Restores only to filename,where filename is not in CONTROL_FILES list. Restores form. specified file.If TO 'filename' not used,restores to all CONTROL_FILES locations.
Catalog,target mounted or open Error.Must use TO 'filename',where filename is not in CONTROL_FILE list. Do not use with catalog. Restores only to filename,where filename is not in CONTROL_FILES list. Restores form. specified file.If TO 'filename' not used,restores to all CONTROL_FILES locations.

 

       本例我們屬於第一種情況:No catalog,target started in NOMOUNT state,所以只有3個途徑進行恢復(見上表的第2行的第3,4,5)因為目標庫與源庫的資料檔案的目錄完全相同,controlfile也就恢復到init.ora設定的目錄,所以3,4列可以合併為3,:RESTORE CONTROLFILE FROM AUTOBACKUP;

    2行第5,因為不可以使用tag,所以可以縮寫為:RESTORE CONTROLFILE FROM 'media_handle';

 

    這樣本例就可以使用兩個方式進行controlfile恢復工作

  A. RESTORE CONTROLFILE FROM AUTOBACKUP;

  B. RESTORE CONTROLFILE FROM 'media_handle'

 

3.2.2 controlfile的恢復

 

先檢查一下源庫的controlfile的備份情況

sstydb$rman target /

Rman>list backup of controlfile;

…...

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

1109    Full    7.00M      SBT_TAPE    00:00:57     15-OCT-10     

        BP Key: 1109   Status: AVAILABLE  Compressed: NO  Tag: TAG20101015T123430

        Handle: cntrl_1118_1_732458070   Media: G:

  Control File Included: Ckp SCN: 13520941     Ckp time: 15-OCT-10

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

1110    Full    7.00M      SBT_TAPE    00:01:09     15-OCT-10     

        BP Key: 1110   Status: AVAILABLE  Compressed: NO  Tag: TAG20101015T123535

        Handle: c-3469129477-20101015-02   Media: G:

  Control File Included: Ckp SCN: 13520988     Ckp time: 15-OCT-10

 

查詢源庫的DBID

Sstydb$sqlplus / as sysdba

SQL>select dbid from v$database;

DBID

--------

3469129877

 

A.使用FROM AUTOBACKUP 方式進行controlfile恢復

Ttjkdb$rman target /

Rman>set DBID=3469129877

Rman>run{

allocate channel d1 type 'sbt_tape' parms="ENV=(NB_ORA_CLIENT=sstydb)";

send 'NB_ORA_SERV=netbackup';

restore controlfile  from 'c-3469129477-20101015-02';

Release channel d1;}

 

released channel: ORA_DISK_1

allocated channel: d1

channel d1: sid=541 devtype=SBT_TAPE

channel d1: Veritas NetBackup for Oracle - Release 6.5 (2007072323)

sent command to channel: d1

Starting restore at 15-OCT-10

channel d1: restoring control file

channel d1: restore complete, elapsed time: 00:00:48

output filename=/oradata/sstydb/control01.ctl

output filename=/oradata/sstydb/control02.ctl

output filename=/oradata/sstydb/control03.ctl

Finished restore at 15-OCT-10

released channel: d1

 

使用from autobackup 方式進行恢復有一個前提,就是源庫的rman環境裡設定了控制檔案的自動備份

Sstydb$rman target /

Rman>show all;

RMAN configuration parameters are:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'TAPE' TO '%F';

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/oracle/product/10.2.0/db_1/dbs/snapcf_gcwz_web.f'; # default

…...

 

如果源庫沒有設定autobackup,可以透過的命令進行設定

Rman>CONFIGURE CONTROLFILE AUTOBACKUP ON;

RMAN>CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'TAPE' TO '%F';

 

B. 使用FROM 'media_handle' 方式進行controlfile恢復

Ttjkdb$rman target /

Rman>set DBID=3469129877

Rman>run{

allocate channel d1 type 'sbt_tape' parms="ENV=(NB_ORA_CLIENT=sstydb)";

send 'NB_ORA_SERV=netbackup';

restore controlfile  from autobackup;

Release channel d1;}

 

 

 

         經實際測試使用A方式進行controlfile的恢復,耗時比B方式多;A方式可能需要掃描帶庫,所以速度慢很多,B方式直接去訪問帶庫中的指定內容,時間要快一點,從速度上上比較,建議選擇B方式進行controlfile的恢復。

 

3.2.3 啟動目標資料庫例項到mount狀態

Ttjkdb$sqlplus / as sysdba

SQL>alter database mount;

 

將資料庫啟動到mount狀態後,就可以進行資料庫的restorerecovery了。

 

3.3 目標資料庫例項恢復,以resetlogs方式開啟資料庫例項

3.3.1 目標資料庫例項恢復

Ttjkdb$rman target /

Rman>set DBID=3469129877

Rman>run{

allocate channel d1 type 'sbt_tape' parms="ENV=(NB_ORA_CLIENT=tydb)";

send 'NB_ORA_SERV=netbackup';

Restore database;

Recover database;

Release channel d1;}

 

allocated channel: d1

channel d1: sid=541 devtype=SBT_TAPE

…...

channel d1: Veritas NetBackup for Oracle - Release 6.5 (2007072323)

sent command to channel: d1

channel d1: starting datafile backupset restore

channel d1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /oradata/gcwz_web/system01.dbf

restoring datafile 00002 to /oradata/gcwz_web/undotbs01.dbf

…...

channel d1: reading from backup piece bk_1094_1_732284984

channel d1: restored backup piece 1

piece handle=bk_1094_1_732284984 tag=HOT_DB_BK_LEVEL0

channel d1: restore complete, elapsed time: 00:01:26

Finished restore at 15-OCT-10

Starting recover at 15-OCT-10

starting media recovery

channel d1: starting archive log restore to default destination

……

piece handle=2clqc5eg_1_1 tag=TAG20101013T180048

channel d1: restore complete, elapsed time: 00:00:56

archive log filename=/oradata/archivelog/1_665_690800133.dbf thread=1 sequence=665

archive log filename=/oradata/archivelog/1_666_690800133.dbf thread=1 sequence=666

unable to find archive log

archive log thread=1 sequence=1

released channel: d1

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 10/15/2010 17:45:30

RMAN-06054: media recovery requesting unknown log: thread 1 seq 1 lowscn 13414913

 

這裡有rman的報錯,這個錯誤因為rman在向下應用日誌的時候,找不到下一個日誌序列=到達尾部(永遠會存在),我們可以忽略這個錯誤。

 

3.3.2 resetlogs方式開啟資料庫例項

Ttjkdb$sqlplus / as sysdba

SQL> alter database open resetlogs;

Database altered.

SQL> select open_mode,name from v$database;

OPEN_MODE  NAME

---------- ---------

READ WRITE SSTYDB

 

 

 

 

 

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

相關文章