記一次簡單的異機恢復操作

super_sky發表於2014-01-07
客戶的主機出現磁碟損壞,導致無法啟動。主機工程師將機器拉起來後,檢查資料庫還正常。這時客戶提出要求需要保留資料庫資料,然後更換磁碟重新安裝作業系統。因此使用rman對資料庫進行了全備,備份了控制檔案和引數檔案。

環境:RHEL5.6 64bit
資料庫:oracle10g 10.2.0.5 單機

下面來簡單的介紹一下恢復的過程。軟體的安裝請參看我的這篇部落格《 使用靜默方式安裝11g資料庫》或者 《OCM實驗-測試環境的搭建 

1)使用備份的引數檔案並修改引數檔案中的檔案路徑
[oracle@icsts dbs]$ cat pfile.ora
*.audit_file_dest='/u01/app/oracle/admin/ICSTEST/adump'
*.background_dump_dest='/u01/app/oracle/admin/ICSTEST/bdump'
*.compatible='10.2.0.5.0'
*.control_files='/u01/app/oracle/datafile/ICSTEST/control01.ctl','/u01/app/oracle/datafile/ICSTEST/control02.ctl','/u01/app/oracle/datafile/ICSTEST/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/ICSTEST/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='ICSTEST'
*.dispatchers=''
*.job_queue_processes=10
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.pga_aggregate_target=1202716672
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1610612736
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/ICSTEST/udump'
2)建立引數檔案中需要的路徑
mkdir -p /u01/app/oracle/admin/ICSTEST/adump
mkdir -p /u01/app/oracle/admin/ICSTEST/bdump
mkdir -p /u01/app/oracle/admin/ICSTEST/cdump
mkdir -p /u01/app/oracle/admin/ICSTEST/udump
mkdir -p /u01/app/oracle/datafile/ICSTEST
3)使用新建的引數檔案啟動並建立spfile檔案
SQL> startup nomount pfile=/u01/app/oracle/product/10.2.0/db_1/dbs/pfile.ora
ORACLE instance started.
Total System Global Area 1610612736 bytes
Fixed Size                  2096632 bytes
Variable Size             385876488 bytes
Database Buffers         1207959552 bytes
Redo Buffers               14680064 bytes
SQL> 
SQL> create spfile from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/pfile.ora';
File created.

重啟,使用spfile檔案
SQL> shutdown abort
ORACLE instance shut down.
SQL> 
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1610612736 bytes
Fixed Size                  2096632 bytes
Variable Size             385876488 bytes
Database Buffers         1207959552 bytes
Redo Buffers               14680064 bytes
SQL>

4)恢復控制檔案
RMAN> restore controlfile from '/u01/backup/control_06osrlpi_1_1';
Starting restore at 07-JAN-14
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:03
output filename=/u01/app/oracle/datafile/ICSTEST/control01.ctl
output filename=/u01/app/oracle/datafile/ICSTEST/control02.ctl
output filename=/u01/app/oracle/datafile/ICSTEST/control03.ctl
Finished restore at 07-JAN-14

將資料庫啟動到mount狀態
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

5)修改redo日誌檔案
檢查現在的redolog檔案
SQL> select member from v$logfile;
MEMBER
----------------------------------------
/data/redolog/ICSTEST/redo03.log
/data/redolog/ICSTEST/redo02.log
/data/redolog/ICSTEST/redo01.log
這些檔案是不存在的。更改redolog檔案
SQL> alter database rename file '/data/redolog/ICSTEST/redo01.log' to '/u01/app/oracle/datafile/ICSTEST/redo01.log';
Database altered.
SQL> alter database rename file '/data/redolog/ICSTEST/redo02.log' to '/u01/app/oracle/datafile/ICSTEST/redo02.log';
Database altered.
SQL> alter database rename file '/data/redolog/ICSTEST/redo03.log' to '/u01/app/oracle/datafile/ICSTEST/redo03.log';
Database altered.
更改後檢查
MEMBER
--------------------------------------------------
/u01/app/oracle/datafile/ICSTEST/redo03.log
/u01/app/oracle/datafile/ICSTEST/redo02.log
/u01/app/oracle/datafile/ICSTEST/redo01.log

6)註冊備份資訊,由於我們是異機恢復,重做系統也相當於異機了。
RMAN> catalog start with '/u01/backup';
searching for all files that match the pattern /u01/backup
List of Files Unknown to the Database
=====================================
File Name: /u01/backup/control_06osrlpi_1_1
File Name: /u01/backup/pfile.ora
File Name: /u01/backup/database_full_05osrlof_1_1
File Name: /u01/backup/database_full_04osrlhe_1_1
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/backup/control_06osrlpi_1_1
File Name: /u01/backup/database_full_05osrlof_1_1
File Name: /u01/backup/database_full_04osrlhe_1_1
List of Files Which Where Not Cataloged
=======================================
File Name: /u01/backup/pfile.ora
  RMAN-07517: Reason: The file header is corrupted
RMAN>

7)恢復資料檔案,我這裡的恢復時資料檔案路徑已經同原來的不一致了。因此多出來很多set netname for datafile file# to 'newname';語句來。
run{
allocate channel ch1 type disk;
allocate channel ch2 type disk;
set newname for datafile  1 to '/u01/app/oracle/datafile/ICSTEST/system01.dbf';
set newname for datafile  2 to '/u01/app/oracle/datafile/ICSTEST/undotbs01.dbf';
set newname for datafile  3 to '/u01/app/oracle/datafile/ICSTEST/sysaux01.dbf';
set newname for datafile  4 to '/u01/app/oracle/datafile/ICSTEST/users01.dbf';
set newname for datafile  5 to '/u01/app/oracle/datafile/ICSTEST/ics_data01.dbf';
set newname for datafile  6 to '/u01/app/oracle/datafile/ICSTEST/ism_data01.dbf';
set newname for datafile  7 to '/u01/app/oracle/datafile/ICSTEST/CWMLITE01.dbf';
set newname for datafile  8 to '/u01/app/oracle/datafile/ICSTEST/DRSYS01.dbf';
set newname for datafile  9 to '/u01/app/oracle/datafile/ICSTEST/EXAMPLE01.dbf';
set newname for datafile 10 to '/u01/app/oracle/datafile/ICSTEST/INDX01.dbf';
set newname for datafile 11 to '/u01/app/oracle/datafile/ICSTEST/ODM01.dbf';
set newname for datafile 12 to '/u01/app/oracle/datafile/ICSTEST/SYSTEM02.dbf';
set newname for datafile 13 to '/u01/app/oracle/datafile/ICSTEST/TBS_BSS01.dbf';
set newname for datafile 14 to '/u01/app/oracle/datafile/ICSTEST/TBS_BSS02.dbf';
set newname for datafile 15 to '/u01/app/oracle/datafile/ICSTEST/TOOLS01.dbf';
set newname for datafile 16 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS01.dbf';
set newname for datafile 17 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS02.dbf';
set newname for datafile 18 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS03.dbf';
set newname for datafile 19 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS04.dbf';
set newname for datafile 20 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS05.dbf';
set newname for datafile 21 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS06.dbf';
set newname for datafile 22 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS07.dbf';
set newname for datafile 23 to '/u01/app/oracle/datafile/ICSTEST/TS_IDS08.dbf';
set newname for datafile 24 to '/u01/app/oracle/datafile/ICSTEST/TS_ISM01.dbf';
set newname for datafile 25 to '/u01/app/oracle/datafile/ICSTEST/TS_SM01.dbf';
set newname for datafile 26 to '/u01/app/oracle/datafile/ICSTEST/TS_TIF01.dbf';
set newname for datafile 27 to '/u01/app/oracle/datafile/ICSTEST/UNDOTBS102.dbf';
set newname for datafile 28 to '/u01/app/oracle/datafile/ICSTEST/UNDOTBS103.dbf';
set newname for datafile 29 to '/u01/app/oracle/datafile/ICSTEST/UNDOTBS104.dbf';
set newname for datafile 30 to '/u01/app/oracle/datafile/ICSTEST/XDB01.dbf';
set newname for datafile 31 to '/u01/app/oracle/datafile/ICSTEST/USERS02.dbf';
restore database;
switch datafile all;
release channel ch1;
release channel ch2;
}
資料檔案恢復後,可以將資料庫啟動到open狀態了。這裡要說明一下,源庫是noarchivelog模式,所以不存在歸檔日誌,不需要做recover操作了。
RMAN> alter database open resetlogs;
database opened

8)修改temporary tablespace 
SQL> create temporary tablespace temptbs tempfile '/u01/app/oracle/datafile/ICSTEST/temptbs01.dbf' size 200M;
Tablespace created.
SQL> alter database default temporary tablespace temptbs;
Database altered.
SQL> drop tablespace temp; #刪除原來的temp表空間
Tablespace dropped.
SQL> select file_name from dba_temp_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/datafile/ICSTEST/temptbs01.dbf

到這裡呢,恢復基本完成了,後續可能還有一些監聽的配置等小操作了。

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

相關文章