基于 RMAN 的同机数据库克隆
时间:2021-07-01 10:21:17
帮助过:2人阅读
print?
-
- [oracle@linux3 database]$ cat /etc/issue
- Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
- Kernel \r on an \m
-
- SQL> select * from v$version where rownum<2;
-
- BANNER
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
-
-
- a、备份目标数据库
- SQL> insert into t select ‘Jackson‘,‘Transfer DB by rman‘ from dual;
-
- SQL> commit;
-
- SQL> select * from t;
-
- NAME ACTION
- Robinson Transfer DB
- Jackson Transfer DB by rman
-
- SQL> alter system archive log current;
-
- [oracle@linux3 ~]$ rman target /
-
- Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jul 25 08:39:42 2013
-
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
-
- connected to target database: SYBO3 (DBID=2347733014)
-
- RMAN> backup database include current controlfile plus archivelog delete input;
-
- piece handle=/u01/database/sybo3/flash_recovery_area/SYBO3/backupset/2013_07_25/o1_mf_annnn_TAG20130725T083957_8z0wyy9n_.bkp
- tag=TAG20130725T083957 comment=NONE
- channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
-
- piece handle=/u01/database/sybo3/flash_recovery_area/SYBO3/backupset/2013_07_25/o1_mf_nnndf_TAG20130725T083959_8z0wz06c_.bkp
- tag=TAG20130725T083959 comment=NONE
- channel ORA_DISK_1: backup set complete, elapsed time: 00:01:30
- Finished backup at 2013/07/25 08:41:29
-
- Starting Control File and SPFILE Autobackup at 2013/07/25 08:41:31
- piece handle=/u01/database/sybo3/flash_recovery_area/SYBO3/autobackup/2013_07_25/o1_mf_s_821695291_8z0x1vsf_.bkp comment=NONE
- Finished Control File and SPFILE Autobackup at 2013/07/25 08:41:34
-
-
- b、创建相应的dump文件夹
- [oracle@linux3 database]$ more sybo5.sh
- #!/bin/sh
- mkdir -p /u01/database
- mkdir -p /u01/database/sybo5/adump
- mkdir -p /u01/database/sybo5/controlf
- mkdir -p /u01/database/sybo5/flash_recovery_area
- mkdir -p /u01/database/sybo5/oradata
- mkdir -p /u01/database/sybo5/redo
- mkdir -p /u01/database/sybo5/dpdump
- mkdir -p /u01/database/sybo5/pfile
- [oracle@linux3 database]$ ./sybo5.sh
-
-
- c、配置辅助实例参数文件
- SQL> create pfile=‘/u01/oracle/db_1/dbs/initsybo5.ora‘ from spfile;
-
- $ sed -i ‘s/sybo3/sybo5/g‘ $ORACLE_HOME/dbs/initsybo5.ora
- $ grep sybo3 $ORACLE_HOME/dbs/initsybo5.ora
-
- [oracle@linux3 database]$ more $ORACLE_HOME/dbs/initsybo5.ora
- sybo5.__db_cache_size=113246208
- sybo5.__java_pool_size=4194304
- sybo5.__large_pool_size=4194304
- sybo5.__oracle_base=‘/u01/oracle‘#ORACLE_BASE set from environment
- sybo5.__pga_aggregate_target=142606336
- sybo5.__sga_target=234881024
- sybo5.__shared_io_pool_size=0
- sybo5.__shared_pool_size=104857600
- sybo5.__streams_pool_size=0
- *.audit_file_dest=‘/u01/database/sybo5/adump/‘
- *.audit_trail=‘db‘
- *.compatible=‘11.2.0.0.0‘
- *.control_files=‘/u01/database/sybo5/controlf/control01.ctl‘,‘/u01/database/sybo5/controlf/control02.ctl‘
- *.db_block_size=8192
- *.db_domain=‘orasrv.com‘
- *.db_name=‘sybo5‘
- *.db_recovery_file_dest=‘/u01/database/sybo5/flash_recovery_area/‘
- *.db_recovery_file_dest_size=4039114752
- *.dg_broker_config_file1=‘/u01/database/sybo5/db_broker/dr1sybo5.dat‘
- *.dg_broker_config_file2=‘/u01/database/sybo5/db_broker/dr2sybo5.dat‘
- *.dg_broker_start=FALSE
- *.diagnostic_dest=‘/u01/database/sybo5‘
- *.log_archive_dest_1=‘‘ #此处未指定archive位置,使用缺省的闪回区
- *.memory_target=374341632
- *.open_cursors=300
- *.processes=150
- *.remote_login_passwordfile=‘EXCLUSIVE‘
- *.undo_tablespace=‘UNDOTBS1‘
-
-
- d、生成辅助实例密码文件
- $ orapwd file=$ORACLE_HOME/dbs/orapwsybo5 password=oracle entries=10
-
-
- e、配置辅助实例监听
- [oracle@linux3 ~]$ more $ORACLE_HOME/network/admin/listener.ora
- # listener.ora Network Configuration File: /u01/oracle/db_1/network/admin/listener.ora
- # Generated by Oracle configuration tools.
-
- SID_LIST_LISTENER_SYBO5 =
- (SID_LIST =
- (SID_DESC =
- (GLOBAL_DBNAME = sybo5.orasrv.com)
- (ORACLE_HOME = /u01/oracle/db_1)
- (SID_NAME = sybo5)
- )
- )
-
- SID_LIST_LISTENER_SYBO3 =
- (SID_LIST =
- (SID_DESC =
- (GLOBAL_DBNAME = sybo3.orasrv.com)
- (ORACLE_HOME = /u01/oracle/db_1)
- (SID_NAME = sybo3)
- )
- )
-
- LISTENER_SYBO5 =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = linux3.orasrv.com)(PORT = 1532))
- )
-
- ADR_BASE_LISTENER_SYBO5 = /u01/oracle
-
- LISTENER_SYBO3 =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = linux3.orasrv.com)(PORT = 1531))
- )
-
- ADR_BASE_LISTENER_SYBO3 = /u01/oracle
-
- [oracle@linux3 ~]$ more $ORACLE_HOME/network/admin/tnsnames.ora
- # tnsnames.ora Network Configuration File: /u01/oracle/db_1/network/admin/tnsnames.ora
- # Generated by Oracle configuration tools.
-
- SYBO5 =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.25)(PORT = 1532))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = SYBO5.ORASRV.COM)
- )
- )
-
- SYBO3 =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.25)(PORT = 1531))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = SYBO3.ORASRV.COM)
- )
- )
-
-
- f、实施数据库克隆
- [oracle@linux3 ~]$ export ORACLE_SID=sybo5
- [oracle@linux3 ~]$ sqlplus / as sysdba
- SQL> startup nomount pfile=/u01/oracle/db_1/dbs/initsybo5.ora;
- ORACLE instance started.
-
- [oracle@linux3 ~]$ rman target sys/oracle@sybo3 auxiliary sys/oracle@sybo5
-
- Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jul 25 14:32:51 2013
-
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
-
- connected to target database: SYBO3 (DBID=2347733014)
- connected to auxiliary database: SYBO5 (not mounted)
-
- RMAN> run{
- 2> set newname for datafile 1 to ‘/u01/database/sybo5/oradata/system01.dbf‘;
- 3> set newname for datafile 2 to ‘/u01/database/sybo5/oradata/sysaux01.dbf‘;
- 4> set newname for datafile 3 to ‘/u01/database/sybo5/oradata/undotbs01.dbf‘;
- 5> set newname for datafile 4 to ‘/u01/database/sybo5/oradata/users01.dbf‘;
- 6> set newname for datafile 5 to ‘/u01/database/sybo5/oradata/example01.dbf‘;
- 7> set newname for tempfile 1 to ‘/u01/database/sybo5/oradata/temp01.dbf‘;
- 8> duplicate target database to sybo5
- 9> logfile
- 10> group 1 (‘/u01/database/sybo5/redo/redo01a.log‘,‘/u01/database/sybo5/redo/redo01b.log‘) size 10m,
- 11> group 2 (‘/u01/database/sybo5/redo/redo02a.log‘,‘/u01/database/sybo5/redo/redo02b.log‘) size 10m,
- 12> group 3 (‘/u01/database/sybo5/redo/redo03a.log‘,‘/u01/database/sybo5/redo/redo03b.log‘) size 10m;
- 13> switch datafile all;
- 14> }
-
- executing command: SET NEWNAME
-
- executing command: SET NEWNAME
-
- executing command: SET NEWNAME
-
- executing command: SET NEWNAME
-
- executing command: SET NEWNAME
-
- executing command: SET NEWNAME
-
- Starting Duplicate Db at 2013/07/25 14:33:14
- using target database control file instead of recovery catalog
- allocated channel: ORA_AUX_DISK_1
- channel ORA_AUX_DISK_1: SID=134 device type=DISK
-
- contents of Memory Script:
- {
- sql clone "create spfile from memory";
- }
- executing Memory Script
-
- sql statement: create spfile from memory
-
- contents of Memory Script:
- {
- shutdown clone immediate;
- startup clone nomount;
- }
- executing Memory Script
-
- Oracle instance shut down
-
- connected to auxiliary database (not started)
- Oracle instance started
-
- Total System Global Area 376635392 bytes
-
- Fixed Size 1336652 bytes
- Variable Size 260049588 bytes
- Database Buffers 109051904 bytes
- Redo Buffers 6197248 bytes
-
- contents of Memory Script:
- {
- sql clone "alter system set db_name =
- ‘‘SYBO3‘‘ comment=
- ‘‘Modified by RMAN duplicate‘‘ scope=spfile";
- sql clone "alter system set db_unique_name =
- ‘‘SYBO5‘‘ comment=
- ‘‘Modified by RMAN duplicate‘‘ scope=spfile";
- shutdown clone immediate;
- startup clone force nomount
- restore clone primary controlfile;
- alter clone database mount;
- }
- executing Memory Script
-
- sql statement: alter system set db_name = ‘‘SYBO3‘‘ comment= ‘‘Modified by RMAN duplicate‘‘ scope=spfile
-
- sql statement: alter system set db_unique_name = ‘‘SYBO5‘‘ comment= ‘‘Modified by RMAN duplicate‘‘ scope=spfile
-
- Oracle instance shut down
-
- Oracle instance started
-
- Total System Global Area 376635392 bytes
-
- Fixed Size 1336652 bytes
- Variable Size 260049588 bytes
- Database Buffers 109051904 bytes
- Redo Buffers 6197248 bytes
-
- Starting restore at 2013/07/25 14:33:29
- allocated channel: ORA_AUX_DISK_1
- channel ORA_AUX_DISK_1: SID=134 device type=DISK
-
- channel ORA_AUX_DISK_1: starting datafile backup set restore
- channel ORA_AUX_DISK_1: restoring control file
- channel ORA_AUX_DISK_1: reading from backup piece /u01/database/sybo3/flash_recovery_area/SYBO3/autobackup/2013_07_25/
- o1_mf_s_821695291_8z0x1vsf_.bkp
- channel ORA_AUX_DISK_1: piece handle=/u01/database/sybo3/flash_recovery_area/SYBO3/autobackup/2013_07_25/
- o1_mf_s_821695291_8z0x1vsf_.bkp tag=TAG20130725T084131
- channel ORA_AUX_DISK_1: restored backup piece 1
- channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
- output file name=/u01/database/sybo5/controlf/control01.ctl
- output file name=/u01/database/sybo5/controlf/control02.ctl
- Finished restore at 2013/07/25 14:33:30
-
- database mounted
-
- contents of Memory Script:
- {
- set until scn 886687;
- set newname for datafile 1 to
- "/u01/database/sybo5/oradata/system01.dbf";
- set newname for datafile 2 to
- "/u01/database/sybo5/oradata/sysaux01.dbf";
- set newname for datafile 3 to
- "/u01/database/sybo5/oradata/undotbs01.dbf";
- set newname for datafile 4 to
- "/u01/database/sybo5/oradata/users01.dbf";
- set newname for datafile 5 to
- "/u01/database/sybo5/oradata/example01.dbf";
- restore
- 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 2013/07/25 14:33:35
- using channel ORA_AUX_DISK_1
-
- channel ORA_AUX_DISK_1: starting datafile backup set restore
- channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
- channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/database/sybo5/oradata/system01.dbf
- channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/database/sybo5/oradata/sysaux01.dbf
- channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/database/sybo5/oradata/undotbs01.dbf
- channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/database/sybo5/oradata/users01.dbf
- channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/database/sybo5/oradata/example01.dbf
- channel ORA_AUX_DISK_1: reading from backup piece /u01/database/sybo3/flash_recovery_area/SYBO3/backupset/2013_07_25/
- o1_mf_nnndf_TAG20130725T083959_8z0wz06c_.bkp
- channel ORA_AUX_DISK_1: piece handle=/u01/database/sybo3/flash_recovery_area/SYBO3/backupset/2013_07_25/
- o1_mf_nnndf_TAG20130725T083959_8z0wz06c_.bkp tag=TAG20130725T083959
- channel ORA_AUX_DISK_1: restored backup piece 1
- channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15
- Finished restore at 2013/07/25 14:34:50
-
- contents of Memory Script:
- {
- switch clone datafile all;
- }
- executing Memory Script
-
- datafile 1 switched to datafile copy
- input datafile copy RECID=7 STAMP=821716490 file name=/u01/database/sybo5/oradata/system01.dbf
- datafile 2 switched to datafile copy
- input datafile copy RECID=8 STAMP=821716491 file name=/u01/database/sybo5/oradata/sysaux01.dbf
- datafile 3 switched to datafile copy
- input datafile copy RECID=9 STAMP=821716491 file name=/u01/database/sybo5/oradata/undotbs01.dbf
- datafile 4 switched to datafile copy
- input datafile copy RECID=10 STAMP=821716491 file name=/u01/database/sybo5/oradata/users01.dbf
- datafile 5 switched to datafile copy
- input datafile copy RECID=11 STAMP=821716491 file name=/u01/database/sybo5/oradata/example01.dbf
-
- contents of Memory Script:
- {
- set until scn 886687;
- recover
- clone database
- delete archivelog
- ;
- }
- executing Memory Script
-
- executing command: SET until clause
-
- Starting recover at 2013/07/25 14:34:51
- using channel ORA_AUX_DISK_1
-
- starting media recovery
-
- archived log for thread 1 with sequence 16 is already on disk as file /u01/database/sybo3/flash_recovery_area/SYBO3/
- archivelog/2013_07_25/o1_mf_1_16_8z16rk6o_.arc
- channel ORA_AUX_DISK_1: starting archived log restore to default destination
- channel ORA_AUX_DISK_1: restoring archived log
- archived log thread=1 sequence=15
- channel ORA_AUX_DISK_1: reading from backup piece /u01/database/sybo3/flash_recovery_area/SYBO3/backupset/2013_07_25/
- o1_mf_annnn_TAG20130725T084129_8z0x1syh_.bkp
- channel ORA_AUX_DISK_1: piece handle=/u01/database/sybo3/flash_recovery_area/SYBO3/backupset/2013_07_25/
- o1_mf_annnn_TAG20130725T084129_8z0x1syh_.bkp tag=TAG20130725T084129
- channel ORA_AUX_DISK_1: restored backup piece 1
- channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
- archived log file name=/u01/database/sybo5/flash_recovery_area/SYBO5/archivelog/2013_07_25/o1_mf_1_15_8z1krh5x_.arc thread=1 sequence=15
- channel clone_default: deleting archived log(s)
- archived log file name=/u01/database/sybo5/flash_recovery_area/SYBO5/archivelog/2013_07_25/o1_mf_1_15_8z1krh5x_.arc RECID=12 STAMP=821716495
- archived log file name=/u01/database/sybo3/flash_recovery_area/SYBO3/archivelog/2013_07_25/o1_mf_1_16_8z16rk6o_.arc thread=1 sequence=16
- media recovery complete, elapsed time: 00:00:04
- Finished recover at 2013/07/25 14:35:00
-
- contents of Memory Script:
- {
- shutdown clone immediate;
- startup clone nomount;
- sql clone "alter system set db_name =
- ‘‘SYBO5‘‘ comment=
- ‘‘Reset to original value by RMAN‘‘ scope=spfile";
- sql clone "alter system reset db_unique_name scope=spfile";
- shutdown clone immediate;
- 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 376635392 bytes
-
- Fixed Size 1336652 bytes
- Variable Size 260049588 bytes
- Database Buffers 109051904 bytes
- Redo Buffers 6197248 bytes
-
- sql statement: alter system set db_name = ‘‘SYBO5‘‘ comment= ‘‘Reset to original value by RMAN‘‘ scope=spfile
-
- sql statement: alter system reset db_unique_name scope=spfile
-
- Oracle instance shut down
-
- connected to auxiliary database (not started)
- Oracle instance started
-
- Total System Global Area 376635392 bytes
-
- Fixed Size 1336652 bytes
- Variable Size 260049588 bytes
- Database Buffers 109051904 bytes
- Redo Buffers 6197248 bytes
- sql statement: CREATE CONTROLFILE REUSE SET DATABASE "SYBO5" RESETLOGS ARCHIVELOG
- MAXLOGFILES 16
- MAXLOGMEMBERS 3
- MAXDATAFILES 100
- MAXINSTANCES 8
- MAXLOGHISTORY 292
- LOGFILE
- GROUP 1 ( ‘/u01/database/sybo5/redo/redo01a.log‘, ‘/u01/database/sybo5/redo/redo01b.log‘ ) SIZE 10 M ,
- GROUP 2 ( ‘/u01/database/sybo5/redo/redo02a.log‘, ‘/u01/database/sybo5/redo/redo02b.log‘ ) SIZE 10 M ,
- GROUP 3 ( ‘/u01/database/sybo5/redo/redo03a.log‘, ‘/u01/database/sybo5/redo/redo03b.log‘ ) SIZE 10 M
- DATAFILE
- ‘/u01/database/sybo5/oradata/system01.dbf‘
- CHARACTER SET AL32UTF8
-
- contents of Memory Script:
- {
- set newname for tempfile 1 to
- "/u01/database/sybo5/oradata/temp01.dbf";
- switch clone tempfile all;
- catalog clone datafilecopy "/u01/database/sybo5/oradata/sysaux01.dbf",
- "/u01/database/sybo5/oradata/undotbs01.dbf",
- "/u01/database/sybo5/oradata/users01.dbf",
- "/u01/database/sybo5/oradata/example01.dbf";
- switch clone datafile all;
- }
- executing Memory Script
-
- executing command: SET NEWNAME
-
- renamed tempfile 1 to /u01/database/sybo5/oradata/temp01.dbf in control file
-
- cataloged datafile copy
- datafile copy file name=/u01/database/sybo5/oradata/sysaux01.dbf RECID=1 STAMP=821716521
- cataloged datafile copy
- datafile copy file name=/u01/database/sybo5/oradata/undotbs01.dbf RECID=2 STAMP=821716521
- cataloged datafile copy
- datafile copy file name=/u01/database/sybo5/oradata/users01.dbf RECID=3 STAMP=821716521
- cataloged datafile copy
- datafile copy file name=/u01/database/sybo5/oradata/example01.dbf RECID=4 STAMP=821716521
-
- datafile 2 switched to datafile copy
- input datafile copy RECID=1 STAMP=821716521 file name=/u01/database/sybo5/oradata/sysaux01.dbf
- datafile 3 switched to datafile copy
- input datafile copy RECID=2 STAMP=821716521 file name=/u01/database/sybo5/oradata/undotbs01.dbf
- datafile 4 switched to datafile copy
- input datafile copy RECID=3 STAMP=821716521 file name=/u01/database/sybo5/oradata/users01.dbf
- datafile 5 switched to datafile copy
- input datafile copy RECID=4 STAMP=821716521 file name=/u01/database/sybo5/oradata/example01.dbf
-
- contents of Memory Script:
- {
- Alter clone database open resetlogs;
- }
- executing Memory Script
-
- database opened
- Finished Duplicate Db at 2013/07/25 14:35:36
-
- [oracle@linux3 dbs]$ export ORACLE_SID=sybo5
- [oracle@linux3 dbs]$ sqlplus / as sysdba
-
- SQL*Plus: Release 11.2.0.1.0 Production on Thu Jul 25 14:38:21 2013
-
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
-
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
-
- SQL> select * from t;
-
- NAME ACTION
- Robinson Transfer DB
- Jackson Transfer DB by rman
-
- SQL> select name,dbid,open_mode from v$database;
-
- NAME DBID OPEN_MODE
- SYBO5 2292457546 READ WRITE
- 转:http://blog.csdn.net/leshami/article/details/9497321
基于 RMAN 的同机数据库克隆
标签: