本地创建Duplicate数据库,新创建的文件路径与目标数据库不同,并且辅助实例的初始化參数DB_NAME与目标数据库不能同样。
1.创建辅助实例的秘钥文件
[oracle@linux5 dbs]$ pwd
/u01/app/oracle/10.2.0/db_1/dbs
[oracle@linux5 dbs]$ orapwd file=/u01/app/oracle/10.2.0/db_1/dbs/orapworcldup password=safe entries=30
2.手工建库
[oracle@linux5 admin]$ pwd
/u01/app/oracle/admin
[oracle@linux5 admin]$ mkdir orcldup
[oracle@linux5 admin]$ cd orcldup/
[oracle@linux5 orcldup]$ mkdir {a,b,c,u}dump
[oracle@linux5 orcldup]$ ls
adump bdump cdump udump
[oracle@linux5 orcldup]$
3.配置初始化參数文件
[oracle@linux5 orcldup]$ export ORACLE_SID=orcl
[oracle@linux5 orcldup]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Apr 17 05:32:56 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create pfile='/u01/dup_test/pfile' from spfile;
File created.
[oracle@linux5 orcldup]$ export ORACLE_SID=orcldup 创建辅助实例的spfile之前要指定sid为辅助实例的sid,否则会覆盖目标数据库。
[oracle@linux5 orcldup]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Apr 17 05:31:41 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
[oracle@linux5 ~]$ cd /u01/
[oracle@linux5 u01]$ ls
app arch bak dup_test
[oracle@linux5 u01]$ cd dup_test/
[oracle@linux5 dup_test]$ ls
pfile
[oracle@linux5 dup_test]$ pwd
/u01/dup_test
[oracle@linux5 dup_test]$ mkdir orcldup
[oracle@linux5 dup_test]$ ls
orcldup pfile
PFILE:
*.control_files='/u01/dup_test/orcldup/control01.ctl','/u01/dup_test/orcldup/control02.ctl','/u01/dup_test/orcldup/control03.ctl'
*.db_block_size=8192
*.db_name='orcldup'
*.shared_pool_size=200000000
*.db_block_size=8192
*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/dup_test/orcldup'
#*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/dup_test/orcldup' 这样也能生成logfile,不用在duplicate再指定语句
*.log_file_name_convert='/u01/arch','/u01/dup_test/orcldup'
*.audit_file_dest='/u01/app/oracle/admin/orcldup/adump'
*.background_dump_dest='/u01/app/oracle/admin/orcldup/bdump'
*.compatible='10.2.0.1.0'
*.core_dump_dest='/u01/app/oracle/admin/orcldup/cdump'
*.user_dump_dest='/u01/app/oracle/admin/orcldup/udump'
SQL> create spfile from pfile='/u01/dup_test/pfile';
File created.
4.启动辅助实例
SQL> startup nomount //必须启动到nomount状态后面才干够运行duplicate命令
ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 1218968 bytes
Variable Size 226494056 bytes
Database Buffers 50331648 bytes
Redo Buffers 2973696 bytes
5.配置网络
/etc/sysconfig/network-scripts
eth0:
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:0C:29:53:DB:E3
ONBOOT=yes
IPADDR=10.255.17.222
NETMASK=255.255.0.0
GATEWAY=10.255.0.1
~
~
eth1:
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:53:db:ed
IPADDR=192.168.1.222
NETMASK=255.255.255.0
~
~
~
[root@linux5 network-scripts]# service network stop
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
[root@linux5 network-scripts]# service network start
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]
配置监听和网络服务名
LISTENER.ORA
# listener.ora Network Configuration File: /u01/app/oracle/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/10.2.0/db_1)
(global_name = orcl)
)
(SID_DESC =
(SID_NAME = orcldup)
(ORACLE_HOME = /u01/app/oracle/10.2.0/db_1)
(global_name = orcldup)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.222)(PORT = 1521))
)
)
TNSNAMES.ORA
# tnsnames.ora Network Configuration File: /u01/app/oracle/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
orcl_local =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.222)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
orcl_dup =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.222)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldup)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
重新启动监听,使其生效
[oracle@linux5 admin]$ lsnrctl stop
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 17-APR-2014 04:56:44
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully
[oracle@linux5 admin]$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 17-APR-2014 04:59:12
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /u01/app/oracle/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /u01/app/oracle/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.222)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 17-APR-2014 04:59:12
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.222)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Service "orcldup" has 1 instance(s).
Instance "orcldup", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
6.启动目标数据库到MOUNT或OPEN状态
[oracle@linux5 orcldup]$ export ORACLE_SID=orcl //ORACLE_SID要大写
[oracle@linux5 orcldup]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Apr 17 05:08:29 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 75499764 bytes
Database Buffers 88080384 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
7.验证备份
RMAN> list backup of database
2> ;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5 Full 573.44M DISK 00:00:53 26-FEB-14
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20140226T035256
Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_02_26/o1_mf_nnndf_TAG20140226T035256_9jvodwgh_.bkp
List of Datafiles in backup set 5
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 500685 26-FEB-14 /u01/app/oracle/oradata/orcl/system01.dbf
2 Full 500685 26-FEB-14 /u01/app/oracle/oradata/orcl/undotbs01.dbf
3 Full 500685 26-FEB-14 /u01/app/oracle/oradata/orcl/sysaux01.dbf
4 Full 500685 26-FEB-14 /u01/app/oracle/oradata/orcl/users01.dbf
5 Full 500685 26-FEB-14 /u01/app/oracle/oradata/orcl/example01.dbf
8.RMAN连接目标库和辅助实例,正式环境依据实际分配通道
[oracle@linux5 admin]$ rman target
sys/oracle@orcl_local auxiliary
sys/safe@orcl_dup
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Apr 17 05:54:44 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1368292794)
connected to auxiliary database: ORCLDUP (not mounted)
RMAN> duplicate target database to orcldup
2> ;
Starting Duplicate Db at 17-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=35 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 04/17/2014 05:57:23
RMAN-05501: aborting duplication of target database
RMAN-05001: auxiliary filename /u01/app/oracle/oradata/orcl/redo03.log conflicts with a file used by the target database
RMAN-05001: auxiliary filename /u01/app/oracle/oradata/orcl/redo02.log conflicts with a file used by the target database
RMAN-05001: auxiliary filename /u01/app/oracle/oradata/orcl/redo01.log conflicts with a file used by the target database
RMAN> duplicate target database to orcldup //先要创建/u01/app/oracle/oradata/orcldup
2> logfile
3> '/u01/app/oracle/oradata/orcldup/redo01.log' size 20m,
4> '/u01/app/oracle/oradata/orcldup/redo02.log' size 20m,
5> '/u01/app/oracle/oradata/orcldup/redo03.log' size 20m
6> ;
Starting Duplicate Db at 17-APR-14
using channel ORA_AUX_DISK_1
contents of Memory Script:
{
set until scn 500750;
set newname for datafile 1 to
"/u01/dup_test/orcldup/system01.dbf";
set newname for datafile 2 to
"/u01/dup_test/orcldup/undotbs01.dbf";
set newname for datafile 3 to
"/u01/dup_test/orcldup/sysaux01.dbf";
set newname for datafile 4 to
"/u01/dup_test/orcldup/users01.dbf";
set newname for datafile 5 to
"/u01/dup_test/orcldup/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 17-APR-14
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/dup_test/orcldup/system01.dbf
restoring datafile 00002 to /u01/dup_test/orcldup/undotbs01.dbf
restoring datafile 00003 to /u01/dup_test/orcldup/sysaux01.dbf
restoring datafile 00004 to /u01/dup_test/orcldup/users01.dbf
restoring datafile 00005 to /u01/dup_test/orcldup/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_02_26/o1_mf_nnndf_TAG20140226T035256_9jvodwgh_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_02_26/o1_mf_nnndf_TAG20140226T035256_9jvodwgh_.bkp tag=TAG20140226T035256
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:12
Finished restore at 17-APR-14
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCLDUP" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/orcldup/redo01.log' SIZE 20 M ,
GROUP 2 '/u01/app/oracle/oradata/orcldup/redo02.log' SIZE 20 M ,
GROUP 3 '/u01/app/oracle/oradata/orcldup/redo03.log' SIZE 20 M
DATAFILE
'/u01/dup_test/orcldup/system01.dbf'
CHARACTER SET WE8ISO8859P1
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
released channel: ORA_AUX_DISK_1
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=845100699 filename=/u01/dup_test/orcldup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=845100699 filename=/u01/dup_test/orcldup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=845100699 filename=/u01/dup_test/orcldup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=845100700 filename=/u01/dup_test/orcldup/example01.dbf
contents of Memory Script:
{
set until scn 500750;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 17-APR-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=35 devtype=DISK
starting media recovery
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=7
channel ORA_AUX_DISK_1: reading from backup piece /u01/bak/rman_bak_02-26_840513235.bak
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/bak/rman_bak_02-26_840513235.bak tag=TAG20140226T035355
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
archive log filename=/u01/app/oracle/10.2.0/db_1/dbs/arch1_7_840512061.dbf thread=1 sequence=7
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db_1/dbs/arch1_7_840512061.dbf recid=1 stamp=845100711
media recovery complete, elapsed time: 00:00:11
Finished recover at 17-APR-14
contents of Memory Script:
{
shutdown clone;
startup clone nomount ;
}
executing Memory Script //////long time 有链接卡在这。最好仅仅开一个窗体
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 281018368 bytes
Fixed Size 1218968 bytes
Variable Size 226494056 bytes
Database Buffers 50331648 bytes
Redo Buffers 2973696 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCLDUP" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/orcldup/redo01.log' SIZE 20 M ,
GROUP 2 '/u01/app/oracle/oradata/orcldup/redo02.log' SIZE 20 M ,
GROUP 3 '/u01/app/oracle/oradata/orcldup/redo03.log' SIZE 20 M
DATAFILE
'/u01/dup_test/orcldup/system01.dbf'
CHARACTER SET WE8ISO8859P1
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/dup_test/orcldup/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/dup_test/orcldup/undotbs01.dbf";
catalog clone datafilecopy "/u01/dup_test/orcldup/sysaux01.dbf";
catalog clone datafilecopy "/u01/dup_test/orcldup/users01.dbf";
catalog clone datafilecopy "/u01/dup_test/orcldup/example01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /u01/dup_test/orcldup/temp01.dbf in control file
cataloged datafile copy
datafile copy filename=/u01/dup_test/orcldup/undotbs01.dbf recid=1 stamp=845228858
cataloged datafile copy
datafile copy filename=/u01/dup_test/orcldup/sysaux01.dbf recid=2 stamp=845228860
cataloged datafile copy
datafile copy filename=/u01/dup_test/orcldup/users01.dbf recid=3 stamp=845228862
cataloged datafile copy
datafile copy filename=/u01/dup_test/orcldup/example01.dbf recid=4 stamp=845228865
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=845228858 filename=/u01/dup_test/orcldup/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=845228860 filename=/u01/dup_test/orcldup/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=845228862 filename=/u01/dup_test/orcldup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=845228865 filename=/u01/dup_test/orcldup/example01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 18-APR-14
RMAN>
验证:
SQL> conn sys/safe@orcl_dup as sysdba
Connected.
SQL> select name from v$tablespace;
NAME
------------------------------
SYSTEM
TEMP
UNDOTBS1
SYSAUX
USERS
EXAMPLE
6 rows selected.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/dup_test/orcldup/system01.dbf
/u01/dup_test/orcldup/undotbs01.dbf
/u01/dup_test/orcldup/sysaux01.dbf
/u01/dup_test/orcldup/users01.dbf
/u01/dup_test/orcldup/example01.dbf
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/dup_test/orcldup/temp01.dbf
注意路径已经转化。