RMAN
Using set newname to Change the Restored File Location
As default, RMAN restores a backup of a datafile to its default
location. To change this behavior, use the set newname command to
define a new location for the restored datafile.
Prior to Oracle 11gR2, this command was used to rename the
datafiles and tempfiles. But starting from Oracle 11gR2, you can
rename all datafiles in any tablespace and even the whole database
files. Moreover, these new options come with new substitution
variables which help to change the set of filenames at once. See
the usage of these options and substitution variables in real
examples.
- Using set newname for datafile
RMAN> run
{
set newname for datafile 4 to '/tmp/datafile4.dbf';
restore datafile 4;
}
executing command: set newname
channel ORA_DISK_1: restoring datafile 00004 to /tmp/datafile4.dbf
- Using set newname for tempfile
To create a tempfile in a new directory while cloning the
database, use the set newname for tempfile to
?. command as follows:
RMAN> run
{
set newname for tempfile 1 to /tmp/temp01.dbf';
duplicate database;
}
RMAN will create a new tempfile with a specified name after the
database is recovered and opened.
- Using set newname for tablespace
This option is used to change all datafiles in a specified
tablespace. When using this option, you must use a substitution
variable to avoid name collisions. Here is the list of
substitution variables which are used during name conversion:
-
%b: Specifies the file name without
the directory that it locates.
-
%N: Specifies the tablespace
name
-
%f: Specifies the absolute file number
of a datafile
-
%I: Specifies DBID
-
%U: Specifies system generated unique
filename as a following format: data-D-%d_id-%I_TS-%N_FNO-%f
See the following example to understand these substitution
variables. In the following example, the %b, %N and %f variables
are used:
RMAN> run
2> {
3> set newname for tablespace users to '/tmp/db/%n_%f_%b';
4> restore tablespace users;
5> }
output file name=/tmp/db/USERS_4_users01.dbf RECID=8
STAMP=728496167
output file name=/tmp/db/USERS_5_user02.dbf RECID=9
STAMP=728496168
By using the %U variable, you can get the system-generated
unique filename. Look at the following example:
RMAN> run
2> {
3> set newname for tablespace users to '/tmp/db/%u';
4> restore tablespace users;
5> }
output file name=/tmp/db/data_d-test_ts-users_fno-4 recid=10
stamp=728496242
output file name=/tmp/db/data_d-test_ts-users_fno-5 recid=11
stamp=728496243
- Using set newname for database
This option is used to set a new name for all datafiles and
tempfiles in a database. This option is also used with one of the
above mentioned substitution variables.