实验环境:Windows XP + Oracle 9.2.0.1
基本步骤如下:
1. 用RMAN做数据库全备,由于配置了controlfile autobackup,所以备份集中包含了datafile, controlfile, spfile。
2. 删除数据库,用dbca删除,只保留了Oracle程序(模拟在其他机器上恢复)。
3. 由于没有使用catalog备份,所以再连RMAN之前还要先建Windows service。
oradim -new -sid ora92br -srvc OracleServiceORA92BR -startmode a
4. 由于没有密码文件,sqlnet.ora中的SQLNET.AUTHENTICATION_SERVICES= (NONE),所以需要建密码文件先(RMAN连接报insufficient privilege错误才想到的):
orapwd file=D:\opt\oracle9i\product\9.2.0\database\PWDora92br.ora password=oracle entries=10
5. 接下来要做的事情就是用RMAN恢复了,整个恢复过程如下:
C:\Documents and Settings\p485224>set oracle_sid=ora92br
C:\Documents and Settings\p485224>rman target sys/oracle
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database (not started)
RMAN>
RMAN> startup nomount; // (1)在nomount状态下恢复spfile
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file 'D:\OPT\ORACLE9I\PRODUCT\9.2.0\DATABASE\INITORA92BR.ORA'
trying to start the Oracle instance without parameter files ...
Oracle instance started
Total System Global Area 97589952 bytes
Fixed Size 453312 bytes
Variable Size 46137344 bytes
Database Buffers 50331648 bytes
Redo Buffers 667648 bytes
RMAN> list incarnation;
//由于没有用catalog,想在此获得dbid的愿望没有实现,不过由于controlfile的备份采用的是默认的格式,其中包含了dbid,所以还是获得了dbid。
using target database controlfile instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 04/15/2008 19:14:39
ORA-01507: database not mounted
RMAN> set dbid 2085492021;
executing command: SET DBID
RMAN> restore spfile;
Starting restore at 2008-04-15 19:15:12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=9 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/15/2008 19:15:12
RMAN-06563: controlfile or SPFILE must be restored using FROM AUTOBACKUP
RMAN> restore spfile from autobackup;
Starting restore at 2008-04-15 19:15:18
using channel ORA_DISK_1
channel ORA_DISK_1: looking for autobackup on day: 20080415
channel ORA_DISK_1: looking for autobackup on day: 20080414
channel ORA_DISK_1: looking for autobackup on day: 20080413
channel ORA_DISK_1: looking for autobackup on day: 20080412
channel ORA_DISK_1: looking for autobackup on day: 20080411
channel ORA_DISK_1: looking for autobackup on day: 20080410
channel ORA_DISK_1: looking for autobackup on day: 20080409
channel ORA_DISK_1: no autobackup in 7 days found
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/15/2008 19:15:19
RMAN-06172: no autobackup found or specified handle is not a valid copy or piece
RMAN> restore spfile from 'D:\ora_bak\RMAN\ora92br\CTRL_C-2085492021-20080415-00';
//通过上面的错误和此步的成功可以看出,在全新环境下restore,还是要指定到具体的file的。
Starting restore at 2008-04-15 19:28:06
using channel ORA_DISK_1
channel ORA_DISK_1: autobackup found: D:\ora_bak\RMAN\ora92br\CTRL_C-2085492021-20080415-00
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 2008-04-15 19:28:08
RMAN> shutdown immediate
Oracle instance shut down
RMAN> startup nomount //(2)在nomount状态下恢复controlfile
connected to target database (not started)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 04/15/2008 19:28:45
RMAN-04014: startup failed: ORA-16032: parameter LOG_ARCHIVE_DEST_1 destination string cannot be translated
ORA-09291: sksachk: invalid device specified for archive destination
OSD-04018: Unable to access the specified directory or device.
O/S-Error: (OS 2) The system cannot find the file specified.
//在此处失败,是因为LOG_ARCHIVE_DEST_1指定的目录找不到,因为是全新的环境,所以相关的目录要手动建好。在下一个步骤之前我重新启了一个session,create pfile from spfile,然后根据pfile中的信息把所有需要的路径都建好(也可以修改pfile内容指定路径到你想要的地方,然后create spfile from pfile即可)。
RMAN> startup nomount;
//此处成功,因为需要的路径已经建好。
Oracle instance started
Total System Global Area 101784276 bytes
Fixed Size 453332 bytes
Variable Size 75497472 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
RMAN> restore controlfile;
Starting restore at 2008-04-15 19:34:35
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=11 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/15/2008 19:34:35
RMAN-06563: controlfile or SPFILE must be restored using FROM AUTOBACKUP
RMAN> restore controlfile from 'D:\ora_bak\RMAN\ora92br\CTRL_C-2085492021-20080415-00';
Starting restore at 2008-04-15 19:35:16
using channel ORA_DISK_1
channel ORA_DISK_1: restoring controlfile
channel ORA_DISK_1: restore complete
replicating controlfile
input filename=D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\CONTROL01.CTL
output filename=D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\CONTROL02.CTL
output filename=D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\CONTROL03.CTL
Finished restore at 2008-04-15 19:35:25
RMAN> alter database mount; //(3)在mount状态下restore和recover数据库
database mounted
RMAN> restore database;
Starting restore at 2008-04-15 19:36:55
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\SYSTEM01.DBF
restoring datafile 00002 to D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\UNDOTBS01.DBF
restoring datafile 00003 to D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\USERS01.DBF
channel ORA_DISK_1: restored backup piece 1
piece handle=D:\ORA_BAK\RMAN\ORA92BR\DF_ORA92BR_1_1.BAK tag=TAG20080415T190405 params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 2008-04-15 19:37:22
RMAN> recover database;
Starting recover at 2008-04-15 19:38:04
using channel ORA_DISK_1
starting media recovery
unable to find archive log
archive log thread=1 sequence=4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/15/2008 19:38:04
RMAN-06054: media recovery requesting unknown log: thread 1 scn 50478
//因为是全新的环境,所有的redo log都是不可获取的,所以接下来就只能open resetlogs了...
RMAN> alter database open resetlogs; //(4)用resetlogs打开数据库
database opened
RMAN>
RMAN> report schema;
Report of database schema
File K-bytes Tablespace RB segs Datafile Name
---- ---------- -------------------- ------- -------------------
1 256000 SYSTEM *** D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\SYSTEM01.DBF
2 204800 UNDOTBS1 *** D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\UNDOTBS01.DBF
3 25600 USERS *** D:\OPT\ORACLE9I\PRODUCT\9.2.0\ORADATA\ORA92BR\USERS01.DBF
RMAN> list incarnation;
List of Database Incarnations
DB Key Inc Key DB Name DB ID CUR Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 1 ORA92BR 2085492021 NO 1 2008-04-15 18:47:17
2 2 ORA92BR 2085492021 YES 50479 2008-04-15 19:38:17
RMAN>
6. 切记,在每次恢复完之后给数据库做一个全备!!!这样可以避免很多问题。
[The End]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9765498/viewspace-237930/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9765498/viewspace-237930/