Pages

Saturday, May 21, 2011

Super fast Database Copying/Cloning

Database Cloning from Production to Development DB

STEP 1: sign on as SYSDBA and issue: “alter database backup controlfile to trace”. This will put the create database syntax in the trace file directory. The trace keyword tells oracle to generate a script containing a create controlfile command and store it in the trace directory identified in the user_dump_dest parameter of the init.ora file. It will look something like this:

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "PRODDB" NORESETLOGS
NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 240
MAXINSTANCES 1
MAXLOGHISTORY 113
LOGFILE
GROUP 1 ('/u03/oradata/PRODDB/log1a.dbf',
'/u03/oradata/PRODDB/log1b.dbf') SIZE 30M,
GROUP 2 ('/u04/oradata/PRODDB/log2a.dbf',
'/u04/oradata/PRODDB/log2b.dbf') SIZE 30M
DATAFILE
'/u01/oradata/PRODDB/system01.dbf',
'/u01/oradata/PRODDB/mydatabase.dbf'
;
# Recovery is required if any of the datafiles are restored
# backups, or if the last shutdown was not normal or immediate.
RECOVER DATABASE
# Database can now be opened normally.
ALTER DATABASE OPEN;


STEP 2: Shutdown the PRODDB database

STEP 3:
Copy all data files into the new directories on the new server. You may change the file names if you want, but you must edit the controlfile to reflect the new data files names on the new server.

rcp /u01/oradata/PRODDB/* newhost:/u01/oradata/DEVDB
rcp /u01/oradata/PRODDB/* newhost:/u01/oradata/DEVDB
rcp /u03/oradata/PRODDB/* newhost:/u03/oradata/DEVDB
rcp /u04/oradata/PRODDB/* newhost:/u04/oradata/DEVDB


STEP 4:
Copy and Edit the Control file – Using the output syntax from STEP 1, modify the controlfile creation script by changing the following:

Old:

CREATE CONTROLFILE REUSE DATABASE "PRODDB" NORESETLOGS

New:

CREATE CONTROLFILE SET DATABASE "DEVDB" RESETLOGS

STEP 5: Remove the “recover database” and “alter database open” syntax

# Recovery is required if any of the datafiles are restored
# backups, or if the last shutdown was not normal or immediate.
RECOVER DATABASE
# Database can now be opened normally.
ALTER DATABASE OPEN;


STEP 6: Re-names of the data files names that have changed.

Save as db_create_controlfile.sql.

Old:

DATAFILE
'/u01/oradata/PRODDB/system01.dbf',
'/u01/oradata/PRODDB/mydatabase.dbf'

New:

DATAFILE
'/u01/oradata/DEVDB/system01.dbf',
'/u01/oradata/DEVDB/mydatabase.dbf'

STEP 7: Create the bdump, udump and cdump directories

cd $DBA/admin
mkdir DEVDB
cd DEVDB
mkdir bdump
mkdir udump
mkdir cdump
mkdir pfile


STEP 8:
Copy-over the old init.ora file

rcp $DBA/admin/PRODDB/pfile/*.ora newhost:/u01/oracle/admin/DEVDB/pfile

STEP 9: Start the DEVDB database

@db_create_controlfile.sql

STEP 10: Place the DEVDB database in archivelog mode

No comments:

Post a Comment