You are on page 1of 12

DATABASE CLONING USING HOT BACKUP

[root@localhost ~]# su - raman


[raman@localhost ~]$ ll
total 16
-rw-r--r-- 1 raman dba1 168 Apr 6 12:47 raman1.env
-rw-r--r-- 1 raman dba1 167 Apr 6 11:33 raman.env
[raman@localhost ~]$ . raman.env
[raman@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.1.0.6.0 - Production on Sun Apr 22 09:42:29 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 272011264 bytes
Fixed Size
1299344 bytes
Variable Size
188746864 bytes
Database Buffers
79691776 bytes
Redo Buffers
2273280 bytes
Database mounted.
Database opened.
Check all the datafiles in a database.
SQL> select name from v$datafile;
NAME
-------------------------------------------------------------------------------/d01/oracle/oradata/raman/system01.dbf
/d01/oracle/oradata/raman/sysaux01.dbf
/d01/oracle/oradata/raman/undotbs01.dbf
/d01/oracle/oradata/raman/users01.dbf

Put the database in backup mode for taking the backup of datafiles.
SQL> alter database begin backup;
alter database begin backup
*
ERROR at line 1:
ORA-01123: cannot start online backup; media recovery not enabled
It will not put the database in backup mode because media recovery is not
enabled, so enable the media recovery first.
SQL> archive log list
Database log mode
No Archive Mode
Automatic archival
Disabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Current log sequence
2
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 272011264 bytes
Fixed Size
1299344 bytes
Variable Size
188746864 bytes
Database Buffers
79691776 bytes
Redo Buffers
2273280 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;

Database altered.
Set the archive destinations where archive redolog file will go.
SQL> alter system set
log_archive_dest_1='LOCATION=/d01/oracle/oradata/raman/arch'
scope=spfile;
System altered.
Shutdown the database cleanly. It will effect on next startup only.
SQL> shutdown immediate
SQL> startup
ORACLE instance started.
Total System Global Area 272011264 bytes
Fixed Size
1299344 bytes
Variable Size
188746864 bytes
Database Buffers
79691776 bytes
Redo Buffers
2273280 bytes
Database mounted.
Database opened.
Now, check all the datafiles in a database.
SQL> select name from v$datafile;
NAME
-------------------------------------------------------------------------------/d01/oracle/oradata/raman/system01.dbf
/d01/oracle/oradata/raman/sysaux01.dbf
/d01/oracle/oradata/raman/undotbs01.dbf
/d01/oracle/oradata/raman/users01.dbf
Put the database in backup mode for taking the backup.
SQL> alter database begin backup;

Database altered.
Check whether the database is in backup mode or not.
SQL> select * from v$backup;
FILE# STATUS
CHANGE# TIME
---------- ------------------ ---------- --------1 ACTIVE
565693 22-APR-12
2 ACTIVE
565693 22-APR-12
3 ACTIVE
565693 22-APR-12
4 ACTIVE
565693 22-APR-12
Check the archive log sequence number.
SQL> archive log list
Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
/d01/oracle/oradata/raman/arch
Oldest online log sequence
1
Next log sequence to archive 3
Current log sequence
3
Check the archive redolog files.
SQL> select name from v$archived_log;
NAME
-------------------------------------------------------------------------------/d01/oracle/oradata/raman/arch1_2_781243943.dbf
/d01/oracle/oradata/raman/arch1_3_781243943.dbf
Change the database backup mode to end backup.
SQL> alter database end backup;
Database altered.
Again, check the archive log list to check the archive log sequence number.

SQL> archive log list


Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
/d01/oracle/oradata/raman/arch
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence
4
Forcefully switch the logfile for archiving.
SQL> alter system switch logfile;
System altered
Take the backup of control file to trace only because we need to change the
database name while creating the control file
SQL> alter database backup controlfile to trace;
Database altered.
Check the alert log file locations using either v$diag_info or
background_dump_dest parameter;
SQL> show parameter background_dump_dest;
NAME
VALUE
------------------------------------ ----------- -----------------------------background_dump_dest
/d01/oracle/diag/rdbms/raman/raman/trace
Go to the alert log file locations and select the appropriate trace file.
[raman@localhost raman]$ cd d01/oracle/diag/rdbms/raman/raman/trace
[raman@localhost trace]$ tail -f alert_raman.log
Completed: alter database begin backup
Sun Apr 22 09:50:20 2012
Thread 1 advanced to log sequence 4

Current log# 1 seq# 4 mem# 0: /d01/oracle/oradata/raman/redo01.log


Sun Apr 22 09:51:36 2012
alter database end backup
Completed: alter database end backup
alter database backup controlfile to trace
Backup controlfile written to trace file
/d01/oracle/diag/rdbms/raman/raman/trace/raman_ora_3662.trc
Completed: alter database backup controlfile to trace
Copy the trace file to some locations and do the modifications in the script.
[raman@localhost trace]$ cp
/d01/oracle/diag/rdbms/raman/raman/trace/raman_ora_3662.trc
/d01/raman.sql
[raman@localhost trace]$ vi /d01/raman.sql
STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "CLONEHOT" RESETLOGS
ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/d01/oracle/oradata/clonehot/redo01.log' SIZE 50M,
GROUP 2 '/d01/oracle/oradata/clonehot/redo02.log' SIZE 50M,
GROUP 3 '/d01/oracle/oradata/clonehot/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/d01/oracle/oradata/clonehot/system01.dbf',
'/d01/oracle/oradata/clonehot/sysaux01.dbf',
'/d01/oracle/oradata/clonehot/undotbs01.dbf',
'/d01/oracle/oradata/clonehot/users01.dbf'
CHARACTER SET WE8MSWIN1252
;
:%s/raman/clonehot/g

Note: All the locations of this control file creation script should exist
physically, so create the appropriate directory physically.
SQL> create pfile from spfile;
File created.
Now, come to parameter file locations and copy the pfile
[raman@localhost trace]$ cd $ORACLE_HOME/dbs
[raman@localhost dbs]$ cp initraman.ora initclonehot.ora
Edit the parameter file and do the appropriate changes.
Note: All the locations of this parameter file should exist physically, so create
the appropriate directory physically and change the database name also
[raman@localhost dbs]$ vi initclonehot.ora
clonehot.__db_cache_size=20971520
clonehot.__java_pool_size=4194304
clonehot.__large_pool_size=4194304
clonehot.__oracle_base='/d01/oracle'#ORACLE_BASE set from environment
clonehot.__pga_aggregate_target=138412032
clonehot.__sga_target=134217728
clonehot.__shared_io_pool_size=0
clonehot.__shared_pool_size=100663296
clonehot.__streams_pool_size=0
*.audit_file_dest='/d01/oracle/admin/clonehot/adump'
*.audit_trail='db'
*.compatible='11.1.0.0.0'
*.control_files='/d01/oracle/oradata/clonehot/control01.ctl','/d01/oracle/oradat
a/clonehot/control02.ctl','/d01/oracle/oradata/clonehot/control03.ctl'
*.db_block_size=8192
*.db_domain='xcellit.com'
*.db_name='clonehot'
*.db_recovery_file_dest='/d01/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648

*.diagnostic_dest='/d01/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=clonehotXDB)'
*.log_archive_dest_1='LOCATION=/d01/oracle/oradata/clonehot/arch'
*.memory_target=269484032
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
:%s/raman/clonedb/g
[raman@localhost ~]$ cd /d01/oracle/oradata/raman
[raman@localhost raman]$ ll
total 1581452
-rw-r----- 1 raman dba1 49289216 Apr 22 09:46 arch1_2_781243943.dbf
-rw-r----- 1 raman dba1 79872 Apr 22 09:50 arch1_3_781243943.dbf
-rw-r----- 1 raman dba1 19255296 Apr 22 10:00 arch1_4_781243943.dbf
-rw-r----- 1 raman dba1 9748480 Apr 22 10:00 control01.ctl
-rw-r----- 1 raman dba1 9748480 Apr 22 10:00 control02.ctl
-rw-r----- 1 raman dba1 9748480 Apr 22 10:00 control03.ctl
-rw-r----- 1 raman dba1 52429312 Apr 22 10:00 redo01.log
-rw-r----- 1 raman dba1 52429312 Apr 22 10:00 redo02.log
-rw-r----- 1 raman dba1 52429312 Apr 22 09:50 redo03.log
-rw-r----- 1 raman dba1 590880768 Apr 22 10:00 sysaux01.dbf
-rw-r----- 1 raman dba1 723525632 Apr 22 10:00 system01.dbf
-rw-r----- 1 raman dba1 20979712 Apr 22 09:56 temp01.dbf
-rw-r----- 1 raman dba1 41951232 Apr 22 09:57 undotbs01.dbf
-rw-r----- 1 raman dba1 5251072 Apr 22 09:51 users01.dbf
Copy the appropriate archive redolog files to backup locations.
[raman@localhost raman]$ cp arch* /d01/oracle/oradata/clonehot/
[raman@localhost ~]$ ll
-rw-r--r-- 1 raman dba1 168 Apr 6 12:47 raman1.env
-rw-r--r-- 1 raman dba1 167 Apr 6 11:33 raman.env

Copy the environement file to new locations and give name to new
environement file and change the ORACLE_SID parameter.
[raman@localhost ~]$ cp raman.env clonehot.env
[raman@localhost ~]$ vi clonehot.env
export ORACLE_BASE=/d01/oracle
export ORACLE_HOME=/d01/oracle/11gR2
export ORACLE_SID=clonehot
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
Now, run the environment file on stage server.
[raman@localhost ~]$ . clonehot.env
[raman@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.1.0.6.0 - Production on Sun Apr 22 09:58:26 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to an idle instance.
Start the database in nomount stage.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 272011264 bytes
Fixed Size
1299344 bytes
Variable Size
247467120 bytes
Database Buffers
20971520 bytes
Redo Buffers
2273280 bytes
Execute the control file script.
SQL> @/d01/raman.sql
Control file created.

Recover the database and apply the archive files.


SQL> recover database using backup controlfile until cancel;
ORA-00279: change 565693 generated at 04/22/2012 09:46:32 needed for
thread 1
ORA-00289: suggestion :
/d01/oracle/oradata/clonehot/arch1_3_781243943.dbf
ORA-00280: change 565693 for thread 1 is in sequence #3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 565742 generated at 04/22/2012 09:50:20 needed for
thread 1
ORA-00289: suggestion :
/d01/oracle/oradata/clonehot/arch1_4_781243943.dbf
ORA-00280: change 565742 for thread 1 is in sequence #4
ORA-00278: log file '/d01/oracle/oradata/clonehot/arch1_3_781243943.dbf'
no
longer needed for this recovery
ORA-00308: cannot open archived log
'/d01/oracle/oradata/clonehot/arch1_4_781243943.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would
get error below
ORA-01195: online backup of file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/d01/oracle/oradata/clonehot/system01.dbf'
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 565742 generated at 04/22/2012 09:50:20 needed for
thread 1

ORA-00289: suggestion :
/d01/oracle/oradata/clonehot/arch1_4_781243943.dbf
ORA-00280: change 565742 for thread 1 is in sequence #4
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log
'/d01/oracle/oradata/clonehot/arch1_4_781243943.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would
get error below
ORA-01195: online backup of file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/d01/oracle/oradata/clonehot/system01.dbf'
Open the database with resetlogs.
SQL> alter database open resetlogs;
Database altered.
Verify whether the cloning is done or not.
SQL> select name from v$database;
NAME
--------CLONEHOT
STEPS OF DATABASE CLONING USING HOT BACKUP
1. Check all the datafiles.
2. Put the database in backup mode.
3. Copy all the datafiles to backup locations.
4. Check the archive log list for archive redolog file number.
5. Put the database in end backup mode.

6. Again check archive log list for archive redo logfile number and switch the
log switch forcefully for archiving.
7. Take the backup of control file to trace.
8. Copy the control file script to backup locations and do the appropriate
changes.
9. Create pfile from spfile.
10. Copy the appropriate archive redolog files and pfile to backup locations
and do appropriate changes in pfile.
11. Now, come to stage server and create environement file and change
ORACLE_SID parameter.
12. Execute the environment file
13. Start the database in nomount stage.
14. Execute the control file script.
15. Recover the database using backup control file until cancel.
16. Apply the archive redolog files.
17. Open the database with resetlogs.
18. Verify the cloning.

You might also like