原理是:
Use the RMAN DUPLICATE command to create a duplicate database using target database backups.
通过RMAN用目标数据库的备份来创建duplicate database
什么是duplicate database:
A duplicate database is a copy of the target database (or a subset of the target database) with a new, unique database identifier (DBID). The target database site and duplicate database site can be on the same or separate hosts. The duplicate database is created using backups and archived redo log files from the target database.
具体的创建步骤如下:
The step of creating a duplicate database:
1,Create an Oracle password file for the auxiliary instance.
2,Establish Oracle Net connectivity to the auxiliary instance.
3,Create an initialization parameter file for the auxiliary instance.
4,Start the auxiliary instance in NOMOUNT mode.
5,Mount or open the target database.
6,Ensure that backups and archived redo log files are available.
7,Allocate auxiliary channels if needed.
8,Execute the DUPLICATE command.
Understanding the RMAN Duplication Operation:
了解RMAN在创建duplicate database的时候具体的做了那些操作:
When you execute the DUPLICATE command, RMAN performs the following operations:
1,Creates a control file for the duplicate database
2,Restores the target datafiles to the duplicate database
3,Performs incomplete recovery using all available incremental backups and archived redo log files
4,Shuts down and restarts the auxiliary instance
5,Opens the duplicate database with the RESETLOGS option
6,Creates the online redo log files
7,Generates a new, unique database identifier (DBID) for the duplicate database
我下面的实验是在同一台host上做的duplicate.
vi /etc/hosts里面DB HOST IP要和Listener.ora里的IP一样
创建目录:
[oracle@even ~]$ mkdir /u01/app/oracle/oradata/testdup
[oracle@even test]$ mkdir -p /u01/app/oracle/admin/testdup/{a,b,c,dp,u}dump
启动监听:
[oracle@even dbs]$ lsnrctl start
创建复制数据库时所使用的初始化参数inittestdup.ora:
$ cd $ORACLE_HOME/dbs
[oracle@even dbs]$ vi inittestdup.ora
db_name=testdup
db_block_size=8192
CONTROL_FILES='/u01/app/oracle/oradata/testdup/control01.ctl', '/u01/app/oracle/oradata/testdup/control02.ctl','/u01/app/oracle/oradata/testdup/control03.ctl'
undo_management=auto
undo_tablespace=undotbs1
#下面路径要成对的出现
db_file_name_convert='/u01/app/oracle/oradata/test','/u01/app/oracle/oradata/testdup'
log_file_name_convert='/u01/app/oracle/oradata/test','/u01/app/oracle/oradata/testdup'
#目标和源版本一致
compatible=10.2.0.1.0
shared_pool_size=200M
sga_target=500M
配置tnsnames:
cd $ORACLE_HOME/network/admin
[oracle@even admin]$ vi tnsnames.ora
TEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = even.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = test)
)
)
TESTDUP =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = even.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testdup)
)
)
配置监听:
cd $ORACLE_HOME/network/admin
[oracle@even admin]$ vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = even.oracle.com)(PORT = 1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=test)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=test)
)
(SID_DESC=
(GLOBAL_DBNAME=testdup)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=testdup)
)
)
重新加载监听:
[oracle@even admin]$ lsnrctl reload
配置密码文件
cd $ORACLE_HOME/dbs
orapwd file=orapwtestdup password=oracle entries=5
[oracle@even ~]$ sqlplus sys/oracle@testdup as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 31 16:15:01 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile='$ORACLE_HOME/dbs/inittestdup.ora'
ORACLE instance started.
Total System Global Area 524288000 bytes
Fixed Size 1220360 bytes
Variable Size 218104056 bytes
Database Buffers 301989888 bytes
Redo Buffers 2973696 bytes
[oracle@even ~]$ export ORACLE_SID=testdup
[oracle@even ~]$ rman target sys/oracle@test auxiliary /
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Dec 31 16:26:32 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: TEST (DBID=2101363784)
connected to auxiliary database: TESTDUP (not mounted)
注意在做duplicate 是恢复到最后一个归档的时间点,所以一定要有归档日志,即duplicate之前一定还要切换几下日志,否则有可能会duplicate 不成功。
会提示unable to find archive log
SQL> alter system switch logfile;
System altered.
RMAN>run{
allocate auxiliary channel c1 device type disk;
allocate auxiliary channel c2 device type disk;
duplicate target database to testdup;
}
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 2012-12-31 16:48:54
表示duplicate数据库成功!!!!
再创建一个spfile,让数据库根据spfile启动。
[oracle@even ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 31 16:53:51 2012
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, Oracle Label Security, OLAP and Data Mining options
SQL> select status,instance_name from v$instance;
STATUS INSTANCE_NAME
------------------------ --------------------------------
OPEN testdup
SQL> create spfile from pfile;
File created.
到此duplicate 数据库顺利完成。。。