使用duplicate命令,可以创建一个完全独立的数据库拷贝,该命令执行过程中会自动为duplicated 数据库分配一个新的dbid。其具体过程我们以同一台机器内部复制和两台机器间的复制分别加以讨论
注意:既然是同一台机器内部复制,那就需考虑为duplicated 数据库的控制文件、数据文件、日志文件寻找新的存储位置。而两台机器间的复制如果为了省事,可以尝试保持和源数据相同的目录结果,或者通过参数设置指定新的存储位置。
具体过程以linux平台为例如下:
一 同台机器内部的复制
1 在源数据库上生成一个pfile
SQL> create pfile from spfile;
File created.
2 拷贝源库的pfile 为目标库pfile
[oracle@oracle dbs]$ ls -lt
total 12084
-rw-r--r-- 1 oracle oinstall 920 Aug 24 00:54 initCRM.ora
-rw-r----- 1 oracle oinstall 2560 Aug 24 00:52 spfileCRM.ora
-rw-r----- 1 oracle oinstall 10076160 Aug 18 20:36 snapcf_CRM.f
-rw-r----- 1 oracle oinstall 1089536 Aug 14 00:04 02oh7u0i_1_1
-rw-r----- 1 oracle oinstall 1163264 Aug 14 00:04 01oh7u06_1_1
-rw-r----- 1 oracle oinstall 24 Aug 20 2012 lkCRM
-rw-rw---- 1 oracle oinstall 1544 Aug 20 2012 hc_CRM.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
[oracle@oracle dbs]$ cp initCRM.ora initCRMTEST.ora
3 更改initCRMTEST.ora 相关参数
源库数据文件和日志文件的位置如下:
SQL> select name from v$datafile;
NAME
--------------------------------------------------
/oracle/CRM2/system01.dbf
/oracle/CRM2/sysaux01.dbf
/oracle/CRM2/zx.dbf
/oracle/CRM2/users01.dbf
/oracle/CRM2/pos.dbf
/oracle/CRM2/erp.dbf
/oracle/CRM2/user01.dbf
/oracle/CRM2/undotbs03.dbf
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------- --------------------------------------------------
4 /oracle/CRM2/redo02.dbf
3 /oracle/CRM2/redo03.log
2 /oracle/CRM2/redo02.log
1 /oracle/CRM2/redo01.log
现打算让目标库的数据文件和日志文件位于/oracle/CRM/下,所以增加下面两个参数
*.db_file_name_convert=('CRM2','CRM')
*.log_file_name_convert=('CRM2','CRM')
更改前:
CRM.__db_cache_size=268435456
CRM.__java_pool_size=16777216
CRM.__large_pool_size=16777216
CRM.__oracle_base='/oracle/app'#ORACLE_BASE set from environment
CRM.__pga_aggregate_target=503316480
CRM.__sga_target=754974720
CRM.__shared_io_pool_size=0
CRM.__shared_pool_size=402653184
CRM.__streams_pool_size=33554432
*.audit_file_dest='/oracle/app/admin/CRM/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oracle/CRM2/control01.ctl','/oracle/CRM2/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_cache_size=218103808
*.db_domain=''
*.db_name='CRM'
*.diagnostic_dest='/oracle/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=CRMXDB)'
*.log_archive_dest_1='LOCATION=/oracle/archive'
*.log_archive_dest_2=''
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1258291200
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_retention=1200
*.undo_tablespace='UNDOTBS3'
更改后:
CRMTEST.__db_cache_size=268435456
CRMTEST.__java_pool_size=16777216
CRMTEST.__large_pool_size=16777216
CRMTEST.__oracle_base='/oracle/app'#ORACLE_BASE set from environment
CRMTEST.__pga_aggregate_target=503316480
CRMTEST.__sga_target=754974720
CRMTEST.__shared_io_pool_size=0
CRMTEST.__shared_pool_size=402653184
CRMTEST.__streams_pool_size=33554432
*.audit_file_dest='/oracle/app/admin/CRMTEST/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oracle/CRM/control01.ctl','/oracle/CRM/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_cache_size=218103808
*.db_domain=''
*.db_name='CRMTEST'
*.diagnostic_dest='/oracle/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=CRMXDB)'
*.log_archive_dest_1='LOCATION=/oracle/archivedest'
*.log_archive_dest_2=''
*.db_file_name_convert=('CRM2','CRM')
*.log_file_name_convert=('CRM2','CRM')
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1258291200
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_retention=1200
*.undo_tablespace='UNDOTBS3'
4 生成目标数据库的spfile
[oracle@oracle dbs]$ export ORACLE_SID=CRMTEST
[oracle@oracle dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Sat Aug 24 01:12:02 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 973080680 bytes
Database Buffers 268435456 bytes
Redo Buffers 8921088 bytes
SQL> create spfile from pfile;
File created.
5 为目标数据库创建口令文件
orapwd file="$ORACLE_HOME/dbs/orapw$ORACLE_SID" password=DHHZDHHZ
6 创建监听和服务名
[oracle@oracle admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /oracle/app/db1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
CRMTEST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.8)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = CRMTEST)
)
)
[oracle@oracle admin]$ cat listener.ora
# listener.ora Network Configuration File: /oracle/app/db1/network/admin/listener.ora
# Generated by Oracle configuration tools.
CRMTEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.8)(PORT = 1521))
)
SID_LIST_CRMTEST =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = CRMTEST)
(ORACLE_HOME = /oracle/app/db1)
(SID_NAME = CRMTEST)
)
)
ADR_BASE_CRMTEST = /oracle/app
7 备份源数据库
[oracle@oracle admin]$ export ORACLE_SID=CRM
[oracle@oracle admin]$ rman target / auxiliary sys/DHHZDHHZ@crmtest
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Aug 24 01:42:09 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: CRM (DBID=3599153036)
connected to auxiliary database: CRMTEST (not mounted)
RMAN> backup database plus archivelog ;
Starting backup at 24-AUG-13
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=198 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=18 RECID=18 STAMP=793650148
input archived log thread=1 sequence=19 RECID=19 STAMP=793747749
input archived log thread=1 sequence=20 RECID=20 STAMP=793748109
input archived log thread=1 sequence=21 RECID=21 STAMP=793748692
input archived log thread=1 sequence=22 RECID=22 STAMP=793749134
input archived log thread=1 sequence=23 RECID=23 STAMP=797025034
input archived log thread=1 sequence=24 RECID=24 STAMP=823376059
input archived log thread=1 sequence=25 RECID=38 STAMP=823810820
input archived log thread=1 sequence=26 RECID=39 STAMP=823810823
input archived log thread=1 sequence=27 RECID=40 STAMP=823810824
input archived log thread=1 sequence=28 RECID=41 STAMP=823810824
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0foi2fh2_1_1 tag=TAG20130824T014257 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=42 STAMP=823811506
input archived log thread=1 sequence=2 RECID=43 STAMP=823811507
input archived log thread=1 sequence=3 RECID=44 STAMP=823811508
input archived log thread=1 sequence=4 RECID=45 STAMP=823811510
input archived log thread=1 sequence=5 RECID=46 STAMP=823811511
input archived log thread=1 sequence=6 RECID=47 STAMP=823811512
input archived log thread=1 sequence=7 RECID=48 STAMP=823811513
input archived log thread=1 sequence=8 RECID=49 STAMP=824149793
input archived log thread=1 sequence=9 RECID=50 STAMP=824239486
input archived log thread=1 sequence=10 RECID=51 STAMP=824259130
input archived log thread=1 sequence=11 RECID=52 STAMP=824262175
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0goi2fha_1_1 tag=TAG20130824T014257 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 24-AUG-13
Starting backup at 24-AUG-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/oracle/CRM2/users01.dbf
input datafile file number=00001 name=/oracle/CRM2/system01.dbf
input datafile file number=00002 name=/oracle/CRM2/sysaux01.dbf
input datafile file number=00005 name=/oracle/CRM2/pos.dbf
input datafile file number=00006 name=/oracle/CRM2/erp.dbf
input datafile file number=00008 name=/oracle/CRM2/undotbs03.dbf
input datafile file number=00003 name=/oracle/CRM2/zx.dbf
input datafile file number=00007 name=/oracle/CRM2/user01.dbf
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0hoi2fhj_1_1 tag=TAG20130824T014315 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:15
Finished backup at 24-AUG-13
Starting backup at 24-AUG-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12 RECID=53 STAMP=824262391
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0ioi2fno_1_1 tag=TAG20130824T014632 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-AUG-13
Starting Control File and SPFILE Autobackup at 24-AUG-13
piece handle=/backup/c-3599153036-20130824-00 comment=NONE
Finished Control File and SPFILE Autobackup at 24-AUG-13
8 复制源数据库
RMAN> duplicate target database to CRMTEST;
Starting Duplicate Db at 24-AUG-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=129 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 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 989857896 bytes
Database Buffers 251658240 bytes
Redo Buffers 8921088 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''CRM'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''CRMTEST'' 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 = ''CRM'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''CRMTEST'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 989857896 bytes
Database Buffers 251658240 bytes
Redo Buffers 8921088 bytes
Starting restore at 24-AUG-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=5 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 /backup/c-3599153036-20130824-00
channel ORA_AUX_DISK_1: piece handle=/backup/c-3599153036-20130824-00 tag=TAG20130824T014634
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
output file name=/oracle/CRM/control01.ctl
output file name=/oracle/CRM/control02.ctl
Finished restore at 24-AUG-13
database mounted
contents of Memory Script:
{
set until scn 2865034;
set newname for datafile 1 to
"/oracle/CRM/system01.dbf";
set newname for datafile 2 to
"/oracle/CRM/sysaux01.dbf";
set newname for datafile 3 to
"/oracle/CRM/zx.dbf";
set newname for datafile 4 to
"/oracle/CRM/users01.dbf";
set newname for datafile 5 to
"/oracle/CRM/pos.dbf";
set newname for datafile 6 to
"/oracle/CRM/erp.dbf";
set newname for datafile 7 to
"/oracle/CRM/user01.dbf";
set newname for datafile 8 to
"/oracle/CRM/undotbs03.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
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 24-AUG-13
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 /oracle/CRM/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/CRM/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/CRM/zx.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/CRM/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/CRM/pos.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oracle/CRM/erp.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /oracle/CRM/user01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /oracle/CRM/undotbs03.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/0hoi2fhj_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:03:45
Finished restore at 24-AUG-13
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=9 STAMP=824262833 file name=/oracle/CRM/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=10 STAMP=824262833 file name=/oracle/CRM/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=11 STAMP=824262833 file name=/oracle/CRM/zx.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=824262833 file name=/oracle/CRM/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=13 STAMP=824262833 file name=/oracle/CRM/pos.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=14 STAMP=824262833 file name=/oracle/CRM/erp.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=15 STAMP=824262833 file name=/oracle/CRM/user01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=16 STAMP=824262834 file name=/oracle/CRM/undotbs03.dbf
contents of Memory Script:
{
set until scn 2865034;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 24-AUG-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 12 is already on disk as file /oracle/archive/1_12_823810820.dbf
archived log file name=/oracle/archive/1_12_823810820.dbf thread=1 sequence=12
media recovery complete, elapsed time: 00:00:01
Finished recover at 24-AUG-13
Oracle instance started
Total System Global Area 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 989857896 bytes
Database Buffers 251658240 bytes
Redo Buffers 8921088 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''CRMTEST'' 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
sql statement: alter system set db_name = ''CRMTEST'' 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 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 989857896 bytes
Database Buffers 251658240 bytes
Redo Buffers 8921088 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CRMTEST" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/oracle/CRM/redo01.log' ) SIZE 200 M REUSE,
GROUP 2 ( '/oracle/CRM/redo02.log' ) SIZE 200 M REUSE,
GROUP 3 ( '/oracle/CRM/redo03.log' ) SIZE 200 M REUSE,
GROUP 4 ( '/oracle/CRM/redo02.dbf' ) SIZE 200 M REUSE
DATAFILE
'/oracle/CRM/system01.dbf'
CHARACTER SET ZHS16GBK
contents of Memory Script:
{
catalog clone datafilecopy "/oracle/CRM/sysaux01.dbf",
"/oracle/CRM/zx.dbf",
"/oracle/CRM/users01.dbf",
"/oracle/CRM/pos.dbf",
"/oracle/CRM/erp.dbf",
"/oracle/CRM/user01.dbf",
"/oracle/CRM/undotbs03.dbf";
switch clone datafile all;
}
executing Memory Script
cataloged datafile copy
datafile copy file name=/oracle/CRM/sysaux01.dbf RECID=1 STAMP=824262915
cataloged datafile copy
datafile copy file name=/oracle/CRM/zx.dbf RECID=2 STAMP=824262915
cataloged datafile copy
datafile copy file name=/oracle/CRM/users01.dbf RECID=3 STAMP=824262916
cataloged datafile copy
datafile copy file name=/oracle/CRM/pos.dbf RECID=4 STAMP=824262916
cataloged datafile copy
datafile copy file name=/oracle/CRM/erp.dbf RECID=5 STAMP=824262916
cataloged datafile copy
datafile copy file name=/oracle/CRM/user01.dbf RECID=6 STAMP=824262916
cataloged datafile copy
datafile copy file name=/oracle/CRM/undotbs03.dbf RECID=7 STAMP=824262916
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=824262915 file name=/oracle/CRM/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=824262915 file name=/oracle/CRM/zx.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=824262916 file name=/oracle/CRM/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=824262916 file name=/oracle/CRM/pos.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=824262916 file name=/oracle/CRM/erp.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=6 STAMP=824262916 file name=/oracle/CRM/user01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=7 STAMP=824262916 file name=/oracle/CRM/undotbs03.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 24-AUG-13
RMAN>
------------------------同台机器内复制数据库完---------------------------------
二 两台机器间的复制
1 在源库生成pfile文件
SQL> create pfile from spfile;
File created.
SQL> host;
[oracle@zx ~]$ ls -lt /oracle/app/db1/dbs
total 12100
-rw-r--r-- 1 oracle oinstall 920 Aug 24 21:31 initCRM.ora
-rw-r----- 1 oracle oinstall 2560 Aug 24 20:18 spfileCRM.ora
-rw-r----- 1 oracle oinstall 10076160 Aug 24 01:46 snapcf_CRM.f
-rw-r----- 1 oracle oinstall 1536 Aug 24 01:31 orapwCRMTEST
-rw-r--r-- 1 oracle oinstall 1043 Aug 24 01:21 initCRMTEST.ora
-rw-r----- 1 oracle oinstall 24 Aug 24 01:18 lkCRMTEST
-rw-rw---- 1 oracle oinstall 1544 Aug 24 01:12 hc_CRMTEST.dat
-rw-r----- 1 oracle oinstall 1089536 Aug 14 00:04 02oh7u0i_1_1
-rw-r----- 1 oracle oinstall 1163264 Aug 14 00:04 01oh7u06_1_1
-rw-r----- 1 oracle oinstall 24 Aug 20 2012 lkCRM
-rw-rw---- 1 oracle oinstall 1544 Aug 20 2012 hc_CRM.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
2 在源库上修改生成的spfile
注意由于源库和目标oracle具有相同的目录结构所以对参数文件不做任何修改保持原样
不过在复制语句中要加入nofilenamecheck参数防止复制操作在还原前检查文件名是否相同
如下为参数文件内容:
[oracle@zx ~]$ cat $ORACLE_HOME/dbs/initCRM.ora
CRM.__db_cache_size=268435456
CRM.__java_pool_size=16777216
CRM.__large_pool_size=16777216
CRM.__oracle_base='/oracle/app'#ORACLE_BASE set from environment
CRM.__pga_aggregate_target=503316480
CRM.__sga_target=754974720
CRM.__shared_io_pool_size=0
CRM.__shared_pool_size=402653184
CRM.__streams_pool_size=33554432
*.audit_file_dest='/oracle/app/admin/CRM/adump' 注意:该参数目录需在目标数据库上创建 mkdir -p /oracle/app/admin/CRM/adump
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oracle/CRM2/control01.ctl','/oracle/CRM2/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_cache_size=218103808
*.db_domain=''
*.db_name='CRM'
*.diagnostic_dest='/oracle/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=CRMXDB)'
*.log_archive_dest_1='LOCATION=/oracle/archive'
*.log_archive_dest_2=''
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1258291200
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_retention=1200
*.undo_tablespace='UNDOTBS3'
注意:如果需要更改数据文件和日志文件的路径则需加入下两个参数进行调整
*.db_file_name_convert=()
*.log_file_name_convert=()
3 在源数据库服务器上备份数据库
RMAN> backup database plus archivelog;
Starting backup at 24-AUG-13
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=13 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=18 RECID=18 STAMP=793650148
input archived log thread=1 sequence=19 RECID=19 STAMP=793747749
input archived log thread=1 sequence=20 RECID=20 STAMP=793748109
input archived log thread=1 sequence=21 RECID=21 STAMP=793748692
input archived log thread=1 sequence=22 RECID=22 STAMP=793749134
input archived log thread=1 sequence=23 RECID=23 STAMP=797025034
input archived log thread=1 sequence=24 RECID=24 STAMP=823376059
input archived log thread=1 sequence=25 RECID=38 STAMP=823810820
input archived log thread=1 sequence=26 RECID=39 STAMP=823810823
input archived log thread=1 sequence=27 RECID=40 STAMP=823810824
input archived log thread=1 sequence=28 RECID=41 STAMP=823810824
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0koi4s2k_1_1 tag=TAG20130824T232923 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=42 STAMP=823811506
input archived log thread=1 sequence=2 RECID=43 STAMP=823811507
input archived log thread=1 sequence=3 RECID=44 STAMP=823811508
input archived log thread=1 sequence=4 RECID=45 STAMP=823811510
input archived log thread=1 sequence=5 RECID=46 STAMP=823811511
input archived log thread=1 sequence=6 RECID=47 STAMP=823811512
input archived log thread=1 sequence=7 RECID=48 STAMP=823811513
input archived log thread=1 sequence=8 RECID=49 STAMP=824149793
input archived log thread=1 sequence=9 RECID=50 STAMP=824239486
input archived log thread=1 sequence=10 RECID=51 STAMP=824259130
input archived log thread=1 sequence=11 RECID=52 STAMP=824262175
input archived log thread=1 sequence=12 RECID=53 STAMP=824262391
input archived log thread=1 sequence=13 RECID=54 STAMP=824329097
input archived log thread=1 sequence=14 RECID=55 STAMP=824340560
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0loi4s2s_1_1 tag=TAG20130824T232923 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 24-AUG-13
Starting backup at 24-AUG-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/oracle/CRM2/users01.dbf
input datafile file number=00001 name=/oracle/CRM2/system01.dbf
input datafile file number=00002 name=/oracle/CRM2/sysaux01.dbf
input datafile file number=00005 name=/oracle/CRM2/pos.dbf
input datafile file number=00006 name=/oracle/CRM2/erp.dbf
input datafile file number=00008 name=/oracle/CRM2/undotbs03.dbf
input datafile file number=00003 name=/oracle/CRM2/zx.dbf
input datafile file number=00007 name=/oracle/CRM2/user01.dbf
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0moi4s34_1_1 tag=TAG20130824T232939 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:35
Finished backup at 24-AUG-13
Starting backup at 24-AUG-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=15 RECID=56 STAMP=824340796
channel ORA_DISK_1: starting piece 1 at 24-AUG-13
channel ORA_DISK_1: finished piece 1 at 24-AUG-13
piece handle=/backup/0noi4s9t_1_1 tag=TAG20130824T233316 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-AUG-13
Starting Control File and SPFILE Autobackup at 24-AUG-13
piece handle=/backup/c-3599153036-20130824-01 comment=NONE
Finished Control File and SPFILE Autobackup at 24-AUG-1
4 拷贝源库参数文件到目标数据库dbs目录下
在源库上拷贝参数文件到目标数据库dbs目录下
[root@zx ~]# scp /oracle/app/db1/dbs/initCRM.ora [email protected]:/oracle/app/db1/dbs/
[email protected]'s password:
initCRM.ora 100% 920 0.9KB/s 00:00
[root@zx ~]#
在目标数据库服务器上更改该参数文件属主
[root@oracle dbs]# ls -lt
total 12
-rw-r--r-- 1 root root 920 Aug 24 23:40 initCRM.ora
-rw-r----- 1 oracle oinstall 1536 Aug 24 23:25 orapwCRM
-rw-rw---- 1 oracle oinstall 1544 Aug 24 20:02 hc_CRM.dat
[root@oracle dbs]# chown oracle:oinstall initCRM.ora
[root@oracle dbs]# ls -lt
total 12
-rw-r--r-- 1 oracle oinstall 920 Aug 24 23:40 initCRM.ora
-rw-r----- 1 oracle oinstall 1536 Aug 24 23:25 orapwCRM
-rw-rw---- 1 oracle oinstall 1544 Aug 24 20:02 hc_CRM.dat
在目标库上生成spfile文件
[oracle@dest ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Sun Aug 25 00:17:58 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 973080680 bytes
Database Buffers 268435456 bytes
Redo Buffers 8921088 bytes
SQL> create spfile from pfile;
File created.
5 拷贝源库备份到目标库同目录下
要拷贝的文件为:
piece handle=/backup/0koi4s2k_1_1
piece handle=/backup/0loi4s2s_1_1
piece handle=/backup/0moi4s34_1_1
piece handle=/backup/0noi4s9t_1_1
piece handle=/backup/c-3599153036-20130824-01
在源服务器上拷贝过程如下:
-rw-r----- 1 oracle oinstall 20393472 Aug 28 2012 05njqj9f_1_1
[root@zx backup]# scp ./c-3599153036-20130824-01 [email protected]:/backup/
[email protected]'s password:
c-3599153036-20130824-01 100% 9920KB 9.7MB/s 00:01
[root@zx backup]# scp ./0noi4s9t_1_1 [email protected]:/backup/
[email protected]'s password:
0noi4s9t_1_1 100% 8192 8.0KB/s 00:00
[root@zx backup]# scp ./0moi4s34_1_1 [email protected]:/backup/
[email protected]'s password:
0moi4s34_1_1 100% 2152MB 7.7MB/s 04:41
[root@zx backup]# scp ./0loi4s2s_1_1 [email protected]:/backup/
[email protected]'s password:
0loi4s2s_1_1 100% 33MB 11.0MB/s 00:03
[root@zx backup]# scp ./0koi4s2k_1_1 [email protected]:/backup/
[email protected]'s password:
0koi4s2k_1_1 100% 39MB 7.7MB/s 00:05
在目标数据库所在的服务器上更改文件属主
[root@oracle backup]# ls -lt
total 9482452
-rw-r----- 1 root root 40567808 Aug 24 23:53 0koi4s2k_1_1
-rw-r----- 1 root root 34523136 Aug 24 23:52 0loi4s2s_1_1
-rw-r----- 1 root root 2256723968 Aug 24 23:51 0moi4s34_1_1
-rw-r----- 1 root root 8192 Aug 24 23:46 0noi4s9t_1_1
-rw-r----- 1 root root 10158080 Aug 24 23:45 c-3599153036-20130824-01
[root@oracle backup]# chown oracle:oinstall c-3599153036-20130824-01
[root@oracle backup]# chown oracle:oinstall 0noi4s9t_1_1
[root@oracle backup]# chown oracle:oinstall 0moi4s34_1_1
[root@oracle backup]# chown oracle:oinstall 0loi4s2s_1_1
[root@oracle backup]# chown oracle:oinstall 0koi4s2k_1_1
[root@oracle backup]# ls -lt
total 9482452
-rw-r----- 1 oracle oinstall 40567808 Aug 24 23:53 0koi4s2k_1_1
-rw-r----- 1 oracle oinstall 34523136 Aug 24 23:52 0loi4s2s_1_1
-rw-r----- 1 oracle oinstall 2256723968 Aug 24 23:51 0moi4s34_1_1
-rw-r----- 1 oracle oinstall 8192 Aug 24 23:46 0noi4s9t_1_1
-rw-r----- 1 oracle oinstall 10158080 Aug 24 23:45 c-3599153036-20130824-01
6 在目标数据库服务器上创建密码文件
orapwd file="$ORACLE_HOME/dbs/orapw$ORACLE_SID" password=DHHZDHHZ
7 在目标数据库上创建监听并启动
[root@dest admin]# cat listener.ora
# listener.ora Network Configuration File: /oracle/app/db1/network/admin/listener.ora
# Generated by Oracle configuration tools.
CRM =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.10)(PORT = 1521))
)
SID_LIST_CRM =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = CRM)
(ORACLE_HOME = /oracle/app/db1)
(SID_NAME = CRM)
)
)
ADR_BASE_CRM = /oracle/app
启动监听
LSNRCTL> start crm
Starting /oracle/app/db1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.2.0 - Production
System parameter file is /oracle/app/db1/network/admin/listener.ora
Log messages written to /oracle/app/diag/tnslsnr/dest/crm/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.5.10)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.5.10)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias crm
Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date 25-AUG-2013 00:34:23
Uptime 0 days 0 hr. 0 min. 1 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/db1/network/admin/listener.ora
Listener Log File /oracle/app/diag/tnslsnr/dest/crm/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.5.10)(PORT=1521)))
Services Summary...
Service "CRM" has 1 instance(s).
Instance "CRM", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
8 在源库上创建连接目标库的服务名
[root@zx admin]# cat tnsnames.ora
# tnsnames.ora Network Configuration File: /oracle/app/db1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
CRM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.10)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = CRM)
)
)
9 复制数据库过程
[oracle@zx ~]$ rman target / auxiliary sys/DHHZDHHZ@crm
Recovery Manager: Release 11.2.0.2.0 - Production on Sun Aug 25 00:35:52 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: CRM (DBID=3599153036)
connected to auxiliary database: CRM (not mounted)
RMAN> duplicate target database to crm nofilenamecheck;
Starting Duplicate Db at 25-AUG-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=63 device type=DISK
contents of Memory Script:
{
sql clone "alter system set db_name =
''CRM'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''CRM'' 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 = ''CRM'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''CRM'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 973080680 bytes
Database Buffers 268435456 bytes
Redo Buffers 8921088 bytes
Starting restore at 25-AUG-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=63 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 /backup/c-3599153036-20130824-01
channel ORA_AUX_DISK_1: piece handle=/backup/c-3599153036-20130824-01 tag=TAG20130824T233319
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/oracle/CRM2/control01.ctl
output file name=/oracle/CRM2/control02.ctl
Finished restore at 25-AUG-13
database mounted
contents of Memory Script:
{
set until scn 2892348;
set newname for datafile 1 to
"/oracle/CRM2/system01.dbf";
set newname for datafile 2 to
"/oracle/CRM2/sysaux01.dbf";
set newname for datafile 3 to
"/oracle/CRM2/zx.dbf";
set newname for datafile 4 to
"/oracle/CRM2/users01.dbf";
set newname for datafile 5 to
"/oracle/CRM2/pos.dbf";
set newname for datafile 6 to
"/oracle/CRM2/erp.dbf";
set newname for datafile 7 to
"/oracle/CRM2/user01.dbf";
set newname for datafile 8 to
"/oracle/CRM2/undotbs03.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
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 25-AUG-13
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 /oracle/CRM2/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/CRM2/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/CRM2/zx.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/CRM2/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/CRM2/pos.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oracle/CRM2/erp.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /oracle/CRM2/user01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /oracle/CRM2/undotbs03.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/0moi4s34_1_1
channel ORA_AUX_DISK_1: piece handle=/backup/0moi4s34_1_1 tag=TAG20130824T232939
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:15
Finished restore at 25-AUG-13
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=824344808 file name=/oracle/CRM2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=824344809 file name=/oracle/CRM2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=824344809 file name=/oracle/CRM2/zx.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=824344809 file name=/oracle/CRM2/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=824344809 file name=/oracle/CRM2/pos.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=6 STAMP=824344809 file name=/oracle/CRM2/erp.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=7 STAMP=824344809 file name=/oracle/CRM2/user01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=8 STAMP=824344809 file name=/oracle/CRM2/undotbs03.dbf
contents of Memory Script:
{
set until scn 2892348;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 25-AUG-13
using channel ORA_AUX_DISK_1
starting media recovery
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 /backup/0noi4s9t_1_1
channel ORA_AUX_DISK_1: piece handle=/backup/0noi4s9t_1_1 tag=TAG20130824T233316
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=/oracle/archive/1_15_823810820.dbf thread=1 sequence=15
channel clone_default: deleting archived log(s)
archived log file name=/oracle/archive/1_15_823810820.dbf RECID=57 STAMP=824344817
media recovery complete, elapsed time: 00:00:02
Finished recover at 25-AUG-13
Oracle instance started
Total System Global Area 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 973080680 bytes
Database Buffers 268435456 bytes
Redo Buffers 8921088 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''CRM'' 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
sql statement: alter system set db_name = ''CRM'' 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 1252663296 bytes
Fixed Size 2226072 bytes
Variable Size 973080680 bytes
Database Buffers 268435456 bytes
Redo Buffers 8921088 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/oracle/CRM2/redo01.log' ) SIZE 200 M REUSE,
GROUP 2 ( '/oracle/CRM2/redo02.log' ) SIZE 200 M REUSE,
GROUP 3 ( '/oracle/CRM2/redo03.log' ) SIZE 200 M REUSE,
GROUP 4 ( '/oracle/CRM2/redo02.dbf' ) SIZE 200 M REUSE
DATAFILE
'/oracle/CRM2/system01.dbf'
CHARACTER SET ZHS16GBK
contents of Memory Script:
{
catalog clone datafilecopy "/oracle/CRM2/sysaux01.dbf",
"/oracle/CRM2/zx.dbf",
"/oracle/CRM2/users01.dbf",
"/oracle/CRM2/pos.dbf",
"/oracle/CRM2/erp.dbf",
"/oracle/CRM2/user01.dbf",
"/oracle/CRM2/undotbs03.dbf";
switch clone datafile all;
}
executing Memory Script
cataloged datafile copy
datafile copy file name=/oracle/CRM2/sysaux01.dbf RECID=1 STAMP=824344852
cataloged datafile copy
datafile copy file name=/oracle/CRM2/zx.dbf RECID=2 STAMP=824344852
cataloged datafile copy
datafile copy file name=/oracle/CRM2/users01.dbf RECID=3 STAMP=824344852
cataloged datafile copy
datafile copy file name=/oracle/CRM2/pos.dbf RECID=4 STAMP=824344852
cataloged datafile copy
datafile copy file name=/oracle/CRM2/erp.dbf RECID=5 STAMP=824344852
cataloged datafile copy
datafile copy file name=/oracle/CRM2/user01.dbf RECID=6 STAMP=824344852
cataloged datafile copy
datafile copy file name=/oracle/CRM2/undotbs03.dbf RECID=7 STAMP=824344852
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=824344852 file name=/oracle/CRM2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=824344852 file name=/oracle/CRM2/zx.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=824344852 file name=/oracle/CRM2/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=824344852 file name=/oracle/CRM2/pos.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=824344852 file name=/oracle/CRM2/erp.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=6 STAMP=824344852 file name=/oracle/CRM2/user01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=7 STAMP=824344852 file name=/oracle/CRM2/undotbs03.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 25-AUG-13
--------------------------------完---------------------------------------------