部分文档,摘取出来了,如下:
Purpose of Database Duplication
A duplicate database is useful for a variety of purposes, most of which involve testing. You can perform the following tasks in a duplicate database:
-
Test backup and recovery procedures
-
Test an upgrade to a new release of Oracle Database
-
Test the effect of applications on database performance
-
Create a standby database
-
Generate reports
For example, you can duplicate the production database on host1 to host2, and then use the duplicate database on host2 to practice restoring and recovering this database while the production database on host1 operates as usual.
自己在虚拟机上试了一下。
环境介绍
操作系统:点击(此处)折叠或打开
- [root@wbg2 ~]# lsb_release -a
- LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
- Distributor ID: RedHatEnterpriseServer
- Description: Red Hat Enterprise Linux Server release 6.6 (Santiago)
- Release: 6.6
- Codename: Santiago
点击(此处)折叠或打开
- [root@wbg2 ~]# cat /etc/hosts
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 1.1.1.1 wbg1
- 1.1.1.2 wbg2
操作过程
点击(此处)折叠或打开
- primary=
- (DESCRIPTION=
- (ADDRESS=(PROTOCOL=tcp)(HOST=wbg1)(PORT=1521))
- (CONNECT_DATA=(SERVICE_NAME=wbg)))
- standby=
- (DESCRIPTION=
- (ADDRESS=(PROTOCOL=tcp)(HOST=wbg2)(PORT=1521))
- (CONNECT_DATA=(SERVICE_NAME=standby)))
备库的口令文件,要从主库拷贝
备库要写一个pfile,只要指定一个db_name就可以了
点击(此处)折叠或打开
- LISTENER=
- (DESCRIPTION=
- (ADDRESS_LIST=
- (ADDRESS=(PROTOCOL=tcp)(HOST=wbg2)(PORT=1521))
- (ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
- SID_LIST_LISTENER=
- (SID_LIST=
- (SID_DESC=
- (GLOBAL_DBNAME=standby)
- (ORACLE_HOME=/u01/oracle)
- (SID_NAME=standby))
- )
点击(此处)折叠或打开
- alter system set log_archive_config='DG_CONFIG=(wbg,standby)';
- alter system set LOG_ARCHIVE_DEST_1='LOCATION=/u01/arch/wbg/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=wbg';
- alter system set LOG_ARCHIVE_DEST_2='SERVICE=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby';
- alter system set FAL_SERVER=standby;
- alter system set STANDBY_FILE_MANAGEMENT=AUTO;
- alter system set DB_FILE_NAME_CONVERT='/u01/data/standby/','/u01/data/wbg/' scope=spfile;
- alter system set LOG_FILE_NAME_CONVERT='/u01/data/standby/','/u01/data/wbg/' scope=spfile;
- ALTER DATABASE ADD STANDBY LOGFILE '/u01/data/wbg/std01.log' size 50m;
- ALTER DATABASE ADD STANDBY LOGFILE '/u01/data/wbg/std02.log' size 50m;
- ALTER DATABASE ADD STANDBY LOGFILE '/u01/data/wbg/std03.log' size 50m;
- ALTER DATABASE ADD STANDBY LOGFILE '/u01/data/wbg/std04.log' size 50m;
点击(此处)折叠或打开
- rman target / auxiliary sys/oracle@1.1.1.2:1521/standby
点击(此处)折叠或打开
- DUPLICATE TARGET DATABASE
- FOR STANDBY
- FROM ACTIVE DATABASE
- DORECOVER
- SPFILE
- SET db_unique_name 'standby'
- SET control_files '/u01/data/standby/ctl1.ctl'
- SET db_file_name_convert '/u01/data/wbg/','/u01/data/standby/'
- SET fal_server 'primary'
- SET log_archive_config 'DG_CONFIG=(wbg,standby)'
- SET log_archive_dest_1 'LOCATION=/u01/arch/standby/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
- SET log_archive_dest_2 'SERVICE=primary ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
- SET log_file_name_convert '/u01/data/wbg/','/u01/data/standby/'
- SET remote_login_passwordfile 'EXCLUSIVE'
- SET standby_file_management 'AUTO'
- ;
点击(此处)折叠或打开
- Archived Log entry 5 added for thread 1 sequence 14 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 5 for thread 1 sequence 15 dbid -874449071 branch 887556119
- Mon Nov 30 17:10:00 2015
- Archived Log entry 6 added for thread 1 sequence 15 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 16 dbid -874449071 branch 887556119
- Mon Nov 30 17:10:02 2015
- Archived Log entry 7 added for thread 1 sequence 16 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 18 dbid -874449071 branch 887556119
- Mon Nov 30 17:10:03 2015
- RFS[3]: Assigned to RFS process 3638
- RFS[3]: Selected log 5 for thread 1 sequence 17 dbid -874449071 branch 887556119
- Archived Log entry 8 added for thread 1 sequence 17 ID 0xcbe1a451 dest 1:
- Archived Log entry 9 added for thread 1 sequence 18 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 19 dbid -874449071 branch 887556119
- Archived Log entry 10 added for thread 1 sequence 19 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 20 dbid -874449071 branch 887556119
- Archived Log entry 11 added for thread 1 sequence 20 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 21 dbid -874449071 branch 887556119
- Archived Log entry 12 added for thread 1 sequence 21 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 22 dbid -874449071 branch 887556119
- Archived Log entry 13 added for thread 1 sequence 22 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 23 dbid -874449071 branch 887556119
- Archived Log entry 14 added for thread 1 sequence 23 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 24 dbid -874449071 branch 887556119
- Archived Log entry 15 added for thread 1 sequence 24 ID 0xcbe1a451 dest 1:
- RFS[1]: Selected log 4 for thread 1 sequence 25 dbid -874449071 branch 887556119
DUPLICATE的过程
点击(此处)折叠或打开
- [oracle@wbg1 admin]$ rman target / auxiliary sys/oracle@1.1.1.2:1521/standby
- Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 30 16:46:41 2015
- Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
- connected to target database: WBG (DBID=3420518225)
- connected to auxiliary database: WBG (not mounted)
- RMAN> DUPLICATE TARGET DATABASE
- 2> FOR STANDBY
- 3> FROM ACTIVE DATABASE
- 4> DORECOVER
- 5> SPFILE
- 6> SET db_unique_name 'standby'
- 7> SET control_files '/u01/data/standby/ctl1.ctl'
- 8> SET db_file_name_convert '/u01/data/wbg/','/u01/data/standby/'
- 9> SET fal_server 'primary'
- 10> SET log_archive_config 'DG_CONFIG=(wbg,standby)'
- 11> SET log_archive_dest_1 'LOCATION=/u01/arch/standby/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
- 12> SET log_archive_dest_2 'SERVICE=primary ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
- 13> SET log_file_name_convert '/u01/data/wbg/','/u01/data/standby/'
- 14> SET remote_login_passwordfile 'EXCLUSIVE'
- 15> SET standby_file_management 'AUTO'
- 16> ;
- Starting Duplicate Db at 30-NOV-15
- using target database control file instead of recovery catalog
- allocated channel: ORA_AUX_DISK_1
- channel ORA_AUX_DISK_1: SID=20 device type=DISK
- contents of Memory Script:
- {
- backup as copy reuse
- targetfile '/u01/oracle/dbs/orapwwbg' auxiliary format
- '/u01/oracle/dbs/orapwstandby' targetfile
- '/u01/oracle/dbs/spfilewbg.ora' auxiliary format
- '/u01/oracle/dbs/spfilestandby.ora' ;
- sql clone "alter system set spfile= ''/u01/oracle/dbs/spfilestandby.ora''";
- }
- executing Memory Script
- Starting backup at 30-NOV-15
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=40 device type=DISK
- Finished backup at 30-NOV-15
- sql statement: alter system set spfile= ''/u01/oracle/dbs/spfilestandby.ora''
- contents of Memory Script:
- {
- sql clone "alter system set db_unique_name =
- ''standby'' comment=
- '''' scope=spfile";
- sql clone "alter system set control_files =
- ''/u01/data/standby/ctl1.ctl'' comment=
- '''' scope=spfile";
- sql clone "alter system set db_file_name_convert =
- ''/u01/data/wbg/'', ''/u01/data/standby/'' comment=
- '''' scope=spfile";
- sql clone "alter system set fal_server =
- ''primary'' comment=
- '''' scope=spfile";
- sql clone "alter system set log_archive_config =
- ''DG_CONFIG=(wbg,standby)'' comment=
- '''' scope=spfile";
- sql clone "alter system set log_archive_dest_1 =
- ''LOCATION=/u01/arch/standby/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'' comment=
- '''' scope=spfile";
- sql clone "alter system set log_archive_dest_2 =
- ''SERVICE=primary ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'' comment=
- '''' scope=spfile";
- sql clone "alter system set log_file_name_convert =
- ''/u01/data/wbg/'', ''/u01/data/standby/'' comment=
- '''' scope=spfile";
- sql clone "alter system set remote_login_passwordfile =
- ''EXCLUSIVE'' comment=
- '''' scope=spfile";
- sql clone "alter system set standby_file_management =
- ''AUTO'' comment=
- '''' scope=spfile";
- shutdown clone immediate;
- startup clone nomount;
- }
- executing Memory Script
- sql statement: alter system set db_unique_name = ''standby'' comment= '''' scope=spfile
- sql statement: alter system set control_files = ''/u01/data/standby/ctl1.ctl'' comment= '''' scope=spfile
- sql statement: alter system set db_file_name_convert = ''/u01/data/wbg/'', ''/u01/data/standby/'' comment= '''' scope=spfile
- sql statement: alter system set fal_server = ''primary'' comment= '''' scope=spfile
- sql statement: alter system set log_archive_config = ''DG_CONFIG=(wbg,standby)'' comment= '''' scope=spfile
- sql statement: alter system set log_archive_dest_1 = ''LOCATION=/u01/arch/standby/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'' comment= '''' scope=spfile
- sql statement: alter system set log_archive_dest_2 = ''SERVICE=primary ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'' comment= '''' scope=spfile
- sql statement: alter system set log_file_name_convert = ''/u01/data/wbg/'', ''/u01/data/standby/'' comment= '''' scope=spfile
- sql statement: alter system set remote_login_passwordfile = ''EXCLUSIVE'' comment= '''' scope=spfile
- sql statement: alter system set standby_file_management = ''AUTO'' comment= '''' scope=spfile
- Oracle instance shut down
- connected to auxiliary database (not started)
- Oracle instance started
- Total System Global Area 626327552 bytes
- Fixed Size 2255832 bytes
- Variable Size 423625768 bytes
- Database Buffers 197132288 bytes
- Redo Buffers 3313664 bytes
- contents of Memory Script:
- {
- backup as copy current controlfile for standby auxiliary format '/u01/data/standby/ctl1.ctl';
- }
- executing Memory Script
- Starting backup at 30-NOV-15
- using channel ORA_DISK_1
- channel ORA_DISK_1: starting datafile copy
- copying standby control file
- output file name=/u01/oracle/dbs/snapcf_wbg.f tag=TAG20151130T164651 RECID=2 STAMP=897151611
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
- Finished backup at 30-NOV-15
- contents of Memory Script:
- {
- sql clone 'alter database mount standby database';
- }
- executing Memory Script
- sql statement: alter database mount standby database
- contents of Memory Script:
- {
- set newname for tempfile 1 to
- "/u01/data/standby/temp01.dbf";
- switch clone tempfile all;
- set newname for datafile 1 to
- "/u01/data/standby/system01.dbf";
- set newname for datafile 2 to
- "/u01/data/standby/sysaux01.dbf";
- set newname for datafile 3 to
- "/u01/data/standby/undotbs01.dbf";
- set newname for datafile 4 to
- "/u01/data/standby/users01.dbf";
- set newname for datafile 5 to
- "/u01/data/standby/example01.dbf";
- backup as copy reuse
- datafile 1 auxiliary format
- "/u01/data/standby/system01.dbf" datafile
- 2 auxiliary format
- "/u01/data/standby/sysaux01.dbf" datafile
- 3 auxiliary format
- "/u01/data/standby/undotbs01.dbf" datafile
- 4 auxiliary format
- "/u01/data/standby/users01.dbf" datafile
- 5 auxiliary format
- "/u01/data/standby/example01.dbf" ;
- sql 'alter system archive log current';
- }
- executing Memory Script
- executing command: SET NEWNAME
- renamed tempfile 1 to /u01/data/standby/temp01.dbf in control file
- executing command: SET NEWNAME
- executing command: SET NEWNAME
- executing command: SET NEWNAME
- executing command: SET NEWNAME
- executing command: SET NEWNAME
- Starting backup at 30-NOV-15
- using channel ORA_DISK_1
- channel ORA_DISK_1: starting datafile copy
- input datafile file number=00001 name=/u01/data/wbg/system01.dbf
- output file name=/u01/data/standby/system01.dbf tag=TAG20151130T164658
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
- channel ORA_DISK_1: starting datafile copy
- input datafile file number=00002 name=/u01/data/wbg/sysaux01.dbf
- output file name=/u01/data/standby/sysaux01.dbf tag=TAG20151130T164658
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
- channel ORA_DISK_1: starting datafile copy
- input datafile file number=00005 name=/u01/data/wbg/example01.dbf
- output file name=/u01/data/standby/example01.dbf tag=TAG20151130T164658
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
- channel ORA_DISK_1: starting datafile copy
- input datafile file number=00003 name=/u01/data/wbg/undotbs01.dbf
- output file name=/u01/data/standby/undotbs01.dbf tag=TAG20151130T164658
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
- channel ORA_DISK_1: starting datafile copy
- input datafile file number=00004 name=/u01/data/wbg/users01.dbf
- output file name=/u01/data/standby/users01.dbf tag=TAG20151130T164658
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
- Finished backup at 30-NOV-15
- sql statement: alter system archive log current
- contents of Memory Script:
- {
- backup as copy reuse
- archivelog like "/u01/arch/wbg/1_10_887556119.dbf" auxiliary format
- "/u01/arch/standby/1_10_887556119.dbf" archivelog like
- "/u01/arch/wbg/1_11_887556119.dbf" auxiliary format
- "/u01/arch/standby/1_11_887556119.dbf" ;
- catalog clone archivelog "/u01/arch/standby/1_10_887556119.dbf";
- catalog clone archivelog "/u01/arch/standby/1_11_887556119.dbf";
- switch clone datafile all;
- }
- executing Memory Script
- Starting backup at 30-NOV-15
- using channel ORA_DISK_1
- channel ORA_DISK_1: starting archived log copy
- input archived log thread=1 sequence=10 RECID=5 STAMP=897151623
- output file name=/u01/arch/standby/1_10_887556119.dbf RECID=0 STAMP=0
- channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
- channel ORA_DISK_1: starting archived log copy
- input archived log thread=1 sequence=11 RECID=6 STAMP=897151688
- output file name=/u01/arch/standby/1_11_887556119.dbf RECID=0 STAMP=0
- channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
- Finished backup at 30-NOV-15
- cataloged archived log
- archived log file name=/u01/arch/standby/1_10_887556119.dbf RECID=1 STAMP=897151692
- cataloged archived log
- archived log file name=/u01/arch/standby/1_11_887556119.dbf RECID=2 STAMP=897151692
- datafile 1 switched to datafile copy
- input datafile copy RECID=2 STAMP=897151692 file name=/u01/data/standby/system01.dbf
- datafile 2 switched to datafile copy
- input datafile copy RECID=3 STAMP=897151692 file name=/u01/data/standby/sysaux01.dbf
- datafile 3 switched to datafile copy
- input datafile copy RECID=4 STAMP=897151692 file name=/u01/data/standby/undotbs01.dbf
- datafile 4 switched to datafile copy
- input datafile copy RECID=5 STAMP=897151692 file name=/u01/data/standby/users01.dbf
- datafile 5 switched to datafile copy
- input datafile copy RECID=6 STAMP=897151692 file name=/u01/data/standby/example01.dbf
- contents of Memory Script:
- {
- set until scn 1021784;
- recover
- standby
- clone database
- delete archivelog
- ;
- }
- executing Memory Script
- executing command: SET until clause
- Starting recover at 30-NOV-15
- allocated channel: ORA_AUX_DISK_1
- channel ORA_AUX_DISK_1: SID=18 device type=DISK
- starting media recovery
- archived log for thread 1 with sequence 10 is already on disk as file /u01/arch/standby/1_10_887556119.dbf
- archived log for thread 1 with sequence 11 is already on disk as file /u01/arch/standby/1_11_887556119.dbf
- archived log file name=/u01/arch/standby/1_10_887556119.dbf thread=1 sequence=10
- archived log file name=/u01/arch/standby/1_11_887556119.dbf thread=1 sequence=11
- media recovery complete, elapsed time: 00:00:00
- Finished recover at 30-NOV-15
- Finished Duplicate Db at 30-NOV-15
- RMAN>
这种方法,创建过程比较炫酷,但是中间不能有错误,要一气呵成。
娱乐一下还可以,少用。
额。。。赓赓。。。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30202921/viewspace-1849928/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30202921/viewspace-1849928/