Restoring Oracle DB using RMAN

oracle-11g

I am a application developer doing DBA work. I have to restore an oracle database on our test server. The databases are backed up using RMAN and the last db restore that was done on this server was in the year 2011. RMAN back up is running daily. Anyways I want to restore the test database to match the production production database. Can I copy the required datafiles and control file from the production server and place it on the test server at the exact location where the back up files are placed, or how to go about this. I want to perform a point in time recovery. I don't want to corrupt the production database. Since the production servers are backing up the database daily, I thought I would copy day before yesterday's copy and put it on the test server and give the path name to RMAN while doing point in time recovery..Please suggest me what to do..And this is the code I would use to recover, please let me know if it is ok. Thanks

SET NLS_DATE_FORMAT="DD-MON-YYYY HH24:MI:SS" 
SET ORACLE_SID=
rman target / nocatalog 
shutdown immediate; 
startup mount; 
 run 
 { 
  SET UNTIL TIME "TO_DATE('set to whatever time you want to recover','DD-MON-YYYY  HH24:MI:SS')"; 
  restore database; 
  recover database; 
  alter database open resetlogs;
 }

Best Answer

You don't want your test database to retain the same internal id number as the production database. Hence it would be best to use RMAN's command DUPLICATE, because it sets a different id (and also a new database name). This command is specifically designed to do what you require.