使用 SET NEWNAME 切换文件(相当于copy),set newname 的作用是恢复到一个新的路径
switch 做切换把新路径文件写到控制文件中恢复到一个新的路径
1) 创建测试表空间,数据文件放在/home/oracle/oradata/目录下
——创建目录:
[oracle@wang ~]$ mkdir oradata
[oracle@wang ~]$ cd oradata/
[oracle@wang oradata]$ ls
[oracle@wang oradata]$
[oracle@wang oradata]$ pwd
/home/oracle/oradata
——创建表空间:
SYS@ORA11GR2>create tablespace ts_xxf datafile '/home/oracle/oradata/ts_xxf_01.dbf' size 10m;
Tablespace created.
SYS@ORA11GR2>select file_name from dba_data_files where tablespace_name='TS_XXF';
FILE_NAME
----------------------------------------------------------------------------
/home/oracle/oradata/ts_xxf_01.dbf
2.通过RMAN切换数据文件路径
RMAN> run
{allocate channel c1 device type disk;
sql "alter tablespace ts_xxf offline immediate";
set newname for datafile '/home/oracle/oradata/ts_xxf_01.dbf' to '/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf';
restore tablespace ts_xxf;
switch datafile all;
recover tablespace ts_xxf;
sql "alter tablespace ts_xxf online";
}
released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=21 device type=DISK
sql statement: alter tablespace ts_xxf offline immediate
executing command: SET NEWNAME
Starting restore at 02-OCT-16
creating datafile file number=6 name=/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 02-OCT-16
datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=924173852 file name=/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf
Starting recover at 02-OCT-16
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 02-OCT-16
sql statement: alter tablespace ts_xxf online
released channel: c1
3.验证
SYS@ORA11GR2>select file_name from dba_data_files where tablespace_name='TS_XXF';
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf
SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf
/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf
SYS@ORA11GR2>
SYS@ORA11GR2>!ls /home/oracle/oradata/ts_xxf_01.dbf
/home/oracle/oradata/ts_xxf_01.dbf
SYS@ORA11GR2>!rm /home/oracle/oradata/ts_xxf_01.dbf
在rman下SET NEWNAME,就是将其他目录下的同名数据文件复制到原目录下去,利用的是RMAN工具!注 切换完毕后,原目录下还有数据文件,删除之即可。
主要内容命令如下:
run
{allocate channel c1 device type disk;
sql "alter tablespace ts_xxf offline immediate";
set newname for datafile '/home/oracle/oradata/ts_xxf_01.dbf' to '/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf';
restore tablespace ts_xxf;
switch datafile all;
recover tablespace ts_xxf;
sql "alter tablespace ts_xxf online";
}
alert日志相应内容如下:
/
Thu Dec 07 23:19:11 2017
alter tablespace ts_xxf offline immediate
Completed: alter tablespace ts_xxf offline immediate
Switch of datafile 6 complete to datafile copy
checkpoint is 3919138
alter database recover datafile list clear
Completed: alter database recover datafile list clear
alter database recover if needed
tablespace TS_XXF
Media Recovery Start
Serial Media Recovery started
Recovery of Online Redo Log: Thread 1 Group 3 Seq 921 Reading mem 0
Mem# 0: /u01/app/oracle/oradata/DBdb/redo03.log
Media Recovery Complete (DBdb)
Completed: alter database recover if needed
tablespace TS_XXF
alter tablespace ts_xxf online
Completed: alter tablespace ts_xxf online
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2126536/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31397003/viewspace-2126536/