Tuesday, February 24, 2009

Cloning Oracle Database - Cold Cloning, Hot Cloning

Clone an Oracle Database using Cold Physical Backup

Database Name: troy

Source Database side: (Troy database)


Cold Backup Steps:

1. Get the file path information using below query

Select name from v$datafile;
select member from v$logfile;
select name from v$controlfile;

2. Parameter file backup

If troy database running on spfile

Create pfile=’/u01/backup/inittroy.ora’ from spfile;

If database running in pfile using os command to copy the pfile and placed in backup path.

3.Taken the control file backup
Alter database backup controlfile to trace as ‘/u01/backup/control01.ora’;

4.Shutdown immediate

5.Copy all the data files/log files using os command & placed in backup path.

6.Startup the database.


Clone Database side: (Clone database)

Database Name: Clone

Clone Database Steps:


1.Create the appropriate folder in corresponding path & placed the backup files in corresponding folder.(bdump,udump,create,pfile,cdump,oradata)

2.Change the init.ora parameter like control file path, dbname, instance name etc...

3.Create the password file using orapwd utility.

(Database in windows we need to create the service id using oradim utility)

4.Startup the Database in NOMOUNT stage.

5.Create the control file for cloning database.

Using backup controlfile trace to generate the create controlfile scripts.
Change the Database name & files path, also change 'REUSE' needs to be changed to 'SET'.


CREATE CONTROLFILE SET DATABASE "clone" RESETLOGS FORCE LOGGING NOARCHIVELOG
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 1
MAXLOGHISTORY 453
LOGFILE
GROUP 1 '/U01/oradata/clone/redo01.log' SIZE 200M,
GROUP 2 '/U01/oradata/clone/redo02.log' SIZE 200M,
GROUP 3 '/U01/oradata/clone/redo03.log' SIZE 200M
DATAFILE
'/U01/oradata/clone/system01.dbf',
'/U01/oradata/clone/undotbs01.dbf',
'/U01/oradata/clone/users01.dbf',
CHARACTER SET WE8ISO8859P1;

Note: placed the script in sql prompt. Now controlfile created.

6.Now open the database.

Alter database open resetlogs;

Note: Check the logfile, datafiles & instance status

**********************************************************************************

Clone an Oracle Database using Hot Physical Backup

Database Name: troy

Database must be in Archive log mode.


Source Database side: (Troy database)

Hot Backup Steps:

1.Get the file path information using below query.
Select tablespace_name, file_name from dba_data_files order by 1;

2. Parameter file backup

If troy database running on spfile

Create pfile=’/u01/backup/inittroy.ora’ from spfile;

If database running in pfile using os command to copy the pfile and placed in backup path.

3.Put the tablespace in begin backup mode Using os command to copy the datafiles belongs to begin backup mode tablespace & placed in backup path. (Refer below example)
4.Once copied the datafile, release the tablespace from begin backup mode to end backup
5.Repeat the steps 1-3 for all your tablespaces.
6.Taken the controlfile backup
Alter database backup controlfile to trace as ‘/u01/backup/control01.ora’;

7.Backup all your archive log files between the previous backup and the new backup as well.

Example:
steps:
2.Alter tablespace system begin backup;

To ensure the begin backup mode tablespace using below query
Select * from v$backup; (refer the Change#, Time column)

3. Host cp /u01/oracle/raja/system1.DBF /u01/backup/system01.dbf à using os command to copy the datafile.
4. Alter tablespace system end backup;
To ensure the begin backup mode tablespace using below query
Select * from v$backup;



Clone Database side: (Clone database)

Database Name: Clone

Clone Database Steps:


1.Create the appropriate folder in corresponding path & placed the backup files in corresponding folder.(bdump,udump,create,pfile,cdump,oradata)

2.Change the init.ora parameter like control file path, dbname, instance name etc...

3.Create the password file using orapwd utility.

(Database in windows we need to create the service id using oradim utility)

4.Startup the Database in NOMOUNT stage.


5.Create the control file for cloning database.

Using backup controlfile trace to generate the create controlfile scripts.
Change the Database name & files path, also change 'REUSE' needs to be changed to 'SET'.


CREATE CONTROLFILE SET DATABASE "clone" RESETLOGS FORCE LOGGING NOARCHIVELOG
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 1
MAXLOGHISTORY 453
LOGFILE
GROUP 1 '/U01/oradata/clone/redo01.log' SIZE 200M,
GROUP 2 '/U01/oradata/clone/redo02.log' SIZE 200M,
GROUP 3 '/U01/oradata/clone/redo03.log' SIZE 200M
DATAFILE
'/U01/oradata/clone/system01.dbf',
'/U01/oradata/clone/undotbs01.dbf',
'/U01/oradata/clone/users01.dbf',
CHARACTER SET WE8ISO8859P1;

Note: placed the script in sql prompt. Now controlfile created.

6.Recover the database using controlfile.

Recover database using backup controlfile until cancel;

7.Now open the database.

Alter database open resetlogs;

Note: Check the logfile, datafiles status.

I Hope this article helped you to understand the cloning oracle database.Suggestions are welcome.


Best Regards
RajaBaskar Thangaraj

32 comments:

  1. hi ji..

    am baburaj.. really am proud u basker u great..its very useful to also..my request is please attach ur blogs hw to apply critical and cpu patches and so on.. its my humble request..still more one should confuse about patches..

    ReplyDelete
  2. Hi Raja Baskar..So difficult.

    Will address you as Raja,
    your document is so simple to follow, but with neat steps. I have not tried yet.. but would like to try cloning, after reading ur document. Realy should appriciate your efforts, spending time for others.. Great..Pls keep posting such details and help beginners like me by sharing your knowledge.

    Thanks
    Amali

    ReplyDelete
  3. can u explain why u set reuse to set while controlfile creation

    ReplyDelete
  4. Any DOcument for RMAN Cloning Raj

    ReplyDelete
  5. can u explain why u set reuse to set while controlfile creation? Question from burle..

    create control file SET database
    the DBID is alway the same as original source database.

    ReplyDelete
  6. HI,
    CLone DB can't be taken into Archive log mode.
    and if db is not in archive mode then how can we recover the db ??

    --Shekhar

    ReplyDelete
  7. Hi

    Clone db cant be taken into archive mode.then
    if archive mode is not enabled, How can we recover the db ?

    Interesting..
    --Shekhar :)

    ReplyDelete
  8. hi raj, while cloning database why we create new control file script? please clarify my doubt..

    Regards
    Elango

    ReplyDelete
  9. while cloning database why we create new control file script?

    we need to change the clone database name,physical files structure while control file creation. while create the control file its update about clone database name in datafiles header

    ReplyDelete
  10. Hi Shekar,

    Clone db cant be taken into archive mode.then
    if archive mode is not enabled, How can we recover the db ?

    oops.. Syntax error.. i removed that noarchivelog..

    ReplyDelete
  11. Thanks Mr Rajabaskar Thangaraj,its very useful.
    keep sending scnarious like this...

    ReplyDelete
  12. Could u please differentiate cold and hot clone

    ReplyDelete
  13. Could u please differentiate cold and hot clone ?


    Cold Cloning:

    Database in archivelog mode/no archivelog mode, we can clone the database.

    Using consistent backup, we create the new database. (only we create the controlfile & open the database)

    Hot cloning:

    Database must be in archivelog mode.

    Using inconsistent backup, we create the new database.
    we create the controlfile.
    Recover the database using controlfile & apply the archive log file.
    open the database.

    Regards
    Rajabaskar Thangaraj

    ReplyDelete
  14. Hi
    I am rajesh pikku.if you have any issue pls send issue on my mail id--rajesh.pikku@rediffmail.com

    ReplyDelete
  15. Excellent raj.. but please attach the documents like how to apply the patches... for cpu patch and o patch...
    It will be more helpful to every one...

    ReplyDelete
  16. hai anna,
    this docm is realy simple, i try this one and its working
    thank u.

    ReplyDelete
  17. This is really a good document.
    Thanks.

    ReplyDelete
  18. Do we need to back up redo logs in case of hot backup ?

    ReplyDelete
  19. hi raj,
    if u have packages names for oracle 11g installation on redhat linux,please provide me, atleast site name where i can find.

    ReplyDelete
  20. What kind of errors can we get when we do the clonning (blunder errors..)Could you tel me plz....??

    ReplyDelete
  21. Hi Srinivas,

    Thanks for writing in. I was done cloning 2 years back :-) I couldn't get chance again. I forgot the errors.. last year i done active database cloning (oracle 11g). That time i faced network configuration issue (listener issue ) only..

    Best Regards
    Rajabaskar Thangaraj

    ReplyDelete
  22. Thanks Raj, it is very nice and clearly explained.

    ReplyDelete
  23. Well done raja your blog is very useful and i did the same RMAN cloning on 11gr2
    http://www.chandu208.blogspot.com/2011/12/11g-rman-cloning-using-duplicate.html

    ReplyDelete
  24. Can you please publish an article on RMAN cloning / duplicate database on ASM..?

    awaiting...

    ReplyDelete
  25. can you take cold backup of normal windows xp system plz explain them



    D.Vijaya Bhaskar

    ReplyDelete
  26. Hi Vijaya Bhaskar,

    Thanks for writing in..You can follow the same steps.

    Regards
    Rajabaskar Thangaraj

    ReplyDelete
  27. wao man that's so good.you made it so simple with this document...........

    ReplyDelete
  28. great rahabaskar its so good and simple. thanks a lot.

    ReplyDelete
  29. great rahabaskar its so good and simple. thanks a lot.

    ReplyDelete