****************************************************************
* Description: Procedure of rman restore and recover a database
* Compatiablity: RDBMS 11g, 12c
* Date: 11:59 AM EST, 05/02/2017
****************************************************************



<1> Drop current database:
     |
     |__ SQL> shutdown immediate;
         SQL> startup exclusive mount restrict;
         SQL> drop database;


		 
<2> Create Oracle Instance Windows Service [MSWIN Platform Only]:
     |
     |__ CMD> ORADIM -new -sid <DB_NAME> -SRVC OracleServiceEmeralit -STARTMODE auto -SRVCSTART system -PFILE C:\oracle\product\11.2.0\dbhome_1\database\initEmeralit.ora
         CMD> ORADIM -DELETE -sid <DB_NAME>


		 
<3> Startup Instance into NOMOUNT Mode:
     |
     |__ CMD> set ORACLE_SID=emeralit
         SQL> startup nomount pfile='C:\oracle\product\11.2.0\dbhome_1\database\initEmeralit.ora';

	
	
<4> Restore Control File:
     |
     |__ CMD> rman target /
         RMAN> restore controlfile from 'E:\rman_backup_07212016\CONTROLC-1077298371-20160721-00.CTL';
	
	
	
<5> Mount Database:
     |
     |__ RMAN> alter database mount;
	

	
<6> Catalog Start [RMAN will recognize where the backup is]:
     |
     |__ RMAN> catalog start with 'E:\rman_backup_07212016';
	 
               -- Manual Method
               CATALOG BACKUPPIECE '/u01/app/oracle/fast_recovery_area/datastore/emeralit_bkp/INC_0_EMERALIT_DB_0bs075s4_11_1';
               CATALOG BACKUPPIECE '/u01/app/oracle/fast_recovery_area/datastore/emeralit_bkp/INC_0_EMERALIT_DB_0cs075s4_12_1';
               CATALOG BACKUPPIECE '/u01/app/oracle/fast_recovery_area/datastore/emeralit_bkp/INC_0_EMERALIT_DB_0ds075s5_13_1';
               CATALOG BACKUPPIECE '/u01/app/oracle/fast_recovery_area/datastore/emeralit_bkp/INC_0_EMERALIT_DB_0es075s5_14_1';
               CATALOG BACKUPPIECE '/u01/app/oracle/fast_recovery_area/datastore/emeralit_bkp/INC_0_EMERALIT_DB_0gs077s5_16_1';
               CATALOG BACKUPPIECE '/u01/app/oracle/fast_recovery_area/datastore/emeralit_bkp/INC_0_EMERALIT_DB_0fs077s3_15_1';


			   
<7> Start Restore:
     |
     |__ CMD> rman target / @E:\rman_script\restore_emeralit.rman log=E:\rman_script\restore_emeralit_1217_07252016.log
	 
                 run {
                         allocate channel c1 type disk;
                         allocate channel c2 type disk;
                         allocate channel c3 type disk;
                         allocate channel c4 type disk;
                         set newname for tempfile 1 to '+DATA'; #Optional
                         set newname for tempfile 2 to '+DATA'; #Optional
                         set newname for tempfile 3 to '+DATA'; #Optional
                         restore database;
                         switch tempfile all;
                         release channel c1;
                         release channel c2;
                         release channel c3;
                         release channel c4;
                 }

	
	
<8> Start Recovery:
     |
     |__ CMD> rman target / @E:\rman_script\recover_emeralit.rman log=E:\rman_script\recover_emeralit_1517_07252016.log
	 
                 run {
                         allocate channel c1 type disk;
                         allocate channel c2 type disk;
                         allocate channel c3 type disk;
                         allocate channel c4 type disk;
                         set until time = "to_date('2015/11/13 22:30:00','YYYY/MM/DD HH24:MI:SS')";
                         recover database;
                         release channel c1;
                         release channel c2;
                         release channel c3;
                         release channel c4;
                 }
	

	
<9> Alter database open:
     |
     |__ SQL> alter database open resetlogs;	 
	 
	 
	 
	 
#========================================== ADDENDUM ==========================================#	 
	 	 
	 
	 
<1> If restore database in different drives/mount point, restore needs "SET NEWNAME": 
     |
     |__ Restore Script:
        	
             run
             {
                 #=== Allocating Channel ===
                 allocate channel c1 type disk;
                 
                 #=== Restore Data File Target Location ===
                 set newname for datafile 1 to 'E:\ORADATA\EMERALIT\SYSTEM01.DBF';
                 set newname for datafile 2 to 'E:\ORADATA\EMERALIT\SYSAUX01.DBF';
                 set newname for datafile 3 to 'E:\ORADATA\EMERALIT\UNDOTBS01.DBF';
                 set newname for datafile 4 to 'E:\ORADATA\EMERALIT\USERS01.DBF';
                 set newname for datafile 5 to 'E:\ORADATA\EMERALIT\CCS_INDEX01.DBF';
                 set newname for datafile 6 to 'E:\ORADATA\EMERALIT\CCS_INDEX02.DBF';
                 set newname for datafile 7 to 'E:\ORADATA\EMERALIT\CCS_DATA01.DBF';
                 set newname for datafile 8 to 'E:\ORADATA\EMERALIT\LAPPS_DATA01.DBF';	
                 set newname for datafile 9 to 'E:\ORADATA\EMERALIT\FORTIS01.DBF';
                 set newname for datafile 10 to 'E:\ORADATA\EMERALIT\AGED_DATA01.DBF';
                 set newname for datafile 11 to 'E:\ORADATA\EMERALIT\QUANTUM01.DBF';
                 set newname for datafile 12 to 'E:\ORADATA\EMERALIT\CCS_OPAR_DATA01.DBF';
                 set newname for datafile 13 to 'E:\ORADATA\EMERALIT\CCS_AGED_DATA01.DBF';
                 set newname for datafile 14 to 'E:\ORADATA\EMERALIT\CCS_AR_DATA01.DBF';
                 set newname for datafile 15 to 'E:\ORADATA\EMERALIT\LAPPS_INDEX01.DBF';
                 set newname for datafile 16 to 'E:\ORADATA\EMERALIT\CCS_INVOICING_DATA01.DBF';
                 set newname for datafile 17 to 'E:\ORADATA\EMERALIT\CCS_COLLECT_DATA01.DBF';
                 set newname for datafile 18 to 'E:\ORADATA\EMERALIT\LAPPS_LOB_DATA01.DBF';
                 set newname for datafile 19 to 'E:\ORADATA\EMERALIT\CANON01.DBF';
                 set newname for datafile 20 to 'E:\ORADATA\EMERALIT\REPLICATED_DATA01.DBF';
                 set newname for datafile 21 to 'E:\ORADATA\EMERALIT\LAPPS_APP_DATA01.DBF';
                 set newname for datafile 22 to 'E:\ORADATA\EMERALIT\CCS_LEASES_DATA01.DBF';
                 set newname for datafile 23 to 'E:\ORADATA\EMERALIT\CCS_DATA02.DBF';
                 set newname for datafile 24 to 'E:\ORADATA\EMERALIT\CCS_AGED_DATA02.DBF';
                 
                 #=== Restore Temp File Target Location ===
                 set newname for tempfile 1 to 'E:\ORADATA\EMERALIT\TEMP01.DBF';
                 set newname for tempfile 2 to 'E:\ORADATA\EMERALIT\LAPPS_TEMP01.DBF';
                 set newname for tempfile 3 to 'E:\ORADATA\EMERALIT\CCS_TEMP01.DBF';
                 
                 #=== Restoring Database ===
                 restore database;
                 
                 #=== Register New Name in Database ===
                 switch datafile all;
                 switch tempfile all;
                 
                 #=== Release channel ===
                 release channel c1;
             }
	
	
	
<2> If redo log location is different, the log needs to be created physically and renamed BEFORE altering database open:
     |
     |__ SQL> ALTER DATABASE RENAME FILE 'D:\DATABASE\ORADATA\EMERALIT\REDO03.LOG' to 'E:\ORADATA\EMERALIT\REDO03.LOG';
         SQL> ALTER DATABASE RENAME FILE 'D:\DATABASE\ORADATA\EMERALIT\REDO02.LOG' to 'E:\ORADATA\EMERALIT\REDO02.LOG';
         SQL> ALTER DATABASE RENAME FILE 'D:\DATABASE\ORADATA\EMERALIT\REDO01.LOG' to 'E:\ORADATA\EMERALIT\REDO01.LOG';