Professional Documents
Culture Documents
Duplicate DB
Duplicate DB
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/
[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>
- 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
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.
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 ~]$
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]$
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]$
[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]$