在WINDOWS 上恢復一個DB 的步驟

kewin發表於2011-08-25
在WINDOWS 上恢復一個DB 的步驟
Kevin Zou
2011-8-25
使用者要求在搭建一個生產環境的測試環境,我想通過RESTORE 來實現。把基本的步驟記錄如下。
環境:
環境的平臺是WINDOWS 2008,Oracle 11GR2。
前提工作:
在生產庫上做個熱備,把備份集拷貝到新的伺服器上,建立對應的目錄。

建立DB的過程:
在新的伺服器上建立密碼檔案:
password file:
orapwd file=orapwkbthprd.ora password=just4db8

由於目錄環境不一致,需要修改pfile中的相關目錄設定。修改完畢,建立spfile。

SQL> conn /as  sysdba
Connected to an idle instance.
SQL> create spfile from pfile='P:\backup\pfilekbthprd.ora';

File created.
要到Windows 命令列上建立一個新的服務:
ORADIM -NEW -SID kbthprd -startup auto
注意在註冊一個新的服務,要確保初始化引數檔案存在,否則ORADIM會報錯:

Thu Aug 25 03:20:56 2011
E:\oracle\product\11.2.0\bin\oradim.exe -startup -sid kbthdev -usrpwd *  -log oradim.log -nocheck 0 
Thu Aug 25 03:21:01 2011
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file 'E:\ORACLE\PRODUCT\11.2.0\DATABASE\INITKBTHDEV.ORA'

這時可以把DB 啟動到NOMOUNT 狀態:
SQL> startup nomount
ORACLE instance started.

Total System Global Area 6847938560 bytes
Fixed Size                  2188768 bytes
Variable Size            5083499040 bytes
Database Buffers         1744830464 bytes
Redo Buffers               17420288 bytes

E:\oracle\product\11.2.0\database>rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Aug 25 03:34:05 2011

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

connected to target database: KBTHPRD (not mounted)

RMAN> restore controlfile from 'P:\backup\O1_MF_NCNNF_TAG20110825T031430_75CD08J4_.BKP';

Starting restore at 25-AUG-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=712 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=E:\ORACLE\KBTHDEV\DATA11\CONTROL01.CTL
output file name=E:\ORACLE\KBTHDEV\INDX11\CONTROL02.CTL
output file name=E:\ORACLE\KBTHDEV\UNDO11\CONTROL03.CTL
Finished restore at 25-AUG-11

RMAN>alter database mount

由於backup piece 的目錄和源目錄不一樣,需要使用catalog命令把backup piece 加到controlfile中。否則會報錯,說找不到backup piece。
RMAN> catalog backuppiece 'P:\backup\FULL_20110825_1308_1';

cataloged backup piece
backup piece handle=P:\BACKUP\FULL_20110825_1308_1 RECID=1308 STAMP=760074939

RMAN> catalog backuppiece 'P:\backup\FULL_20110825_1309_1';

cataloged backup piece
backup piece handle=P:\BACKUP\FULL_20110825_1309_1 RECID=1309 STAMP=760074944

執行RESTORE的操作:
RMAN> run{
2> set newname for datafile 1 to "E:\ORACLE\KBTHDEV\DATA11\SYSTEM01.DBF";
3> set newname for datafile 2 to "E:\ORACLE\KBTHDEV\DATA11\SYSAUX01.DBF";
4> set newname for datafile 3 to "E:\ORACLE\KBTHDEV\UNDO11\UNDOTBS01.DBF";
5> set newname for datafile 4 to "E:\ORACLE\KBTHDEV\DATA11\USERS01.DBF";
6> set newname for datafile 5 to "E:\ORACLE\KBTHDEV\DATA11\KABA01.DBF";
7> set newname for datafile 6 to "E:\ORACLE\KBTHDEV\DATA11\PERFSTAT01.DBF";
8> set newname for datafile 7 to "E:\ORACLE\KBTHDEV\DATA11\KABA02.DBF";
9> restore database;
10> switch datafile all;
11> }

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 25-AUG-11
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to E:\ORACLE\KBTHDEV\UNDO11\UNDOTBS
01.DBF
channel ORA_DISK_1: restoring datafile 00004 to E:\ORACLE\KBTHDEV\DATA11\USERS01
.DBF
channel ORA_DISK_1: restoring datafile 00005 to E:\ORACLE\KBTHDEV\DATA11\KABA01.
DBF
channel ORA_DISK_1: restoring datafile 00007 to E:\ORACLE\KBTHDEV\DATA11\KABA02.
DBF
channel ORA_DISK_1: reading from backup piece P:\BACKUP\FULL_20110825_1308_1
channel ORA_DISK_1: piece handle=P:\BACKUP\FULL_20110825_1308_1 tag=TAG20110825T
031058
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to E:\ORACLE\KBTHDEV\DATA11\SYSTEM0
1.DBF
channel ORA_DISK_1: restoring datafile 00002 to E:\ORACLE\KBTHDEV\DATA11\SYSAUX0
1.DBF
channel ORA_DISK_1: restoring datafile 00006 to E:\ORACLE\KBTHDEV\DATA11\PERFSTA
T01.DBF
channel ORA_DISK_1: reading from backup piece P:\BACKUP\FULL_20110825_1309_1
channel ORA_DISK_1: piece handle=P:\BACKUP\FULL_20110825_1309_1 tag=TAG20110825T
031058
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 25-AUG-11

datafile 1 switched to datafile copy
input datafile copy RECID=8 STAMP=760075184 file name=E:\ORACLE\KBTHDEV\DATA11\S
YSTEM01.DBF
datafile 2 switched to datafile copy
input datafile copy RECID=9 STAMP=760075184 file name=E:\ORACLE\KBTHDEV\DATA11\S
YSAUX01.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=10 STAMP=760075184 file name=E:\ORACLE\KBTHDEV\UNDO11\
UNDOTBS01.DBF
datafile 4 switched to datafile copy
input datafile copy RECID=11 STAMP=760075184 file name=E:\ORACLE\KBTHDEV\DATA11\
USERS01.DBF
datafile 5 switched to datafile copy
input datafile copy RECID=12 STAMP=760075184 file name=E:\ORACLE\KBTHDEV\DATA11\
KABA01.DBF
datafile 6 switched to datafile copy
input datafile copy RECID=13 STAMP=760075184 file name=E:\ORACLE\KBTHDEV\DATA11\
PERFSTAT01.DBF
datafile 7 switched to datafile copy
input datafile copy RECID=14 STAMP=760075184 file name=E:\ORACLE\KBTHDEV\DATA11\
KABA02.DBF

恢復DATAFILE後,需要做RECOVER DB。這個步驟和恢復DATAFILE的步驟類似。
RMAN> catalog archivelog 'P:\backup\ARC0000002197_0750215200.0001';

cataloged archived log
archived log file name=P:\BACKUP\ARC0000002197_0750215200.0001 RECID=2329 STAMP=760076155
RMAN> recover database until sequence =2197 thread =1;

Starting recover at 25-AUG-11
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 25-AUG-11

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 08/25/2011 04:17:38
ORA-00344: unable to re-create online log 'E:\ORACLE\KBTHPRD\REDO11\REDO01A.LOG'
ORA-27040: file create error, unable to create file
OSD-04002: unable to open file
O/S-Error: (OS 3) The system cannot find the path specified.
這個報錯應該目錄的變化,而且當前伺服器上沒有E:\ORACLE\KBTHPRD\REDO11 目錄。
解決這個問題有2個方法,1) 建立缺失的目錄;2) 通過ALTER 命令指向存在的目錄。 本次的恢復通過方法2來實現。
在SQLPLUS中執行:
alter database rename file 'E:\ORACLE\KBTHDEV\REDO11\REDO04A.LOG' to 'E:\ORACLE\KBTHDEV\REDO11\REDO04A.LOG';
alter database rename file 'E:\ORACLE\KBTHPRD\REDO12\REDO04B.LOG' to 'E:\ORACLE\KBTHDEV\REDO12\REDO04B.LOG';
alter database rename file 'E:\ORACLE\KBTHPRD\REDO11\REDO03A.LOG' to 'E:\ORACLE\KBTHDEV\REDO11\REDO03A.LOG';
alter database rename file 'E:\ORACLE\KBTHPRD\REDO12\REDO03B.LOG' to 'E:\ORACLE\KBTHDEV\REDO12\REDO03B.LOG';
alter database rename file 'E:\ORACLE\KBTHPRD\REDO11\REDO02A.LOG' to 'E:\ORACLE\KBTHDEV\REDO11\REDO02A.LOG';
alter database rename file 'E:\ORACLE\KBTHPRD\REDO12\REDO02B.LOG' to 'E:\ORACLE\KBTHDEV\REDO12\REDO02B.LOG';
alter database rename file 'E:\ORACLE\KBTHPRD\REDO11\REDO01A.LOG' to 'E:\ORACLE\KBTHDEV\REDO11\REDO01A.LOG';
alter database rename file 'E:\ORACLE\KBTHPRD\REDO12\REDO01B.LOG' to 'E:\ORACLE\KBTHDEV\REDO12\REDO01B.LOG';
回到RMAN 介面執行:
MAN> alter database open resetlogs;

atabase opened

到此整個RESTORE & RECOVER 的過程完畢。
如果恢復後,需要修改DB NAME,可以通過重建CONTROLFILE檔案來實現,這裡不再詳細列出操作步驟。
-END-

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

相關文章