You are on page 1of 9

Thc hnh: S dng RMAN Duplicate Database

Trong thc t c rt nhiu trng hp chng ta cn phi Duplicate Database (Clone DB). Chng hn nh chng ta cn DB test chng trnh mi, s dng cho developer, dng

chy reports,... C nhiu cch Clone DB, v d nh cch Clone DB bng Tay m chng ta tng tham kho. Hm nay chng ta s cng Clone DB bng mt cng c khc: RMAN Cc bc thc hin bao gm:

1. Chun b DB ngun v server. 2. Thit lp kt ni (Oracle Net) n DB ngun. 3. To Parameter File (pfile) cho DB nhn bn. 4. To Password File cho DB nhn bn. 5. Startup DB nhn bn bc NOMOUNT. 6. Dng RMAN full backup DB ngun. 7. Chy lnh Duplicate. 1. Chun b DB ngun v server.
Cu hnh DB v OS trong bi ny: - OS: Linux CentOS 4 - DB: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Server Name: labs - DB ngun: orcl + Archive Mode - DB nhn bn: oravn - Backup Dir: /u01/oravn_backup/ - ORACLE_HOME: /u01/app/oracle/product/10.2.0/db_1/

2. Thit lp kt ni (Oracle Net) n DB ngun.


ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = labs)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )

- M file /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora thm vo an kt ni nh bn di:

- Th nghim kt ni bng tnsping v bng sqlplus

[oracle@labs ~]$ tnsping orcl TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 27-APR-2009 09:28:32 Copyright (c) 1997, 2005, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = labs) (PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl))) OK (10 msec) [oracle@labs ~]$ [oracle@labs ~]$ sqlplus sys/oracle@orcl as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 27 09:30:18 2009 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining options SQL>

- tm hiu ci hnh Oracle Net, vui lng xem y.

3. To Parameter File (pfile) cho DB nhn bn.


Cch n gin to pfile cho DB nhn bn l "copy" ni dung t spfile ca DB ngun thng qua lnh CREATE PFILE..., sau sa li. - Copy t spfile ca DB ngun:
[oracle@labs ~]$ export ORACLE_SID=orcl [oracle@labs ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Tue Apr 28 04:25:46 2009 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining options SQL> create pfile='/u01/oravn_backup/initoravn.ora' from spfile ; File created. SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining options [oracle@labs ~]$ [oracle@labs ~]$ ls -lh /u01/oravn_backup/initoravn.ora -rw-r--r-- 1 oracle dba 1.1K Apr 27 09:49 /u01/oravn_backup/initoravn.ora [oracle@labs ~]$

- Sa li mt cht trong file trn: + Thay cc dng dn n orcl thnh oravn + Thm dng convert ng dn sang ni khc.

<i>Bn tri l ni dung pfile c, bn phi l ni dung sau khi sa li.</i> -Lu : to cc ng dn tng ng trong file trn:
[oracle@labs [oracle@labs [oracle@labs [oracle@labs [oracle@labs ~]$ ~]$ ~]$ ~]$ ~]$ mkdir mkdir mkdir mkdir mkdir -p -p -p -p -p /u01/app/oracle/admin/oravn/adump /u01/app/oracle/admin/oravn/bdump /u01/app/oracle/admin/oravn/cdump /u01/app/oracle/admin/oravn/udump /u01/app/oracle/oradata/oravn

4. To Password File cho DB nhn bn.


- Dng lnh orapwd to password file. Trong lnh ny ti t password cho user SYS l oracle
[oracle@labs ~]$ orapwd file='/u01/app/oracle/product/10.2.0/db_1/dbs/orapworavn' password=oracle entries=5 [oracle@labs ~]$ ls -lh /u01/app/oracle/product/10.2.0/db_1/dbs/orapworavn -rw-r----- 1 oracle dba 1.5K Nov 13 11:54 /u01/app/oracle/product/10.2.0/db_1/dbs/orapworavn

Lu : + Trn Linux v Unix, tn file phn bit ch Hoa v ch thng. + Tn v v tr pwfile phi nm ng th mc qui c ty theo OS.

5. Startup DB nhn bn bc NOMOUNT.

Sau khi c pfile v pwfile, chng ta c th STARTUP NOMOUNT DB nhn bn, ng thi to lun spfile t pfile (bc 2).
[oracle@labs ~]$export ORACLE_SID=oravn [oracle@labs ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 27 10:22:48 2009 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount pfile='/u01/oravn_backup/initoravn.ora' ;

ORACLE instance started. Total System Global Area 285212672 bytes Fixed Size 1218992 bytes Variable Size 92276304 bytes Database Buffers 188743680 bytes Redo Buffers 2973696 bytes SQL> create spfile from pfile='/u01/oravn_backup/initoravn.ora' ; File created. SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining options [oracle@labs ~]$

Kim tra chc chn l spfile cho oravn c to:


[oracle@labs -rw-r----- 1 -rw-r----- 1 [oracle@labs ~]$ ls -l $ORACLE_HOME/dbs/sp*.ora oracle dba 2560 Apr 27 10:23/u01/app/oracle/product/10.2.0/db_1/dbs/spfileoravn.ora oracle dba 2560 Apr 27 06:51/u01/app/oracle/product/10.2.0/db_1/dbs/spfileorcl.ora ~]$

6. Dng RMAN full backup DB ngun.


Trong phn ny chng ta lm 2 vic: - Kim tra xem thng s CONTROLFILE AUTOBACKUP, v bt ln thnh ON. - Full Backup Database cng vi Archive Log file.
[oracle@labs oravn_backup]$ rman Recovery Manager: Release 10.2.0.1.0 - Production on Mon Apr 27 10:03:00 2009 Copyright (c) 1982, 2005, Oracle. All rights reserved. RMAN> connect target sys/oracle@orcl connected to target database: ORCL (DBID=1212807860) RMAN> show all; RMAN configuration parameters are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ENCRYPTION FOR DATABASE OFF; # default CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_orcl.f'; # default RMAN> CONFIGURE CONTROLFILE AUTOBACKUP on ; new RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters are successfully stored RMAN> backup database format '/u01/oravn_backup/db_%u' plus archivelog format '/u01/oravn_backup/arc_%u'; Starting backup at 27-APR-09 current log archived allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=148 devtype=DISK channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=11 recid=1 stamp=685028724 input archive log thread=1 sequence=12 recid=2 stamp=685028773 input archive log thread=1 sequence=13 recid=3 stamp=685033763 input archive log thread=1 sequence=14 recid=4 stamp=685262679 input archive log thread=1 sequence=15 recid=5 stamp=685264476 input archive log thread=1 sequence=16 recid=6 stamp=685264476 input archive log thread=1 sequence=17 recid=7 stamp=685270847 input archive log thread=1 sequence=18 recid=8 stamp=685274682 channel ORA_DISK_1: starting piece 1 at 27-APR-09 channel ORA_DISK_1: finished piece 1 at 27-APR-09 piece handle=/u01/oravn_backup/arc_08kdgthr tag=TAG20090427T100442 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04 Finished backup at 27-APR-09 Starting backup at 27-APR-09 using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 27-APR-09 channel ORA_DISK_1: finished piece 1 at 27-APR-09 piece handle=/u01/oravn_backup/db_09kdgti0 tag=TAG20090427T100447 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55 Finished backup at 27-APR-09 Starting backup at 27-APR-09 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=19 recid=9 stamp=685274743 channel ORA_DISK_1: starting piece 1 at 27-APR-09 channel ORA_DISK_1: finished piece 1 at 27-APR-09 piece handle=/u01/oravn_backup/arc_0akdgtjn tag=TAG20090427T100543 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 27-APR-09 Starting Control File and SPFILE Autobackup at 27-APR-09 piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2009_04_27/o1_mf_s_685274746_4zb8 8bx3_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 27-APR-09 RMAN> RMAN> list backup ; List of Backup Sets =================== BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ --------------8 24.43M DISK 00:00:02 27-APR-09 BP Key: 8 Status: AVAILABLE Compressed: NO Tag: TAG20090427T100442 Piece Name: /u01/oravn_backup/arc_08kdgthr List of Archived Logs in backup set 8 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- --------- ---------- --------1 11 474684 24-APR-09 478439 24-APR-09 1 12 478439 24-APR-09 478462 24-APR-09 1 13 478462 24-APR-09 498555 24-APR-09 1 14 498555 24-APR-09 522289 27-APR-09 1 15 522289 27-APR-09 532775 27-APR-09 1 16 532775 27-APR-09 532833 27-APR-09 1 17 532833 27-APR-09 535826 27-APR-09 1 18 535826 27-APR-09 537654 27-APR-09 BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------9 Full 570.48M DISK 00:00:47 27-APR-09 BP Key: 9 Status: AVAILABLE Compressed: NO Tag: TAG20090427T100447 Piece Name: /u01/oravn_backup/db_09kdgti0 List of Datafiles in backup set 9 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---1 Full 537660 27-APR-09 /u01/app/oracle/oradata/orcl/system01.dbf 2 Full 537660 27-APR-09 /u01/app/oracle/oradata/orcl/undotbs01.dbf 3 Full 537660 27-APR-09 /u01/app/oracle/oradata/orcl/sysaux01.dbf 4 Full 537660 27-APR-09 /u01/app/oracle/oradata/orcl/users01.dbf 5 Full 537660 27-APR-09 /u01/app/oracle/oradata/orcl/example01.dbf BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ --------------10 6.50K DISK 00:00:01 27-APR-09 BP Key: 10 Status: AVAILABLE Compressed: NO Tag: TAG20090427T100543 Piece Name: /u01/oravn_backup/arc_0akdgtjn List of Archived Logs in backup set 10 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- --------- ---------- --------1 19 537654 27-APR-09 537681 27-APR-09 BS Key Type LV Size Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ --------------11 Full 6.80M DISK 00:00:01 27-APR-09 BP Key: 11 Status: AVAILABLE Compressed: NO Tag: TAG20090427T100546 Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2009_04_27/o1_mf_s_685274746_4zb88bx3_.bkp Control File Included: Ckp SCN: 537687 Ckp time: 27-APR-09 SPFILE Included: Modification time: 27-APR-09 RMAN> RMAN> exit Recovery Manager complete. [oracle@labs oravn_backup]$ [oracle@labs oravn_backup]$ ls -lh total 596M -rw-r----- 1 oracle dba 25M Apr 27 10:04 arc_08kdgthr -rw-r----- 1 oracle dba 7.0K Apr 27 10:05 arc_0akdgtjn -rw-r----- 1 oracle dba 571M Apr 27 10:05 db_09kdgti0 -rw-r--r-- 1 oracle dba 1.1K Apr 27 09:49 initoravn.ora [oracle@labs oravn_backup]$

7. Chy lnh Duplicate.


Sau khi xong cc bc chun b, gi chng ta c th Duplicate c DB ri. - Duplicate, chng ta cn: + connect vo DB ngun ang OPEN ( MOUNT cng oki). + connect vo DB nhn bn (auxiliary) ang NOMOUNT.
[oracle@labs oravn_backup]$ export ORACLE_SID=oravn [oracle@labs oravn_backup]$ rman Recovery Manager: Release 10.2.0.1.0 - Production on Mon Apr 27 10:25:08 2009 Copyright (c) 1982, 2005, Oracle. All rights reserved. RMAN> connect target sys/oracle@orcl connected to target database: ORCL (DBID=1212807860) RMAN> connect auxiliary / ; connected to auxiliary database: ORAVN (not mounted) RMAN>

- Gi chy lnh DUPLICATE c ri !

RMAN> run { 2> ALLOCATE AUXILIARY CHANNEL oravn DEVICE TYPE DISK ; 3> DUPLICATE TARGET DATABASE to oravn; 4> } using target database control file instead of recovery catalog allocated channel: oravn channel oravn: sid=156 devtype=DISK Starting Duplicate Db at 27-APR-09 contents of Memory Script: { set until scn 537681; set newname for datafile 1 to "/u01/app/oracle/oradata/oravn/system01.dbf"; set newname for datafile 2 to "/u01/app/oracle/oradata/oravn/undotbs01.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/oravn/sysaux01.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/oravn/users01.dbf"; set newname for datafile 5 to "/u01/app/oracle/oradata/oravn/example01.dbf"; restore check readonly clone database } executing Memory Script executing command: SET until clause executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting restore at 27-APR-09 channel oravn: starting datafile backupset restore channel oravn: specifying datafile(s) to restore from backup set restoring datafile 00001 to /u01/app/oracle/oradata/oravn/system01.dbf

restoring datafile 00002 to /u01/app/oracle/oradata/oravn/undotbs01.dbf restoring datafile 00003 to /u01/app/oracle/oradata/oravn/sysaux01.dbf restoring datafile 00004 to /u01/app/oracle/oradata/oravn/users01.dbf restoring datafile 00005 to /u01/app/oracle/oradata/oravn/example01.dbf channel oravn: reading from backup piece /u01/oravn_backup/db_09kdgti0 channel oravn: restored backup piece 1 piece handle=/u01/oravn_backup/db_09kdgti0 tag=TAG20090427T100447 channel oravn: restore complete, elapsed time: 00:00:46 Finished restore at 27-APR-09 sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORAVN" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/u01/app/oracle/oradata/oravn/redo01.log' ) SIZE 5 M REUSE, GROUP 2 ( '/u01/app/oracle/oradata/oravn/redo02.log' ) SIZE 5 M REUSE, GROUP 3 ( '/u01/app/oracle/oradata/oravn/redo03.log' ) SIZE 5 M REUSE DATAFILE '/u01/app/oracle/oradata/oravn/system01.dbf' CHARACTER SET WE8ISO8859P1 contents of Memory Script: { switch clone datafile all; } executing Memory Script datafile 2 switched to datafile copy input datafile copy recid=1 stamp=685276005 filename=/u01/app/oracle/oradata/oravn/undotbs01.dbf datafile 3 switched to datafile copy input datafile copy recid=2 stamp=685276005 filename=/u01/app/oracle/oradata/oravn/sysaux01.dbf datafile 4 switched to datafile copy input datafile copy recid=3 stamp=685276005 filename=/u01/app/oracle/oradata/oravn/users01.dbf datafile 5 switched to datafile copy input datafile copy recid=4 stamp=685276005 filename=/u01/app/oracle/oradata/oravn/example01.dbf contents of Memory Script: { set until scn 537681; recover clone database delete archivelog } executing Memory Script executing command: SET until clause Starting recover at 27-APR-09 starting media recovery archive log thread 1 sequence 19 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_04_27/o1_mf_1_19_4zb887kf_.arc archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_04_27/o1_mf_1_19_4zb887kf_ .arc thread=1 sequence=19 media recovery complete, elapsed time: 00:00:02 Finished recover at 27-APR-09 contents of Memory Script: { shutdown clone; startup clone nomount ; } executing Memory Script database dismounted Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 285212672 bytes Fixed Size 1218992 bytes Variable Size 92276304 bytes Database Buffers 188743680 bytes

Redo Buffers 2973696 bytes sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORAVN" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/u01/app/oracle/oradata/oravn/redo01.log' ) SIZE 5 M REUSE, GROUP 2 ( '/u01/app/oracle/oradata/oravn/redo02.log' ) SIZE 5 M REUSE, GROUP 3 ( '/u01/app/oracle/oradata/oravn/redo03.log' ) SIZE 5 M REUSE DATAFILE '/u01/app/oracle/oradata/oravn/system01.dbf' CHARACTER SET WE8ISO8859P1 contents of Memory Script: { set newname for tempfile 1 to "/u01/app/oracle/oradata/oravn/temp01.dbf"; switch clone tempfile all; catalog clone datafilecopy "/u01/app/oracle/oradata/oravn/undotbs01.dbf"; catalog clone datafilecopy "/u01/app/oracle/oradata/oravn/sysaux01.dbf"; catalog clone datafilecopy "/u01/app/oracle/oradata/oravn/users01.dbf"; catalog clone datafilecopy "/u01/app/oracle/oradata/oravn/example01.dbf"; switch clone datafile all; } executing Memory Script executing command: SET NEWNAME renamed temporary file 1 to /u01/app/oracle/oradata/oravn/temp01.dbf in control file cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/oravn/undotbs01.dbf recid=1 stamp=685276020 cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/oravn/sysaux01.dbf recid=2 stamp=685276020 cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/oravn/users01.dbf recid=3 stamp=685276021 cataloged datafile copy datafile copy filename=/u01/app/oracle/oradata/oravn/example01.dbf recid=4 stamp=685276021 datafile 2 switched to datafile copy input datafile copy recid=1 stamp=685276020 filename=/u01/app/oracle/oradata/oravn/undotbs01.dbf datafile 3 switched to datafile copy input datafile copy recid=2 stamp=685276020 filename=/u01/app/oracle/oradata/oravn/sysaux01.dbf datafile 4 switched to datafile copy input datafile copy recid=3 stamp=685276021 filename=/u01/app/oracle/oradata/oravn/users01.dbf datafile 5 switched to datafile copy input datafile copy recid=4 stamp=685276021 filename=/u01/app/oracle/oradata/oravn/example01.dbf contents of Memory Script: { Alter clone database open resetlogs; } executing Memory Script database opened Finished Duplicate Db at 27-APR-09 RMAN> exit Recovery Manager complete. [oracle@labs oravn_backup]$

- Gi n lc xem li kt qu Clone DB.

[oracle@labs oravn_backup]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 27 10:27:57 2009 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining options SQL> select name from v$database ; NAME --------ORAVN SQL> select count(*) from hr.employees ; COUNT(*)

---------107 SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining options [oracle@labs _backup]$

Nh vy chng ta DUPLICATE c orcl sang DB mi l oravn.

You might also like