42: Database Clone - Agnivo102/Database_Architect GitHub Wiki
Cloning a database to a different server in real time:
Step 1:
Connect 2 servers in network.
Step 2:
Create a listener and a tnsname in the database. Then send the tnsname file to the different server and check whether its ok or not using tnsping command.
Step 3:
Put the new database sid in oratab file to create an environment with it.
Step 4:
Create a password file. Remember that the database which we will duplicate and the new database in the other machine has to have same sys user password.
Step 5:
Create a pfile for the new database with only (*.db_name='dev') this line.
Step 6:
Create the directory structure for control file, data files, log files and audit dump files in the new server from the pfile.
Oops there was some error. Create the directory structure with the new database name not the old name.
Step 7:
Now start the new database in nomount state. And lets again check the tnsname listener connection name connection.
Step 8:
Now connect to RMAN tool with this command rman target sys/oracle@tnsnew auxiliary sys/oracle. This connect both the database at the same time.
Step 9: Now run this Duplication Script:
run { duplicate database to dev from active database spfile parameter_value_convert=('production','dev') set db_file_name_convert='/u01/app/oracle/oradata/PRODUCTION/','/u01/app/oracle/oradata/DEV/' set log_file_name_convert='/u01/app/oracle/oradata/PRODUTION/','/u01/app/oracle/oradata/DEV/' set control_files='/u01/app/oracle/oradata/DEV/control01.ctl','/u01/app/oracle/fast_recovery_area/DEV/control02.ctl' set db_name='dev' NOFILENAMECHECK; }
Step 10: This will copy the database into new server.
Finish: See now we can open the database.
Explanation of the script:
run { duplicate database to dev from active database : Duplicates the database to the new database which is currently inactive feom the active running database. spfile : This tell to copy the spfile from the active database. parameter_value_convert=('production','dev') :As we are changing the database name in its clone. set db_file_name_convert='/u01/app/oracle/oradata/PRODUCTION/','/u01/app/oracle/oradata/DEV/' : As we need to change the location adress of the data files. By the way all these locations in the script all have to be created beforehand. set log_file_name_convert='/u01/app/oracle/oradata/PRODUTION/','/u01/app/oracle/oradata/DEV/' : This is for changing the location of redo log files. set control_files='/u01/app/oracle/oradata/DEV/control01.ctl','/u01/app/oracle/fast_recovery_area/DEV/control02.ctl' : This creates the control files itself again for the cloned database. set db_name='dev' : Sets the name of the new database. NOFILENAMECHECK; : As we are changing the names of the database this line forces the process to not check any file names during the duplication. }
Also Improtant thing. The active database has to be in archive log mode for the duplication to work.