Sei sulla pagina 1di 4

How to clone a database manually?

Posted by Amin Jaffer on January 12, 2009


Using the following steps one can clone a database manually. In the following ex
ample PRD represents the source and DEV represents target/new database.
1) Get list of datafiles on the PRD database. In the following example this data
base has 3 datafiles.
SQL> SELECT name FROM v$datafile;
NAME

/u03/oradata/PRD/system01.dbf
/u03/oradata/PRD/undotbs01.dbf
/u03/oradata/PRD/sysaux01.dbf
3 rows selected.
2) On the PRD (source) database, run the following query to find the last archiv
ed logs, the archive logs created after backup begin is run needs to be copied,
so make a note of sequence # shown needs to be copied on the DEV (target) databa
se to restore.
SQL> SELECT sequence#, TO_CHAR(next_time, DD-MON-YYYY HH24:MI:SS)
FROM (SELECT sequence#, next_time FROM V$archived_log ORDER BY next_time DESC)
WHERE rownum < 2;
SEQUENCE# TO_CHAR(NEXT_TIME,D
-
6 12-JAN-2009 20:40:15
1 row selected.
3) Execute the following SQL to make the datafiles in backup mode. This command
is supported in 10g for 9i, each tablespace would need to placed in backup mode
by using ALTER TABLESPACE name BEGIN BACKUP;
SQL> ALTER DATABASE BEGIN BACKUP;
Database altered.
4) Now the datafiles can be copied from PRD (source) to DEV (target) machine fro
m the list created in step (1)
$ cd /u03/oradata/DEV
$ cp -pi /u03/oradata/PRD/system01.dbf .
$ cp -pi /u03/oradata/PRD/undotbs01.dbf .
$ cp -pi /u03/oradata/PRD/sysaux01.dbf .
4) Execute the following SQL to make the datafiles out of backup mode.
SQL> ALTER DATABASE END BACKUP;
Database altered.
5) Perform some logswitches on the PRD (source) database, this step will create
archive logs on the source database.
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
System altered.
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
System altered.
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
System altered.
6) On the PRD (source) database, run the SQL in step (2) again to get the curren
t sequence# of archived logs. The archived log files created for the sequence# b
etween step (2) and step (6) would need to copied to the DEV (target) machine. I
n this example archive logs with sequence# 6-12 would need to be copied on the t
arget host.
SEQUENCE# TO_CHAR(NEXT_TIME,D
-
14 12-JAN-2009 20:43:05
1 row selected.
7) Modify the pfile by copying the pfile from PRD (source) to target or if the s
ource is using spfile, run the following SQL to create the pfile CREATE PFILE=/tmp
/initDEV.ora TO SPFILE; The parameters in the pfile needs to be modified for the t
arget database. In the following example the following parameters where modified
where PRD was replaced with DEV.
*.audit_file_dest=/u01/app/oracle/admin/DEV/adump
*.background_dump_dest=/u01/app/oracle/admin/DEV/bdump
*.user_dump_dest=/u01/app/oracle/admin/DEV/udump
*.core_dump_dest=/u01/app/oracle/admin/DEV/cdump
*.control_files=/u03/oradata/DEV/control01.ctl,/u03/oradata/DEV/control02.ctl,/u03/or
adata/DEV/control03.ctl
*.db_name=SMOXY
*.log_archive_format=DEV_%t_%s_%r.arc
*.log_archive_dest_1=LOCATION=/u03/oradata/DEV/arch
8 ) On the PRD (source) instance create the backup control file to trace using t
he following SQL
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
Database Altered
Modify the control file creation script in udump folder, section where the reset
logs and change REUSE TO SET, modify the name PRD to DEV, change the path of the
datafiles if needed, only the following section would needs to be run.
CREATE CONTROLFILE SET DATABASE DEV RESETLOGS ARCHIVELOG
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXDATAFILES 500
MAXINSTANCES 1
MAXLOGHISTORY 2045
LOGFILE
GROUP 1 (
/u03/oradata/DEV/redo01a.log,
/u03/oradata/DEV/redo01b.log
) SIZE 100M,
GROUP 2 (
/u03/oradata/DEV/redo02a.log,
/u03/oradata/DEV/redo02b.log
) SIZE 100M,
GROUP 3 (
/u03/oradata/DEV/redo03a.log,
/u03/oradata/DEV/redo03b.log
) SIZE 100M,
GROUP 4 (
/u03/oradata/DEV/redo04a.log,
/u03/oradata/DEV/redo04b.log
) SIZE 100M
DATAFILE
/u03/oradata/DEV/system01.dbf,
/u03/oradata/DEV/undotbs01.dbf,
/u03/oradata/DEV/sysaux01.dbf
CHARACTER SET WE8ISO8859P1;
9) On the target machine, and start the instance in nomount, make sure it will u
se the pfile created in step (7)
export ORACLE_SID=DEV
SQL> startup nomount
10) Using the script create the control file created in step ( 8 )
11) Now database can be recovered, at this step Oracle will prompt for the archi
ve logs copied in step (2) and (6) or a specific point in time can be specified.
When all the archive logs are applied, type CANCEL
SQL> RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL;
ORA-00279: change 9603 generated at 01/12/2009 20:40:43 needed for thread 1
ORA-00289: suggestion : /u03/oradata/DEV/arch/DEV_1_9_675981354.arc
ORA-00280: change 9603 for thread 1 is in sequence #9
21:07:48 Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u03/oradata/DEV/arch/DEV_1_9_675981354.arc
ORA-00279: change 9614 generated at 01/12/2009 20:40:56 needed for thread 1
ORA-00289: suggestion : /u03/oradata/DEV/arch/DEV_1_10_675981354.arc
ORA-00280: change 9614 for thread 1 is in sequence #10
ORA-00278: log file /u03/oradata/DEV/arch/DEV_1_9_675981354.arc no longer needed f
or this recovery
..
21:11:25 Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL
Media recovery cancelled.
Or (for point in time recovery)
SQL> RECOVER DATABASE UNTIL TIME 2009-01-11:15:14:30' USING BACKUP CONTROLFILE;

Media recovery complete


12) Now the database can be opened with the reset logs option.
ALTER DATABASE OPEN RESETLOGS;
Database altered.
13) Add datafile to temporary tablespace, the size of the datafile can be adjust
ed as needed.
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE /u03/oradata/DEV/temp01.dbf SIZE 100M REUS
E AUTOEXTEND OFF;
14) Change global name of the cloned database
SQL> ALTER DATABASE RENAME global_name TO DEV;
SQL> SELECT * FROM global_name;
GLOBAL_NAME

DEV

Potrebbero piacerti anche