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

我们看一个完整的复制示例:

Target DB:

IP: 192.168.2.42

SID:orcl

Auxiliary:

IP:192.168.2.43

SID:orcl

我这里复制的目录相同。 如果不同的话需要在pfile里面加入db_file_name_convert和log_file_name_convert.

1.在Auxiliary创建pfile参数文件:

[Oracle@qs-dmm-rh2 dbs]$ pwd

/u01/app/oracle/product/11.2.0/dbhome_1/dbs

[oracle@qs-dmm-rh2 dbs]$ cat initorcl.ora

DB_NAME=orcl

只有一个参数:DB_NAME

2.在Auxiliary库上创建口令文件

[oracle@qs-dmm-rh2 admin]$ orapwd file=?/dbs/orapworcl password=oracle

3.在Auxiliary库创建相关的目录结构:

[oracle@qs-dmm-rh2 trace]$ mkdir -p /u01/app/oracle/oradata/orcl

不然在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状态:

[oracle@qs-dmm-rh2 admin]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Tue Mar 8 00:28:48 2011

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

SQL> conn / as sysdba;

Connected to an idle instance.

SQL> startup nomount pfile=?/dbs/initorcl.ora

ORACLE instance started.

Total System Global Area146472960 bytes

Fixed Size1335080 bytes

Variable Size92274904 bytes

Database Buffers50331648 bytes

Redo Buffers2531328 bytes

SQL>

5.在Target和Auxiliary都配置Oracle Net(Listener.ora and tnsnames.ora):

[oracle@www.linuxidc.com admin]$cat listener.ora

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = localhost6.localdomain6)(PORT = 1521))

)

)

ADR_BASE_LISTENER = /u01/app/oracle

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = orcl)

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

(SID_NAME = orcl)

)

)

[oracle@www.linuxidc.com admin]$ cat tnsnames.ora

ORCL_ST =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.43)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = orcl)

)

)

ORCL_PD =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.42)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = orcl)

)

)

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@qs-dmm-rh2 dbs]$ rman target sys/oracle@orcl_pd auxiliary sys/oracle@orcl_st

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 8 01:01:42 2011

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

connected to target database: ORCL (DBID=1272955137)

connected to auxiliary database: ORCL (not mounted)

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

Starting Duplicate Db at 08-MAR-11

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 Area146472960 bytes

Fixed Size1335080 bytes

Variable Size92274904 bytes

Database Buffers50331648 bytes

Redo Buffers2531328 bytes

contents of Memory Script:

{

sql clone "alter system setdb_name =

''ORCL'' comment=

''Modified by RMAN duplicate'' scope=spfile";

sql clone "alter system setdb_unique_name =

''ORCL'' 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/dbhome_1/dbs/cntrlorcl.dbf';

alter clone database mount;

}

executing Memory Script

sql statement: alter system setdb_name =''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system setdb_unique_name =''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area146472960 bytes

Fixed Size1335080 bytes

Variable Size92274904 bytes

Database Buffers50331648 bytes

Redo Buffers2531328 bytes

Starting backup at 08-MAR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=43 device type=DISK

channel ORA_DISK_1: starting datafile copy

copying current control file

output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f tag=TAG20110308T010214 RECID=3 STAMP=745203735

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 08-MAR-11

database mounted

contents of Memory Script:

{

set newname for datafile1 to

"/u01/app/oracle/oradata/orcl/system01.dbf";

set newname for datafile2 to

"/u01/app/oracle/oradata/orcl/sysaux01.dbf";

set newname for datafile3 to

"/u01/app/oracle/oradata/orcl/undotbs01.dbf";

set newname for datafile4 to

"/u01/app/oracle/oradata/orcl/users01.dbf";

backup as copy reuse

datafile1 auxiliary format

"/u01/app/oracle/oradata/orcl/system01.dbf"datafile

2 auxiliary format

"/u01/app/oracle/oradata/orcl/sysaux01.dbf"datafile

3 auxiliary format

"/u01/app/oracle/oradata/orcl/undotbs01.dbf"datafile

4 auxiliary format

"/u01/app/oracle/oradata/orcl/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 08-MAR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

--在这里开始copy数据文件,比较慢。

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

output file name=/u01/app/oracle/oradata/orcl/system01.dbf tag=TAG20110308T010221

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

output file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf tag=TAG20110308T010221

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

output file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf tag=TAG20110308T010221

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

output file name=/u01/app/oracle/oradata/orcl/users01.dbf tag=TAG20110308T010221

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 08-MAR-11

sql statement: alter system archive log current

contents of Memory Script:

{

backup as copy reuse

archivelog like"/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_03_08/o1_mf_1_7_6qb3zyoo_.arc" auxiliary format

"/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf";

catalog clone archivelog"/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf";

switch clone datafile all;

}

executing Memory Script

Starting backup at 08-MAR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log copy

input archived log thread=1 sequence=7 RECID=3 STAMP=745203841

output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf RECID=0 STAMP=0

channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:07

Finished backup at 08-MAR-11

cataloged archived log

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf RECID=3 STAMP=745203848

datafile 1 switched to datafile copy

input datafile copy RECID=3 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=4 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=5 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=6 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/users01.dbf

contents of Memory Script:

{

set until scn844147;

recover

clone database

delete archivelog

;

}

executing Memory Script

executing command: SET until clause

Starting recover at 08-MAR-11

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=18 device type=DISK

starting media recovery

archived log for thread 1 with sequence 7 is already on disk as file /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf thread=1 sequence=7

media recovery complete, elapsed time: 00:00:01

Finished recover at 08-MAR-11

contents of Memory Script:

{

shutdown clone immediate;

startup clone nomount;

sql clone "alter system setdb_name =

''ORCL'' comment=

''Reset to original value by RMAN'' scope=spfile";

sql clone "alter system resetdb_unique_name scope=spfile";

shutdown clone immediate;

startup clone nomount;

}

executing Memory Script

database dismounted

Oracle instance shut down

connected to auxiliary database (not started)

Oracle instance started

Total System Global Area146472960 bytes

Fixed Size1335080 bytes

Variable Size92274904 bytes

Database Buffers50331648 bytes

Redo Buffers2531328 bytes

sql statement: alter system setdb_name =''ORCL'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system resetdb_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)

Oracle instance started

Total System Global Area146472960 bytes

Fixed Size1335080 bytes

Variable Size92274904 bytes

Database Buffers50331648 bytes

Redo Buffers2531328 bytes

sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS ARCHIVELOG

MAXLOGFILES16

MAXLOGMEMBERS3

MAXDATAFILES100

MAXINSTANCES8

MAXLOGHISTORY292

LOGFILE

GROUP1 ( '/u01/app/oracle/oradata/orcl/redo01.log' ) SIZE 50 MREUSE,

GROUP2 ( '/u01/app/oracle/oradata/orcl/redo02.log' ) SIZE 50 MREUSE,

GROUP3 ( '/u01/app/oracle/oradata/orcl/redo03.log' ) SIZE 50 MREUSE

DATAFILE

'/u01/app/oracle/oradata/orcl/system01.dbf'

CHARACTER SET ZHS16GBK

contents of Memory Script:

{

set newname for tempfile1 to

"/u01/app/oracle/oradata/orcl/temp01.dbf";

switch clone tempfile all;

catalog clone datafilecopy"/u01/app/oracle/oradata/orcl/sysaux01.dbf",

"/u01/app/oracle/oradata/orcl/undotbs01.dbf",

"/u01/app/oracle/oradata/orcl/users01.dbf";

switch clone datafile all;

}

executing Memory Script

executing command: SET NEWNAME

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

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf RECID=1 STAMP=745203867

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf RECID=2 STAMP=745203867

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/users01.dbf RECID=3 STAMP=745203867

datafile 2 switched to datafile copy

input datafile copy RECID=1 STAMP=745203867 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=2 STAMP=745203867 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=3 STAMP=745203867 file name=/u01/app/oracle/oradata/orcl/users01.dbf

contents of Memory Script:

{

Alter clone database open resetlogs;

}

executing Memory Script

database opened

Finished Duplicate Db at 08-MAR-11

RMAN>

复制结束。 查询:

Target库:

SQL> select name,dbid from v$database;

NAMEDBID

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

ORCL1272955137

Auxiliary库:

SQL> select name,dbid from v$database;

NAMEDBID

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

ORCL12729846020b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值