当前位置:数据库 > Oracle >>

Oracle 11gR2使用RMAN duplicate from active database复制数据库

Oracle 11gR2使用RMAN duplicate from active database复制数据库
 
在Oracle 10g下,我们可以使用RMAN duplicate 命令创建一个具有不同DBID 的复制库。到了Oracle 11gR2,RMAN 的duplicate 有2种方法实现:
  1. Active database duplication 
  2. Backup-based duplication
 
Active database duplication 通过网络,直接copy target 库到auxiliary 库,然后创建复制库。 这种方法就不需要先用RMAN 备份数据库,然后将备份文件发送到auxiliary端。这个功能的作用是非常大的。 尤其是对T级别的库。 因为对这样的库进行备份,然后将备份集发送到备库,在进行duplicate 的代价是非常大的。 一备份要占用时间,二要占用备份空间,三在网络传送的时候,还需要占用带宽和时间。所以Active database duplicate 很好的解决了以上的问题。 它对大库的迁移非常有用。
 
如果是从RAC duplicate 到单实例,操作是一样的。 如果是从单实例duplicate 到RAC。 那么先duplicate 到 单实例。 然后将单实例转换成RAC。 
 
下面我们看一下11gR2下,Active Database Duplicate的步骤如下:
1. 创建Auxiliary 库的Initialization Parameter:
 
如果使用spfile,那么在pfile文件里只需要设置一个DB_NAME参数,其他参数会在duplicate 命令中自己设置。
 
如果使用pfile,那么需要设置如下参数:
 
DB_NAME 
CONTROL_FILES
DB_BLOCK_SIZE
DB_FILE_NAME_CONVERT
LOG_FILE_NAME_CONVERT
DB_RECOVERY_FILE_DEST

 

 
2. 在Auxiliary库创建Password File 文件 
对于Backup-based duplication,Password File 不是必须的,但是对于Active Database Duplication,Password File是必须的。因为Active Database Duplication 使用相同的SYSDBA 密码直接连接到auxiliary 库。 所以,确保target 和Auxiliary库的SYSDBA 密码一样很重要。 
 
当然,我们也可以在duplicate 命令中加上PASSWORD FILE 选项(也是默认值),这样RMAN 在copy 的时候也会从target 库把密码文件copy过来,如果auxiliary库上已经存在了Password file,那么该操作会重写那个文件。
 
如:
RMAN> DUPLICATE TARGET DATABASE TO orcl FROM ACTIVE DATABASE NOFILENAMECHECK PASSWORD FILE SPFILE;

 

 
3. 如果是windows 平台,还需要创建Database service:
% set ORACLE_SID=DAVE
% set ORACLE_HOME=E:/oracle/product/11.1.0/db_1
% oradim -NEW -SID orcl

 

 
4. 配置oracle net,修改listener.ora和tnsnames.ora 文件:
在Target 库和Auxiliary 都要修改。这个也可以使用netca 和netmgr命令配置。
Target: tnsnames.ora
orcl2_au =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.99.92)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl2)
    )
  )

Auxiliary: listener.ora
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = standby)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = orcl2)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl2)
    )
  )

 

 
5. 用第一步创建的pfile文件,将Auxiliary启动到nomout 状态。 然后进行Active Database duplicate。
 
我们看一个完整的复制示例:
 
我这里复制的目录相同。 如果不同的话需要在pfile里面加入db_file_name_convert和log_file_name_convert.
 
1. 在Auxiliary 创建pfile 参数文件:
[oracle@rhel5 dbs]$ cat initorcl.ora 
DB_NAME=orcl2

 

 
2. 在Auxiliary库上创建口令文件
[oracle@rhel5 dbs]$ orapwd file=?/dbs/orapworcl password=oracle

 

3. 在Auxiliary库创建相关的目录结构:
 
不然在duplicate时会报如下错误:
ORA-19505: failed to identify file "/u01/app/oracle/oradata/orcl/users01.dbf"
ORA-27040: file create error, unable to create file
 
4. 启动Auxiliary 到nomout 状态:
SQL> startup nomount pfile=?/dbs/initorcl.ora
 
5. 在Target 和Auxiliary 都配置Oracle Net(Listener.ora and tnsnames.ora):
Target: tnsnames.ora
orcl2_au =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.99.92)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl2)
    )
  )

Auxiliary: listener.ora
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = standby)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = orcl2)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl2)
    )
  )

 

 
6. 开始RMAN duplicate from active database:
注意:如果target 和 Auxiliary库的目录结构相同,记得加上nofilenamecheck参数,不然会报如下错误:
RMAN-05001: auxiliary file name /u01/app/oracle/oradata/orcl/users01.dbf conflicts with a file used by the target database
 
如果目录不同,在pfile里加如下2个参数进行转换:
db_file_name_convert
log_file_name_convert.

[oracle@rhel5 dbs]$ rman target / auxiliary sys/oracle@orcl2_au
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Oct 21 21:33:44 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL2 (DBID=810247392)
connected to auxiliary database: ORCL2 (not mounted)

RMAN> run { 
2> allocate channel prmy1 type disk;
3> allocate channel prmy2 type disk;
4> allocate channel prmy3 type disk; 
5> allocate auxiliary channel stby1 type disk; 
6> duplicate target database to orcl2 from active database nofilenamecheck spfile;
7> }

using target database control file instead of recovery catalog
allocated channel: prmy1
channel prmy1: SID=31 device type=DISK

allocated channel: prmy2
channel prmy2: SID=36 device type=DISK

allocated channel: prmy3
channel prmy3: SID=40 device type=DISK

allocated channel: stby1
channel stby1: SID=20 device type=DISK

Starting Duplicate Db at 21-OCT-13

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl2.ora' auxiliary format 
 '/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl2.ora'   ;
   sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl2.ora''";
}
executing Memory Script

Starting backup at 21-OCT-13
Finished backup at 21-OCT-13

sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl2.ora''

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''ORCL2'' comment=
 ''duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script
sql statement: alter system set  db_name =  ''ORCL2'' comment= ''duplicate'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     849530880 bytes


Fixed Size                     1339824 bytes
Variable Size                637537872 bytes
Database Buffers             205520896 bytes
Redo Buffers                   5132288 bytes
allocated channel: stby1
channel stby1: SID=19 device type=DISK

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''ORCL2'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 &#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,