RMAN : Restoring datafiles to Nondefault locations

RMAN : Restoring datafiles to Nondefault locations

You have just experiences a serious media failure and won’t able to restore datafiles to their original location.In this case, you need to restore datafiles to a nondafault location.

You can use set newname and switch commands to restore datafiles to nondefault locations. You must set newname command and the switch command from within a run{} block. 
The switch command updates the target database controlfile with new location of the datafile. It’s OK to use switch datafile all, which updates all datafile locations.

If you are  performing  Point in time recovery (POITR) ensure you switch datafiles before you perform the recovery.

Now we can see the examples.
I have created one tablespace.Its name TEST with two datafiles test01.dbf,test02.dbf
The location is
                                                
C:/APP/MAZAR/ORADATA/OWN/TEST01.DBF (6) –> C:/APP/MAZAR/ORADATA/OWN/new/TEST01.DBF (Target new location)
        

C:/APP/MAZAR/ORADATA/OWN/TEST02.DBF (7) –> C:/APP/MAZAR/ORADATA/OWN/new/TEST02.DBF (Target new location)

       
6,7 Datafile ID

startup mount stage

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1046224896 bytes
Fixed Size                  1379212 bytes
Variable Size             167773300 bytes
Database Buffers          872415232 bytes
Redo Buffers                4657152 bytes
Database mounted.
SQL> host
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:/Users/mazar>rman target /

Recovery Manager: Release 11.2.0.1.0 – Production on Wed Sep 1 11:31:13 2010

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

connected to target database: OWN (DBID=1547349083, not open)

RMAN> run{
2> set newname for datafile 6 to ‘C:/APP/MAZAR/ORADATA/OWN/new/test01.dbf’;
3> set newname for datafile 7 to ‘C:/APP/MAZAR/ORADATA/OWN/new/test02.dbf’;
4> restore tablespace “TEST”;
5> switch datafile all;
6> recover tablespace “TEST”;
7> alter database open;
8> }

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 01-SEP-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

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 00006 to C:/APP/MAZAR/ORADATA/OWN/new/tes
t01.dbf
channel ORA_DISK_1: restoring datafile 00007 to C:/APP/MAZAR/ORADATA/OWN/new/tes
t02.dbf
channel ORA_DISK_1: reading from backup piece C:/APP/MAZAR/FLASH_RECOVERY_AREA/O
WN/BACKUPSET/2010_09_01/O1_MF_NNNDF_TAG20100901T112433_67W3G28B_.BKP
channel ORA_DISK_1: piece handle=C:/APP/MAZAR/FLASH_RECOVERY_AREA/OWN/BACKUPSET/
2010_09_01/O1_MF_NNNDF_TAG20100901T112433_67W3G28B_.BKP tag=TAG20100901T112433
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 01-SEP-10

datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=728566586 file name=C:/APP/MAZAR/ORADATA/OWN/N
EW/TEST01.DBF
datafile 7 switched to datafile copy
input datafile copy RECID=4 STAMP=728566586 file name=C:/APP/MAZAR/ORADATA/OWN/N
EW/TEST02.DBF

Starting recover at 01-SEP-10
using channel ORA_DISK_1

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

Finished recover at 01-SEP-10

database opened

If the database is open, you can place the datafile offline and then set their new names for restore and recovery.

RMAN> run{
2> sql ‘alter database datafile 6,7 offline’;
3> set newname for datafile 6 to ‘C:/APP/MAZAR/ORADATA/OWN/new/test01.dbf’;
4> set newname for datafile 7 to ‘C:/APP/MAZAR/ORADATA/OWN/new/test02.dbf’;
5> restore datafile 6,7;
6> switch datafile all;
7> recover datafile 6,7;
8> sql ‘alter database datafile 6,7 online’;
9> }

sql statement: alter database datafile 6,7 offline

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 01-SEP-10
using channel ORA_DISK_1

channel ORA_DISK_1: restoring datafile 00006
input datafile copy RECID=5 STAMP=728566586 file name=C:/APP/MAZAR/ORADATA/OWN/T
EST01.DBF
destination for restore of datafile 00006: C:/APP/MAZAR/ORADATA/OWN/new/test01.d
bf
channel ORA_DISK_1: copied datafile copy of datafile 00006
output file name=C:/APP/MAZAR/ORADATA/OWN/NEW/TEST01.DBF RECID=0 STAMP=0
channel ORA_DISK_1: restoring datafile 00007
input datafile copy RECID=6 STAMP=728566586 file name=C:/APP/MAZAR/ORADATA/OWN/T
EST02.DBF
destination for restore of datafile 00007: C:/APP/MAZAR/ORADATA/OWN/new/test02.d
bf
channel ORA_DISK_1: copied datafile copy of datafile 00007
output file name=C:/APP/MAZAR/ORADATA/OWN/NEW/TEST02.DBF RECID=0 STAMP=0
Finished restore at 01-SEP-10
Starting recover at 01-SEP-10
using channel ORA_DISK_1

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

Finished recover at 01-SEP-10

sql statement: alter database datafile 6,7 online

RMAN>

You can check the new datafiles locations using report schema command.

RMAN> report schema;

Report of database schema for database with db_unique_name OWN

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
—- ——– ——————– ——- ————————
1    700      SYSTEM               ***     C:/APP/MAZAR/ORADATA/OWN/SYSTEM01.DBF

2    600      SYSAUX               ***     C:/APP/MAZAR/ORADATA/OWN/SYSAUX01.DBF

3    500      UNDOTBS1             ***     C:/APP/MAZAR/ORADATA/OWN/UNDOTBS01.DBF
4    5        USERS                ***     C:/APP/MAZAR/ORADATA/OWN/USERS01.DBF
5    100      RMAN001              ***     C:/APP/MAZAR/ORADATA/OWN/RMAN01.DBF
6    100      TEST                 ***     C:/APP/MAZAR/ORADATA/OWN/NEW/TEST01.DBF
7    100      TEST                 ***     C:/APP/MAZAR/ORADATA/OWN/NEW/TEST02.DBF

and also you can check from v$datafile view.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当出现"bash: rman: 未找到命令"的错误提示时,说明系统无法找到rman命令。这通常是因为rman命令没有被正确安装或者没有设置正确的环境变量导致的。 要解决这个问题,你可以按照以下步骤进行操作: 1. 首先,确认你已经安装了rman命令。你可以通过运行"which rman"命令来检查是否已经安装。如果没有安装,你需要安装Oracle数据库软件,这将包含rman命令。 2. 如果已经安装了rman命令,但仍然出现"bash: rman: 未找到命令"的错误提示,那么可能是因为系统没有正确设置环境变量。rman命令通常位于Oracle数据库软件的安装目录下,你需要将该目录添加到系统的环境变量中。 - 如果你是root用户,可以编辑"/etc/profile"文件并在文件末尾添加以下行: ``` export PATH=$PATH:/path/to/rman/directory ``` 将"/path/to/rman/directory"替换为实际的rman命令所在的目录。 - 如果你是普通用户,可以编辑你的用户配置文件,如"~/.bashrc",并在文件末尾添加相同的行。 3. 添加完以上的环境变量后,保存文件并重新加载环境变量。 - 如果你是root用户,可以运行以下命令重新加载环境变量: ``` source /etc/profile ``` - 如果你是普通用户,可以运行以下命令重新加载环境变量: ``` source ~/.bashrc ``` 4. 完成以上步骤后,再次运行rman命令,应该就可以找到并使用了。 请注意,以上步骤是在Linux系统下操作的,如果你的操作系统不同,可能会有些许差异。另外,如果你在安装Oracle数据库软件或配置环境变量的过程中遇到了问题,你可以参考相关的文档或咨询Oracle官方支持以获得更详细的帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值