通过RMAN duplicate迁移数据库(单机到单机)

时间:2022-05-01 06:36:34

客户要求搭建一套测试库,现在环境是window下oracle RAC,使用能使用导入导出最好,但是目前是归档模式,使用导入导出风险太大,使用RMAN备份服务器上没有足够的空间。好吧,最好的方法就是RMAN duplicate的方法了。先在单机环境测试一下!

Oracle 11gRMAN duplicate 可以通过Activedatabase duplicateBackup-based duplicate两种方法实现。本案例使用的是Active database duplicate,对于Active databaseduplicate来说,在克隆数据库时不用对Source备份,这对于大数据特别是T级别的数据库来说优点非常明显,复制前不需要进行备份,减少了备份和传送备份的时间,同时节省备份空间。

本次测试将PROD2数据库复制到另外一台服务器上,名称为PROD5

查看源库信息

源库必须为归档模式,并启用快速恢复区;确认数据文件和日志文件路径!

 [oracle@orar2p1 ~]$ sqlplus / as sysdba

SQL*Plus:Release 11.2.0.3.0 Production on Tue Sep 5 14:56:01 2017

Copyright (c)1982, 2011, Oracle.  All rights reserved.

Connected to:

Oracle Database11g Enterprise Edition Release 11.2.0.3.0 - Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

 

SYS@PROD2>selectstatus from v$instance;

 

STATUS

------------

OPEN

 

SYS@PROD2>selectname from v$datafile;

 

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/PROD2/system01.dbf

/u01/app/oracle/oradata/PROD2/sysaux01.dbf

/u01/app/oracle/oradata/PROD2/undotbs01.dbf

/u01/app/oracle/oradata/PROD2/users01.dbf

/u01/app/oracle/oradata/PROD2/example01.dbf

 

SYS@PROD2>selectmember from v$logfile;

 

MEMBER

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/PROD2/redo03.log

/u01/app/oracle/oradata/PROD2/redo02.log

/u01/app/oracle/oradata/PROD2/redo01.log

SYS@PROD2>showparameter name

 

NAME                                 TYPE        VALUE

----------------------------------------------- ------------------------------

db_file_name_convert                 string

db_name                              string      PROD2

db_unique_name                       string      PROD2

global_names                         boolean     FALSE

instance_name                        string      PROD2

lock_name_space                      string

log_file_name_convert                string

processor_group_name                 string

service_names                        string      PROD2.us.oracle.com

构建测试库PROD5

1)生成测试库pfile

可以将源库的pfile拷贝过来,将名称替换,也可以重新生成pfile,下面是重新生成的!

[oracle@orar2p2dbs]$ cat init.ora | grep -v ^#| grep -v ^$ >initPROD5.ora

[oracle@orar2p2dbs]$ vi initPROD5.ora

db_name='PROD5'

memory_target=1G

processes = 150

audit_file_dest='$ORACLE_BASE/admin/PROD5/adump'

audit_trail='db'

db_block_size=8192

db_domain='us.oracle.com'

db_recovery_file_dest='$ORACLE_BASE/fast_recovery_area'

db_recovery_file_dest_size=2G

diagnostic_dest='$ORACLE_BASE'

dispatchers='(PROTOCOL=TCP)(SERVICE=PROD5XDB)'

open_cursors=300

remote_login_passwordfile='EXCLUSIVE'

undo_tablespace='UNDOTBS1'    此处必须和源库名称一样!

control_files ='/u01/app/oracle/oradata/PROD5/ora_control01.ctl','/u01/app/oracle/fast_recovery_area/PROD5/ora_control02.ctl'

compatible='11.2.0'

db_file_name_convert='/u01/app/oracle/oradata/PROD2/','/u01/app/oracle/oradata/PROD5/'

log_file_name_convert='/u01/app/oracle/oradata/PROD2/','/u01/app/oracle/oradata/PROD5/','/u01/app/oracle/fast_recovery_area/PROD2/onlinelog/','/u01/app/oracle/fast_recovery_area/PROD5/'(日志文件的对应关系必须确认好,否则会报错)

2)创建测试库相关目录(根据pfile信息创建相关目录)

[oracle@orar2p2oradata]$ mkdir PROD5

[oracle@orar2p2oradata]$ cd ../admin

[oracle@orar2p2admin]$ mkdir -p PROD5/adump

 

3)生成口令文件  可以直接将源库的密码文件拷贝过来,或者重新生成,但是两边的密码必须一致!

 

oracle@orar2p2dbs]$ orapwd file=orapwPROD5 password=oracle entries=30

传输参数文件scp initPROD2.ora oracle@192.0.2.12:/u01/app/oracle/product/11.2.0/db_1/dbs

传输密码文件scp orapwPROD2 oracle@192.0.2.12:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwPROD5

测试库启动到nomout状态

[oracle@orar2p2admin]$ export ORACLE_SID=PROD5

[oracle@orar2p2admin]$ sqlplus / as sysdba

SQL*Plus:Release 11.2.0.3.0 Production on Tue Sep 5 08:35:48 2017

Copyright (c)1982, 2011, Oracle.  All rights reserved.

Connected to anidle instance.

SYS@PROD5>startupnomount

配置监听

两端都要配置源库和目标库的监听和tnsname.ora

源库静态监听信息

SID_LIST_LISTENER=

  (SID_LIST=

    (SID_DESC=

      (GLOBAL_DBNAME=PROD2.us.oracle.com)

     (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)

      (SID_NAME=PROD2))

   )

源库tnsnames.ora配置信息

PROD2 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = orar2p1.example.com)(PORT= 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = PROD2.us.oracle.com)

    )

  )

PROD5 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = orar2p2.example.com)(PORT= 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = PROD5.us.oracle.com)

    )

  )

目标库静态监听信息

SID_LIST_LISTENER=

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME =PROD5.us.oracle.com)

      (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1)

      (SID_NAME =PROD5)

    )

  )

目标库tnsnames.ora配置信息

PROD2 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = orar2p1.example.com)(PORT= 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = PROD2.us.oracle.com)

    )

  )

PROD5 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = orar2p2.example.com)(PORT= 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = PROD5.us.oracle.com)

    )

  )

 

 

 

在源库PROD2启动rman,复制数据库

开始数据库复制

[oracle@orar2p2admin]$ rman target sys/oracle@prod2 auxiliary sys/oracle@prod5

 

RecoveryManager: Release 11.2.0.3.0 - Production on Tue Sep 5 08:26:17 2017

 

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

 

connected totarget database: PROD2 (DBID=1512727797)

connected toauxiliary database: PROD5 (not mounted)

 

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

duplicate targetdatabase to prod from active database nofilenamecheck;

--如果主备库文件路径不变,要加nofilenamecheck(否则会报错)

 

验证克隆

[oracle@orar2p2admin]$ sql

 

SQL*Plus:Release 11.2.0.3.0 Production on Tue Sep 5 08:41:35 2017

 

Copyright (c)1982, 2011, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database11g Enterprise Edition Release 11.2.0.3.0 - Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

 

SYS@PROD5>selectstatus from v$instance;

 

STATUS

------------

OPEN

 

SYS@PROD5>selectname from v$datafile;

 

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/PROD5/system01.dbf

/u01/app/oracle/oradata/PROD5/sysaux01.dbf

/u01/app/oracle/oradata/PROD5/undotbs01.dbf

/u01/app/oracle/oradata/PROD5/users01.dbf

/u01/app/oracle/oradata/PROD5/example01.dbf

 

SYS@PROD5>selectmember from v$logfile;

 

MEMBER

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/PROD5/redo03.log

/u01/app/oracle/oradata/PROD5/redo02.log

/u01/app/oracle/oradata/PROD5/redo01.log

 

SYS@PROD5>showparameter control

 

NAME                                 TYPE        VALUE

----------------------------------------------- ------------------------------

_optimizer_extended_stats_usage_continteger     192

rol

_optimizer_join_order_control        integer     3

control_file_record_keep_time        integer     7

control_files                        string      /u01/app/oracle/oradata/PROD5/

                                                 ora_control01.ctl,/u01/app/or

                                                acle/fast_recovery_area/PROD5/

                                                ora_control02.ctl

control_management_pack_access       string      DIAGNOSTIC+TUNING

SYS@PROD5>


本文出自 “海阔天空” 博客,请务必保留此出处http://1146695.blog.51cto.com/1136695/1965852