ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 在WINDOWS 上恢复一个DB 的步骤

在WINDOWS 上恢复一个DB 的步骤

原创 Linux操作系统 作者:kewin 时间:2011-08-25 13:22:59 0 删除 编辑
在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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-03-10

  • 博文量
    125
  • 访问量
    589158