In this scenario, the database is first shut down and then started in mount mode. You can restore and recover any data file in your database while the database is not open.
This example shows the restoring of data file 1, which is associated with the SYSTEM tablespace of the container database (CDB):
$ rman target /
RMAN> shutdown abort; RMAN> startup mount; RMAN> restore datafile 1; RMAN> recover datafile 1;
RMAN> alter database open;
You can also specify the filename when performing a data file recovery:
$ rman target /
RMAN> shutdown abort; RMAN> startup mount;
RMAN> restore datafile ‘/u01/dbfile/db23c/system01.dbf’; RMAN> recover datafile ‘/u01/dbfile/db23c/system01.dbf’; RMAN> alter database open;
Restoring Data Files to Nondefault Locations
Sometimes a failure will occur that renders the disks associated with a mount point inoperable. In these situations, you will need to restore and recover the data files to a location different from the one where they originally resided.
Another typical need for restoring data files to nondefault locations is for files that you are restoring to a different database server, on which the mount points are completely different from those of the server on which the backup originated.
Use the SET NEWNAME and SWITCH commands to restore data files to nondefault locations.
Both of these commands must be run from within an RMAN run{} block. You can think of using SET NEWNAME and SWITCH as a way to rename data files (similar to the SQL ALTER DATABASE RENAME FILE statement).
This example changes the location of data files when doing a restore and recover.
First, place the database in mount mode:
$ rman target / RMAN> startup mount;
Then, run the following block of RMAN code:
run{set newname for datafile 4 to ‘/u02/dbfile/db23c/users01.dbf’; set newname for datafile 5 to ‘/u02/dbfile/db23c/users02.dbf’; restore datafile 4, 5;switch datafile all; # Updates repository with new datafile location. recover datafile 4, 5;alter database open; }
This is a partial listing of the output:
datafile 4 switched to datafile copyinput datafile copy RECID=79 STAMP=8045The33148 file name=/u02/dbfile/ db23c/users01.dbf
datafile 5 switched to datafile copyinput datafile copy RECID=80 STAMP=804533148 file name=/u02/dbfile/db23c/ users02.dbf
If the database is open, you can place the data files offline and then set their new names for restore and recovery, as follows:
run{alter database datafile 4, 5 offline; set newname for datafile 4 to ‘/u02/dbfile/db23c/users01.dbf’; set newname for datafile 5 to ‘/u02/dbfile/db23c/users02.dbf’; restore datafile 4, 5; switch datafile all; # Updates repository with new datafile location. recover datafile 4, 5; alter database datafile 4, 5 online; }
Here is the same example using ASM; the newname is just referring to the diskgroup:
run{set newname for datafile 4 to ‘+DATA’; set newname for datafile 5 to ‘+DATA’; restore datafile 4, 5;switch datafile all; # Updates repository with new datafile location. recover datafile 4, 5;alter database open; }