Oracle 11G Active Database Duplicate

经过上一篇文章《Oracle 11G Duplicate 介绍》,我们已经对11g Duplicate有了较为深刻的理解,本篇文章将介绍Oracle 11G duplicate From Active Database方式进行在源库开库状态下进行数据库的复制,本文 介绍异机复制的两个案例,相同实例名和不同的实例名。

DUPLICATE
目的

使用DUPLICATE命令来创建一个副本源数据库。 RMAN可以创建以下类型的数据库:

一个复制数据库,这是源数据库的一个副本(或源数据库的一个子集)和一个独特的DBID。 因为复制数据库都有一个独特的DBID,它独立于源数据库,可以注册在同一个恢复目录。 一般来说,重复的数据库是用于测试。

一个备用数据库,这是一个特殊的源数据库(称为副本主数据库在数据保护环境),通过应用更新归档重做日志文件从主数据库。 一个备用数据库没有分配一个新的DBID。

RMAN可以执行下列的重复支持模式:

1、Active duplication 活跃的复制

RMAN可以在源库open或者mount状态下复制数据库。

2、Backup-based duplicate 不连接目标库模式

RMAN创建复制文件从既存RMAN备份和拷贝。 DUPLICATE命令必须带DATABASE子句。 此模式需要连接一个辅助实例和恢复目录。

这种模式非常有用当目标数据库不可用或连接是不可取的(如规定安全政策限制或防火墙)。

3、Backup-based duplicate 连接目标库模式

RMAN创建复制文件从既存RMAN备份和拷贝。

4、Backup-based duplicate 没有链接目标库和恢复目录

RMAN创建从RMAN备份和复制文件放置在指定的副本BACKUP LOCATION.

示例环境:
源主机(Target库)
机器名:dgmaster01
IP地址:192.168.100.1
实例名:testdg
数据库版本:11.2.0.4.0

目的地主机(Auxiliary库)
机器名:dgstandby02
IP地址:192.168.100.2
实例1名:testdg
实例2名:testdg2
数据库版本:11.2.0.4.0

一、示例一:相同的实例名(源testdg 目的地:testdg)
(1)源主机配置
1、源主机 环境配置

[oracle@dgmaster01 ~]$ vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=testdg

2、配置listener.ora 增加实例的静态监听

[oracle@dgmaster01 ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dgmaster01)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /u01/app/oracle
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = testdg)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = testdg)
)
)

3、配置tnsnames.ora

[oracle@dgmaster01 ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
DGM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = testdg)
)
)

DGS =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = testdg)
)
)

4、创建pfile文件

SQL> create pfile from spfile;

5、将源主机密码文件和新创建的参数文件拷贝到目的地主机

[oracle@dgmaster01 dbs]$ scp inittestdg.ora orapwtestdg oracle@192.168.100.2:/u01/app/oracle/product/11.2.0/db_1/dbs/

(2)目的地主机配置:
目的地主机不用创建实例(也可以创建实例,这样省去手动创建文件夹,两种方法根据自己喜好),只安装数据库软件,并用netca创建监听即可。
1、目的地主机 环境配置

[oracle@dgstandby02 ~]$ vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=testdg

2、配置listener.ora 增加实例的静态监听

[oracle@dgstandby02 ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dgmaster01)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /u01/app/oracle
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = testdg)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = testdg)
)
)

3、配置tnsnames.ora

[oracle@dgstandby02 ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
DGM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = testdg)
)
)

DGS =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = testdg)
)
)

4、tnsping 配置是否正确(源和目的地主机都要测试)

[oracle@dgmaster01 dbs]$  tnsping DGM

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 12-SEP-2015 21:29:17

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = testdg)))
OK (10 msec)

[oracle@dgmaster01 dbs]$  tnsping DGS

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 12-SEP-2015 21:29:17

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = testdg)))
OK (10 msec)

5、手工创建目录(根据你的参数配置创建)
oracle用户下执行

mkdir -p /u01/app/oracle/fast_recovery_area/testdg ##默认的归档日志、控制文件备份位置
mkdir -p /u01/app/oradata/testdg ##数据文件 控制文件、redolog 位置
mkdir -p /u01/app/oracle/admin/testdg/adump
mkdir -p /u01/app/oracle/admin/testdg/dpdump
mkdir -p /u01/app/oracle/admin/testdg/pfile

6、修改拷贝过来的参数文件inittestdg.ora (如果实例名称一样、路径也一样的话,参数文件内容不用修改,直接可用)

[oracle@dgstandby02 dbs]$ cat inittestdg.ora
testdg.__db_cache_size=687865856
testdg.__java_pool_size=16777216
testdg.__large_pool_size=33554432
testdg.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
testdg.__pga_aggregate_target=671088640
testdg.__sga_target=989855744
testdg.__shared_io_pool_size=0
testdg.__shared_pool_size=234881024
testdg.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/testdg/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oradata/testdg/control01.ctl','/u01/app/oracle/fast_recovery_area/testdg/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='testdg'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=8589934592
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=testdgXDB)'
*.memory_target=1656750080
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=335
*.undo_tablespace='UNDOTBS1'

6、启动到nomount状态

SQL> startup nomount pfile=/u01/app/oracle/product/11.2.0/db_1/dbs/inittestdg.ora;   
ORACLE instance started.

Total System Global Area 1653518336 bytes
Fixed Size                  2253784 bytes
Variable Size            1056967720 bytes
Database Buffers          587202560 bytes
Redo Buffers                7094272 bytes
SQL> 

(3)源主机操作(源主机Target库必须开启归档模式)
1、为了验证是否复制成功,我们在target源库插入两条数据

SQL> insert into emp (empno,ename) values (9000,'zhang');
SQL> insert into emp (empno,ename) values (8888,'WUJR');
SQL> commit;

2、开始复制数据库 Active database 模式

[oracle@dgmaster01 dbs]$ rman target sys/admin2012@DGM auxiliary sys/admin2012@DGS

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 9 10:20:30 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: TESTDG (DBID=2822661610)
connected to auxiliary database: TESTDG (not mounted)

RMAN> duplicate target database to testdg from active database nofilenamecheck;


##nofilenamecheck,target库与auxiliary 库 文件名都一致的情况下使用,否则会报错。

### 过程如下:
Starting Duplicate Db at 2015-09-09 10:20:39
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=246 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 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes

contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTDG'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''TESTDG'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
backup as copy current controlfile auxiliary format '/u01/app/oradata/testdg/control01.ctl';
restore clone controlfile to '/u01/app/oracle/fast_recovery_area/testdg/control02.ctl' from
'/u01/app/oradata/testdg/control01.ctl';
alter clone database mount;
}
executing Memory Script

sql statement: alter system set db_name = ''TESTDG'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set db_unique_name = ''TESTDG'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes

Starting backup at 2015-09-09 10:20:53
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 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_1/dbs/snapcf_testdg.f tag=TAG20150909T102054 RECID=2 STAMP=889957254
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-09-09 10:20:55

Starting restore at 2015-09-09 10:20:55
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=245 device type=DISK

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 2015-09-09 10:20:56

database mounted

contents of Memory Script:
{
set newname for datafile 1 to
"/u01/app/oradata/testdg/system01.dbf";
set newname for datafile 2 to
"/u01/app/oradata/testdg/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oradata/testdg/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oradata/testdg/users01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oradata/testdg/system01.dbf" datafile
2 auxiliary format
"/u01/app/oradata/testdg/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oradata/testdg/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oradata/testdg/users01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 2015-09-09 10:21:01
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oradata/testdg/system01.dbf
output file name=/u01/app/oradata/testdg/system01.dbf tag=TAG20150909T102101
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oradata/testdg/sysaux01.dbf
output file name=/u01/app/oradata/testdg/sysaux01.dbf tag=TAG20150909T102101
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oradata/testdg/undotbs01.dbf
output file name=/u01/app/oradata/testdg/undotbs01.dbf tag=TAG20150909T102101
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oradata/testdg/users01.dbf
output file name=/u01/app/oradata/testdg/users01.dbf tag=TAG20150909T102101
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-09-09 10:21:28

sql statement: alter system archive log current

contents of Memory Script:
{
backup as copy reuse
archivelog like "/u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_9_byz5x85r_.arc" auxiliary format
"/u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_9_%u_.arc" ;
catalog clone recovery area;
switch clone datafile all;
}
executing Memory Script

Starting backup at 2015-09-09 10:21:28
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=9 RECID=2 STAMP=889957288
output file name=/u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_9_07qgnat8_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 2015-09-09 10:21:29

searching for all files in the recovery area

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_9_07qgnat8_.arc
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_9_07qgnat8_.arc

datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=889957290 file name=/u01/app/oradata/testdg/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=889957290 file name=/u01/app/oradata/testdg/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=889957290 file name=/u01/app/oradata/testdg/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=889957290 file name=/u01/app/oradata/testdg/users01.dbf

contents of Memory Script:
{
set until scn 1046462;
recover
clone database
delete archivelog
;
}
executing Memory Script

executing command: SET until clause

Starting recover at 2015-09-09 10:21:29
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 9 is already on disk as file /u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_9_07qgnat8_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_9_07qgnat8_.arc thread=1 sequence=9
media recovery complete, elapsed time: 00:00:00
Finished recover at 2015-09-09 10:21:31
Oracle instance started

Total System Global Area 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes

contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTDG'' 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 = ''TESTDG'' 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 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TESTDG" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 SIZE 50 M ,
GROUP 2 SIZE 50 M ,
GROUP 3 SIZE 50 M
DATAFILE
'/u01/app/oradata/testdg/system01.dbf'
CHARACTER SET ZHS16GBK

contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oradata/testdg/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oradata/testdg/sysaux01.dbf",
"/u01/app/oradata/testdg/undotbs01.dbf",
"/u01/app/oradata/testdg/users01.dbf";
switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oradata/testdg/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oradata/testdg/sysaux01.dbf RECID=1 STAMP=889957304
cataloged datafile copy
datafile copy file name=/u01/app/oradata/testdg/undotbs01.dbf RECID=2 STAMP=889957304
cataloged datafile copy
datafile copy file name=/u01/app/oradata/testdg/users01.dbf RECID=3 STAMP=889957304

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=889957304 file name=/u01/app/oradata/testdg/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=889957304 file name=/u01/app/oradata/testdg/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=889957304 file name=/u01/app/oradata/testdg/users01.dbf

contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 2015-09-09 10:21:47

RMAN>;


3、在目的地数据库验证数据:

SQL> conn scott/tiger
Connected.
SQL> select empno,ename from emp;

     EMPNO ENAME
---------- ----------
      9000 zhang
      8000 WUJR
      7369 SMITH
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING

     EMPNO ENAME
---------- ----------
      7844 TURNER
      7876 ADAMS
      7900 JAMES
      7902 FORD
      7934 MILLER

16 rows selected.

二、示例二:不同的实例名(源testdg 目的地:testdg2)
(1)源主机配置

1、配置tnsnames.ora 增加一个tns配置

[oracle@dgmaster01 ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora 
DGM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = testdg)
    )
  )
 
DGS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = testdg)
    )
  )
DGS2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = testdg2)
    )
  )

2、将参数文件和密码文件拷贝到目的主机并命名为
inittestdg2.ora
orapwtestdg2

(2)目的地主机配置:
目的地主机不用创建实例(也可以创建实例,这样省去手动创建文件夹,两种方法根据自己喜好),只安装数据库软件,并用netca创建监听即可。
1、目的地主机 环境配置

[oracle@dgstandby02 ~]$ vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=testdg2

2、配置listener.ora 增加实例的静态监听

[oracle@dgstandby02 admin]$ cat listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dgstandby02)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = testdg)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = testdg)
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = testdg2)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = testdg2)
    )
  )

3、配置tnsnames.ora

[oracle@dgmaster01 ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora 
DGM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = testdg)
    )
  )
 
DGS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = testdg)
    )
  )
DGS2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = testdg2)
    )
  )

4、tnsping 配置是否正确(源和目的地主机都要测试)

[oracle@dgmaster01 dbs]$  tnsping DGM

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 12-SEP-2015 21:29:17

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = testdg)))
OK (10 msec)

[oracle@dgmaster01 dbs]$  tnsping DGS2

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 12-SEP-2015 21:29:17

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = testdg2)))
OK (10 msec)

5、手工创建目录(根据你的参数配置创建)
oracle用户下执行

mkdir -p /u01/app/oracle/fast_recovery_area/testdg2 ##默认的归档日志、控制文件备份位置
mkdir -p /u01/app/oradata/testdg2 ##数据文件 控制文件、redolog 位置
mkdir -p /u01/app/oracle/admin/testdg2/adump
mkdir -p /u01/app/oracle/admin/testdg2/dpdump
mkdir -p /u01/app/oracle/admin/testdg2/pfile

6、开始复制数据库

[oracle@dgmaster01 dbs]$ rman target sys/admin2012@DGM auxiliary sys/admin2012@DGS2

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 9 13:48:41 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: TESTDG (DBID=2822661610)
connected to auxiliary database: TESTDG2 (not mounted)

RMAN> duplicate target database to testdg2 from active database;

###过程如下:
Starting Duplicate Db at 2015-09-09 13:49:07
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=10 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 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes

contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTDG'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''TESTDG2'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
backup as copy current controlfile auxiliary format '/u01/app/oradata/testdg2/control01.ctl';
restore clone controlfile to '/u01/app/oracle/fast_recovery_area/testdg2/control02.ctl' from
'/u01/app/oradata/testdg2/control01.ctl';
alter clone database mount;
}
executing Memory Script

sql statement: alter system set db_name = ''TESTDG'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set db_unique_name = ''TESTDG2'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes

Starting backup at 2015-09-09 13:49:24
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 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_1/dbs/snapcf_testdg.f tag=TAG20150909T134925 RECID=5 STAMP=889969765
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-09-09 13:49:26

Starting restore at 2015-09-09 13:49:26
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=245 device type=DISK

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 2015-09-09 13:49:27

database mounted

contents of Memory Script:
{
set newname for datafile 1 to
"/u01/app/oradata/testdg2/system01.dbf";
set newname for datafile 2 to
"/u01/app/oradata/testdg2/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oradata/testdg2/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oradata/testdg2/users01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oradata/testdg2/system01.dbf" datafile
2 auxiliary format
"/u01/app/oradata/testdg2/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oradata/testdg2/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oradata/testdg2/users01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 2015-09-09 13:49:32
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oradata/testdg/system01.dbf
output file name=/u01/app/oradata/testdg2/system01.dbf tag=TAG20150909T134932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oradata/testdg/sysaux01.dbf
output file name=/u01/app/oradata/testdg2/sysaux01.dbf tag=TAG20150909T134932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oradata/testdg/undotbs01.dbf
output file name=/u01/app/oradata/testdg2/undotbs01.dbf tag=TAG20150909T134932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oradata/testdg/users01.dbf
output file name=/u01/app/oradata/testdg2/users01.dbf tag=TAG20150909T134932
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-09-09 13:49:59

sql statement: alter system archive log current

contents of Memory Script:
{
backup as copy reuse
archivelog like "/u01/app/oracle/fast_recovery_area/TESTDG/archivelog/2015_09_09/o1_mf_1_11_byzl477g_.arc" auxiliary format
"/u01/app/oracle/fast_recovery_area/TESTDG2/archivelog/2015_09_09/o1_mf_1_11_%u_.arc" ;
catalog clone recovery area;
switch clone datafile all;
}
executing Memory Script

Starting backup at 2015-09-09 13:49:59
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=11 RECID=4 STAMP=889969799
output file name=/u01/app/oracle/fast_recovery_area/TESTDG2/archivelog/2015_09_09/o1_mf_1_11_0kqgnn47_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 2015-09-09 13:50:00

searching for all files in the recovery area

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/fast_recovery_area/TESTDG2/archivelog/2015_09_09/o1_mf_1_11_0kqgnn47_.arc
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/TESTDG2/archivelog/2015_09_09/o1_mf_1_11_0kqgnn47_.arc

datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=889969801 file name=/u01/app/oradata/testdg2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=889969801 file name=/u01/app/oradata/testdg2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=889969801 file name=/u01/app/oradata/testdg2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=889969801 file name=/u01/app/oradata/testdg2/users01.dbf

contents of Memory Script:
{
set until scn 1052427;
recover
clone database
delete archivelog
;
}
executing Memory Script

executing command: SET until clause

Starting recover at 2015-09-09 13:50:00
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 11 is already on disk as file /u01/app/oracle/fast_recovery_area/TESTDG2/archivelog/2015_09_09/o1_mf_1_11_0kqgnn47_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/TESTDG2/archivelog/2015_09_09/o1_mf_1_11_0kqgnn47_.arc thread=1 sequence=11
media recovery complete, elapsed time: 00:00:00
Finished recover at 2015-09-09 13:50:01
Oracle instance started

Total System Global Area 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes

contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTDG2'' 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 = ''TESTDG2'' 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 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1073744936 bytes
Database Buffers 570425344 bytes
Redo Buffers 7094272 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TESTDG2" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oradata/testdg2/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oradata/testdg2/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oradata/testdg2/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oradata/testdg2/system01.dbf'
CHARACTER SET ZHS16GBK

contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oradata/testdg2/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oradata/testdg2/sysaux01.dbf",
"/u01/app/oradata/testdg2/undotbs01.dbf",
"/u01/app/oradata/testdg2/users01.dbf";
switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oradata/testdg2/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oradata/testdg2/sysaux01.dbf RECID=1 STAMP=889969813
cataloged datafile copy
datafile copy file name=/u01/app/oradata/testdg2/undotbs01.dbf RECID=2 STAMP=889969813
cataloged datafile copy
datafile copy file name=/u01/app/oradata/testdg2/users01.dbf RECID=3 STAMP=889969813

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=889969813 file name=/u01/app/oradata/testdg2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=889969813 file name=/u01/app/oradata/testdg2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=889969813 file name=/u01/app/oradata/testdg2/users01.dbf

contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 2015-09-09 13:50:18

RMAN>

发表评论