近期由于公司需求把生产环境数据导入测试环境进行业务测试,而生产数据库管理员使用rman 进行全备份。所以在测试环境我也得使用rman进行恢复.操作步骤如下所示:
 1、首先手动创建一个参数文件,只要能启动实例就行,然后恢复备份的参数文件:
1)启动数据库到nomount状态
RMAN> startup nomount;
Oracle instance started
Total System Global Area    1610612736 bytes
Fixed Size                     2068296 bytes
Variable Size                385876152 bytes
Database Buffers            1207959552 bytes
Redo Buffers                  14708736 bytes
2)启动rman并恢复参数文件,但报错
RMAN> restore spfile from '/home/orarch_ecdsdb2/20121218/spfile.bk';
Starting restore at 07-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=541 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/07/2013 11:17:48
RMAN-06564: must use the TO clause when the instance is started with SPFILE
 

3)修改了命令继续执行发现报错如下:
RMAN> restore spfile to '/home/oracle/ora10/dbs/spfileecdsdb.ora' from '/home/orarch_ecdsdb2/20121218/spfile.bk';
Starting restore at 07-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: autobackup found: /home/orarch_ecdsdb2/20121218/spfile.bk
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/07/2013 12:20:38
ORA-32011: cannot restore SPFILE to location already being used by the instance
此错误时因为我数据库已经启动到了nomout状态用spfileecdsdb.ora文件所以生成不了,于是我就先生成spfileecds.ora'
4)生成spfileecds.ora
RMAN> restore spfile to '/home/oracle/ora10/dbs/spfileecds.ora' from '/home/orarch_ecdsdb2/20121218/spfile.bk';
Starting restore at 07-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: autobackup found: /home/orarch_ecdsdb2/20121218/spfile.bk
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 07-JAN-13
RMAN>
5)利用此文件再生成pfile_ecdsdb.ora文件
$ export ORACLE_SID=ecdsdb(可根据需求自己进行设置)
$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Mon Jan 7 12:23:15 2013
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> shutdown immediate;
ORA-01507: database not mounted

ORACLE instance shut down.
 
SQL> CREATE PFILE='/home/oracle/ora10/dbs/pfile_ecdsdb.ora' from spfile='/home/oracle/ora10/dbs/spfileecds.ora'
  2  ;
File created.
SQL>

6)按实际情况修改pfile_ecdsdb.ora文件,其中要注意control_files、audit_file_dest、background_dump_dest、core_dump_dest等四个文件的路径于你需要恢复的数据库路径一样,并且数据库实例名称要改为利用export ORACLE_SID=ecdsdb设置的ecdsdb
7)利用pfile_ecdsdb.ora生成spfileecds.ora文件
SQL> create spfile  From Pfile='/home/oracle/ora10/dbs/pfile_ecdsdb.ora'
  2  ;
File created.

2、恢复控制文件
1)启动数据库到nomount状态
SQL> startup nomount
ORACLE instance started.
Total System Global Area 2147483648 bytes
Fixed Size                  2069320 bytes
Variable Size             486542520 bytes
Database Buffers         1644167168 bytes
Redo Buffers               14704640 bytes
2)恢复控制文件
MAN> RESTORE CONTROLFILE FROM '/home/orarch_ecdsdb2/20121218/ctl.bk';
Starting restore at 07-JAN-13
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/07/2013 13:01:13
ORA-03135: connection lost contact
RMAN> quit
报如上错误信息说明是连接已经断了,所以要重新登录rman
Recovery Manager complete.
3)再一次执行恢复命令
$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Mon Jan 7 13:03:56 2013
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: ecdsdb (not mounted)
RMAN> RESTORE CONTROLFILE FROM '/home/orarch_ecdsdb2/20121218/ctl.bk';
Starting restore at 07-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=2190 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
output filename=/home/oracle/oradata/ecdsdb/rcontrol01
output filename=/home/oracle/oradata/ecdsdb/rcontrol02
output filename=/home/oracle/oradata/ecdsdb/rcontrol03
Finished restore at 07-JAN-13
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

RMAN> catalog start with '/dsms2012/';
released channel: ORA_DISK_1
searching for all files that match the pattern /dsms2012/
List of Files Unknown to the Database
=====================================
File Name: /dsms2012/arch_ECDSDB_30530_1.bk
File Name: /dsms2012/arch_ECDSDB_30531_1.bk
File Name: /dsms2012/ctl.bk
File Name: /dsms2012/pri_ECDSDB_30526_1.bk
File Name: /dsms2012/pri_ECDSDB_30527_1.bk
File Name: /dsms2012/pri_ECDSDB_30528_1.bk
File Name: /dsms2012/pri_ECDSDB_30529_1.bk
File Name: /dsms2012/spfile.bk
Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /dsms2012/arch_ECDSDB_30530_1.bk
File Name: /dsms2012/arch_ECDSDB_30531_1.bk
File Name: /dsms2012/ctl.bk
File Name: /dsms2012/pri_ECDSDB_30526_1.bk
File Name: /dsms2012/pri_ECDSDB_30527_1.bk
File Name: /dsms2012/pri_ECDSDB_30528_1.bk
File Name: /dsms2012/pri_ECDSDB_30529_1.bk
File Name: /dsms2012/spfile.bk
3、修复数据库
1)执行恢复命令
RMAN> RESTORE DATABASE;
Starting restore at 07-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=2190 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /home/db/oracle/oradata/ecdsdb/rsystem_01_4g
restoring datafile 00002 to /home/db/oracle/oradata/ecdsdb/rundotbs1_01_10g
restoring datafile 00004 to /home/db/oracle/oradata/ecdsdb/ruser_01_512m
restoring datafile 00006 to /home/db/oracle/oradata/ecdsdb/rtbs_data1_01_16g
restoring datafile 00008 to /home/db/oracle/oradata/ecdsdb/rtbs_part_01_16g
channel ORA_DISK_1: reading from backup piece /home/orarch_ecdsdb2/20121218/pri_ECDSDB_30527_1.bk
ORA-19870: error reading backup piece /home/orarch_ecdsdb2/20121218/pri_ECDSDB_30527_1.bk
ORA-19504: failed to create file "/home/db/oracle/oradata/ecdsdb/rtbs_data1_01_16g"
ORA-27040: file create error, unable to create file
HPUX-ia64 Error: 2: No such file or directory
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00003 to /home/db/oracle/oradata/ecdsdb/rsysaux_01_4g
restoring datafile 00005 to /home/db/oracle/oradata/ecdsdb/rundotbs2_01_10g
restoring datafile 00007 to /home/db/oracle/oradata/ecdsdb/rtbs_data2_01_24g
restoring datafile 00009 to /home/db/oracle/oradata/ecdsdb/rtbs_idx1_01_16g
restoring datafile 00010 to /home/db/oracle/oradata/ecdsdb/rpatrol_data_01_256m
channel ORA_DISK_1: reading from backup piece /home/orarch_ecdsdb2/20121218/pri_ECDSDB_30526_1.bk
ORA-19870: error reading backup piece /home/orarch_ecdsdb2/20121218/pri_ECDSDB_30526_1.bk
ORA-19504: failed to create file "/home/db/oracle/oradata/ecdsdb/rtbs_data2_01_24g"
ORA-27040: file create error, unable to create file
HPUX-ia64 Error: 2: No such file or directory
failover to previous backup
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/07/2013 13:07:37
RMAN-06026: some targets not found - aborting restore
RMAN-06100: no channel to restore a backup or copy of datafile 10
RMAN-06100: no channel to restore a backup or copy of datafile 9
RMAN-06100: no channel to restore a backup or copy of datafile 8
RMAN-06100: no channel to restore a backup or copy of datafile 7
RMAN-06100: no channel to restore a backup or copy of datafile 6
RMAN-06100: no channel to restore a backup or copy of datafile 5
RMAN-06100: no channel to restore a backup or copy of datafile 4
RMAN-06100: no channel to restore a backup or copy of datafile 3
RMAN-06100: no channel to restore a backup or copy of datafile 2
RMAN-06100: no channel to restore a backup or copy of datafile 1
报如上错误,说明控制文件中记录了目标数据库的数据库文件路径和本地的/home/oracle/oradata/ecdsdb/不同,所以必须重新指向数据文件的位置如下操作。
 
 
2)执行脚本命令重新恢复数据库
RMAN> run{
2> set newname for datafile 1 to '/home/oracle/oradata/ecdsdb/system_01_4g';
3>    set newname for datafile 2 to '/home/oracle/oradata/ecdsdb/undotbs1_01_10g';
4>    set newname for datafile 4 to '/home/oracle/oradata/ecdsdb/user_01_512m';
5>    set newname for datafile 6 to '/home/oracle/oradata/ecdsdb/tbs_data1_01_16g';
6>    set newname for datafile 8 to '/home/oracle/oradata/ecdsdb/tbs_part_01_16g';
7>    set newname for datafile 3 to '/home/doracle/oradata/ecdsdb/sysaux_01_4g';
8>    set newname for datafile 5 to '/home/oracle/oradata/ecdsdb/undotbs2_01_10g';
9>    set newname for datafile 7 to '/home/oracle/oradata/ecdsdb/tbs_data2_01_24g';
10>    set newname for datafile 9 to '/home/oracle/oradata/ecdsdb/tbs_idx1_01_16g';
11>    set newname for datafile 10 to '/home/oracle/oradata/ecdsdb/patrol_data_01_256m';
12> restore database;
13> }
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
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 07-JAN-13
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 /home/oracle/oradata/ecdsdb/rsystem_01_4g
restoring datafile 00002 to /home/oracle/oradata/ecdsdb/rundotbs1_01_10g
restoring datafile 00004 to /home/oracle/oradata/ecdsdb/ruser_01_512m
restoring datafile 00006 to /home/oracle/oradata/ecdsdb/rtbs_data1_01_16g
restoring datafile 00008 to /home/oracle/oradata/ecdsdb/rtbs_part_01_16g
channel ORA_DISK_1: reading from backup piece /home/orarch_ecdsdb2/20121218/pri_ECDSDB_30527_1.bk
4、恢复数据库
rman>RECOVER DATABASE;