正德厚生,臻于至善

RMAN SET NEWNAME

在做数据恢复时,偶尔会碰到需要对数据文件位置调整的案例,在这种情况下,可以在RMAN中使用SET NEWNAME命令。

在Oracle 11g之前,RMAN只支持SET NEWNAME FOR DATAFILE,在Oracle 11g中增加了SET NEWNAME FOR TEMPFILE/SET NEWNAME FOR TABLESPACE/SET NEWNAME FOR DATABASE的命令。

优先顺序如下:
1.SET NEWNAME FOR DATAFILE and SET NEWNAME FOR TEMPFILE
2.SET NEWNAME FOR TABLESPACE
3.SET NEWNAME FOR DATABASE

当使用SET NEWNAME FOR DATAFILE/TEMPFILE的时候,可以使用下面的SQL生成所有的SET NEWNAME命令:
set lines 200 pages 50000
select 'alter database rename file '''||member||''' to '''||replace(member,'/xxebs/origin/db/apps_st/data/','/yyebs/sit/db/apps_st/data/')||''';' from v$logfile;

alter database open resetlogs;

select 'set newname for datafile ' || file_id || ' to ''' || replace(file_name,'/xxebs/origin/db/apps_st/data/','/yyebs/sit/db/apps_st/data/') || ''';' from dba_data_files order by file_id;

select 'set newname for tempfile ' || file_id || ' to ''' || replace(file_name,'/xxebs/origin/db/apps_st/data/','/yyebs/sit/db/apps_st/data/') || ''';' from dba_temp_files order by file_id;

当使用FOR TABLESPACE/DATABASE命令的时候,可以指定下面的变量格式:
%b  Specifies the file name stripped of directory paths.对应的文件名称
%f  Specifies the absolute file number of the data file for which the new name is generated. 数据文件的绝对文件号
%U  Specifies the following format: data-D-%d_id-%I_TS-%N_FNO-%f
%I  Specifies the DBID 对应的DBID
%N  Specifies the tablespace name 对应的表空间名称

其中前面三个变量必须指定一个,后面2个是可选的。
常见的,我们需要保持数据文件一直,值使用%b即可。

run{
allocate channel d1 device type disk;
allocate channel d2 device type disk;
allocate channel d3 device type disk;
allocate channel d4 device type disk;
allocate channel d5 device type disk;
allocate channel d6 device type disk;
allocate channel d7 device type disk;
allocate channel d8 device type disk;
catalog start with '/backup/L0/';
set newname for database to '/yyebs/sit/db/apps_st/data/%b';
#set newname for datafile '/xxebs/origin/db/apps_st/data/%b' to '/yyebs/sit/db/apps_st/data/%b';
#set newname for tempfile '/xxebs/origin/db/apps_st/data/%b' to '/yyebs/sit/db/apps_st/data/%b';
sql'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';
set until time '2021-07-21 18:08:53';
restore database;
switch datafile all;
switch tempfile all; 
recover database;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
release channel d5;
release channel d6;
release channel d7;
release channel d8;
}

官方文档提供下面命令来判别具体原因.
RMAN> list incarnation of database;
 
RMAN> list backup of datafile 1;
 
RMAN> list copy of datafile 1;
 
RMAN> list backup summary;

set lines 160 pages 9999 
select name from v$datafile 
union 
select member from v$logfile 
union 
select name from v$controlfile 
union 
select name from v$tempfile; 

参考资料:
http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmdupad.htm
http://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta055.htm#i1003832
http://docs.oracle.com/cd/B10501_01/server.920/a96565/rcmsynta50.htm#RCMRF153

赞(0) 打赏
未经允许不得转载:徐万新之路 » RMAN SET NEWNAME
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏