应用场景:
1、旧库可以使用并且网络顺畅
实验环境:
target db:
ip 192.168.56.10
oracle_sid=mydb
oracle_version=11.2.0.3
auxiliary db:
ip 192.168.56.150
oracle_sid=oradu
oracle_version=11.2.0.3
1、在新库创建参数文件并启动实例到nomount状态
--auxiliary db上执行
[oracle@localhost ~]$ cat initoradu.ora
db_name=oradu
db_block_size=8192
db_file_name_convert=('/u01/app/oracle/oradata/mydb/','/u01/app/oracle/oradata/oradu/')
log_file_name_convert=('/u01/app/oracle/oradata/mydb/','/u01/app/oracle/oradata/oradu/')
--由于这里使用的是不同实例,所以必须添加db_file_name_convert和log_file_name_convert,否则在复制的时候会报错无法创建数据文件,如果是同实例名复制,且两数据目录完全一样的情况下,这两个参数可省略。
--在auxiliary db 上创建新库的数据文件在存放的目录
mkdir -p /u01/app/oracle/oradata/oradu/
[oracle@localhost ~]$ export ORACLE_SID=oradu
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sun Mar 20 12:56:36 2016
Copyright (c) 1982, 2011, Oracle.? All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile=/home/oracle/initoradu.ora
ORACLE instance started.
Total System Global Area? 238034944 bytes
Fixed Size? ? ? ? ? ? ? ? ? 2227136 bytes
Variable Size? ? ? ? ? ? 180356160 bytes
Database Buffers? ? ? ? ? 50331648 bytes
Redo Buffers? ? ? ? ? ? ? ? 5120000 bytes
SQL>
2、创建密码文件
--必须保持target DB和auxiliary DB的密码一致。这里我直接把target db的密码文件复制到auxiliary db对应的目录下并重命名
--target db上执行
[oracle@localhost ~]$ scp /u01/app/oracle/product/11.2.0/db/dbs/orapwmydb oracle@192.168.56.150:/u01/app/oracle/product/11.2.0/db/dbs/orapworadu
The authenticity of host '192.168.56.150 (192.168.56.150)' can't be established.
RSA key fingerprint is 58:71:ed:0c:e0:2a:57:68:3e:fe:79:52:8b:72:2e:00.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.150' (RSA) to the list of known hosts.
oracle@192.168.56.150's password:
orapwmydb? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 100% 1536? ? 1.5KB/s? 00:00? ?
3、配置target db 和auxiliary db的监听
--auxiliary db必须使用静态监听,否则报错RMAN-04006: error from auxiliary database: ORA-12528: TNS:listener: all appropriate instances are blocking new connections
--auxiliary db
vi /u01/app/oracle/product/11.2.0/db/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
? ? (SID_DESC =
? ? ? (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
? ? ? (SID_NAME=oradu)
? ? )
)
vi /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora
mydb =
(DESCRIPTION =
? ? (ADDRESS_LIST =
? ? ? (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.10)(PORT = 1521))
? ? )
? ? (CONNECT_DATA =
? ? ? (SERVICE_NAME = mydb)
? ? ? (SERVER = DEDICATED)
? ? )
)
?--target db
vi /u01/app/oracle/product/11.2.0/db/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
? ? (SID_DESC =
? ? ? (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
? ? ? (ORACLE_SID = mydb)
? ? )
)
vi /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora
oradu =
(DESCRIPTION =
? ? (ADDRESS_LIST =
? ? ? (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.150)(PORT = 1521))
? ? )
? ? (CONNECT_DATA =
? ? ? (SERVICE_NAME = oradu)
? ? ? (SERVER = DEDICATED)
? ? )
)
--重启两台机器的监听
lsnrctl stop
lsnrctl start
4、开始复制
--在target db上执行
[oracle@localhost ~]$ rman target / auxiliary sys/123456@oradu
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Mar 20 14:09:39 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.? All rights reserved.
connected to target database: MYDB (DBID=2820637901)
connected to auxiliary database: ORADU (not mounted)
RMAN> duplicate target database to oradu from active database;
Starting Duplicate Db at 20-MAR-16
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:
{
? 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? ? 238034944 bytes
Fixed Size? ? ? ? ? ? ? ? ? ? 2227136 bytes
Variable Size? ? ? ? ? ? ? ? 180356160 bytes
Database Buffers? ? ? ? ? ? ? 50331648 bytes
Redo Buffers? ? ? ? ? ? ? ? ? 5120000 bytes
contents of Memory Script:
{
? sql clone "alter system set? db_name =
?''MYDB'' comment=
?''Modified by RMAN duplicate'' scope=spfile";
? sql clone "alter system set? db_unique_name =
?''ORADU'' comment=
?''Modified by RMAN duplicate'' scope=spfile";
? shutdown clone immediate;
? startup clone force nomount
? backup as copy current controlfile auxiliary format? '/u01/app/oracle/product/11.2.0/db/dbs/cntrloradu.dbf';
? alter clone database mount;
}
executing Memory Script
sql statement: alter system set? db_name =? ''MYDB'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set? db_unique_name =? ''ORADU'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area? ? 238034944 bytes
Fixed Size? ? ? ? ? ? ? ? ? ? 2227136 bytes
Variable Size? ? ? ? ? ? ? ? 180356160 bytes
Database Buffers? ? ? ? ? ? ? 50331648 bytes
Redo Buffers? ? ? ? ? ? ? ? ? 5120000 bytes
Starting backup at 20-MAR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/11.2.0/db/dbs/snapcf_mydb.f tag=TAG20160320T140956 RECID=31 STAMP=906991797
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 20-MAR-16
database mounted
contents of Memory Script:
{
? set newname for datafile? 1 to
?"/u01/app/oracle/oradata/oradu/system01.dbf";
? set newname for datafile? 2 to
?"/u01/app/oracle/oradata/oradu/sysaux01.dbf";
? set newname for datafile? 3 to
?"/u01/app/oracle/oradata/oradu/undotbs01.dbf";
? set newname for datafile? 4 to
?"/u01/app/oracle/oradata/oradu/users01.dbf";
? s