码迷,mamicode.com
首页 > 数据库 > 详细

数据库迁移(分享十一续集)

时间:2017-11-27 13:29:27      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:init   max   备份   none   char   fixed   lease   set   rod   

          上集主要讲解了oracle自身导入导出功能,本集讲解rman这个工具。

           Oracle 11gR2 使用RMAN Duplicate复制数据库、通过备份恢复方式来迁移数据库。

 

Active database duplicate 功能强大,不需要先把目标数据库进行rman备份,只要目标数据库处于归档模式下即可直接通过网络对数据库进行copy,且copy完成后自动open数据库。这对于大数据特别是T级别的数据库来说优点非常明显,复制前不需要进行备份,减少了备份和传送备份的时间,同时节省备份空间。下面来进行具体的duplicate操作。

应用场景:

 

 

技术分享图片

           Active database duplicate 功能强大,不需要先把目标数据库进行rman备份,只要目标数据库处于归档模式下即可直接通过网络对数据库进行copy,且copy完成后自动open数据库。这对于大数据特别是T级别的数据库来说优点非常明显,复制前不需要进行备份,减少了备份和传送备份的时间,同时节省备份空间。下面来进行具体的duplicate操作。

应用场景:文件路径一样,旧库可以使用并且网络顺畅

实验环境:

target db:

ip 192.168.56.1

oracle_sid=test

oracle_version=11.2.0.3

auxiliary db:

ip 192.168.56.2

oracle_sid=test

oracle_version=11.2.0.3

在新库创建参数文件并启动实例到nomount状态

--auxiliary db上执行

[oracle@localhost ~]$ cat initoradu.ora

db_name=test

db_block_size=8192

 

[oracle@localhost ~]$ export ORACLE_SID=test

[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/inittest、.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/orapwtest oracle@192.168.56.150:/u01/app/oracle/product/11.2.0/db/dbs/orapwtest

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=test)

    )

  )

  vi /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora

  test =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = test)

      (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 = test)

    )

  )

  vi /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora

  test =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = test)

      (SERVER = DEDICATED)

    )

  )

  --重启两台机器的监听

  lsnrctl stop

  lsnrctl start

4、开始复制

--在target db上执行

[oracle@localhost ~]$ rman target / auxiliary sys/123456@test

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: test(not mounted)

RMAN> duplicate target database to test 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";

   set newname for datafile  5 to

"/u01/app/oracle/oradata/oradu/test.dbf";

   set newname for datafile  6 to

"/u01/app/oracle/oradata/oradu/store_01.dbf";

   set newname for datafile  7 to

"/u01/app/oracle/oradata/oradu/store_02.dbf";

   set newname for datafile  8 to

"/u01/app/oracle/oradata/oradu/pitr01.dbf";

   backup as copy reuse

   datafile  1 auxiliary format

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

2 auxiliary format

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

3 auxiliary format

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

4 auxiliary format

"/u01/app/oracle/oradata/oradu/users01.dbf"   datafile

5 auxiliary format

"/u01/app/oracle/oradata/oradu/test.dbf"   datafile

6 auxiliary format

"/u01/app/oracle/oradata/oradu/store_01.dbf"   datafile

7 auxiliary format

"/u01/app/oracle/oradata/oradu/store_02.dbf"   datafile

8 auxiliary format

"/u01/app/oracle/oradata/oradu/pitr01.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

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 20-MAR-16

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

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

output file name=/u01/app/oracle/oradata/oradu/system01.dbf tag=TAG20160320T141004

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

channel ORA_DISK_1: starting datafile copy

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

output file name=/u01/app/oracle/oradata/oradu/sysaux01.dbf tag=TAG20160320T141004

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

channel ORA_DISK_1: starting datafile copy

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

output file name=/u01/app/oracle/oradata/oradu/undotbs01.dbf tag=TAG20160320T141004

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

channel ORA_DISK_1: starting datafile copy

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

output file name=/u01/app/oracle/oradata/oradu/users01.dbf tag=TAG20160320T141004

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

channel ORA_DISK_1: starting datafile copy

input datafile file number=00007 name=/u01/app/oracle/oradata/mydb/store_02.dbf

output file name=/u01/app/oracle/oradata/oradu/store_02.dbf tag=TAG20160320T141004

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

channel ORA_DISK_1: starting datafile copy

input datafile file number=00005 name=/u01/app/oracle/oradata/mydb/test.dbf

output file name=/u01/app/oracle/oradata/oradu/test.dbf tag=TAG20160320T141004

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

channel ORA_DISK_1: starting datafile copy

input datafile file number=00006 name=/u01/app/oracle/oradata/mydb/store_01.dbf

output file name=/u01/app/oracle/oradata/oradu/store_01.dbf tag=TAG20160320T141004

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

channel ORA_DISK_1: starting datafile copy

input datafile file number=00008 name=/u01/app/oracle/oradata/mydb/pitr01.dbf

output file name=/u01/app/oracle/oradata/oradu/pitr01.dbf tag=TAG20160320T141004

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

Finished backup at 20-MAR-16

sql statement: alter system archive log current

contents of Memory Script:

{

   backup as copy reuse

   archivelog like  "/u01/app/oracle/product/11.2.0/db/dbs/arch/1_22_906314379.dbf" auxiliary format

"/u01/app/oracle/product/11.2.0/db/dbs/arch1_22_906314379.dbf"   ;

   catalog clone archivelog  "/u01/app/oracle/product/11.2.0/db/dbs/arch1_22_906314379.dbf";

   switch clone datafile all;

}

executing Memory Script

Starting backup at 20-MAR-16

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log copy

input archived log thread=1 sequence=22 RECID=44 STAMP=906991972

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

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

Finished backup at 20-MAR-16

cataloged archived log

archived log file name=/u01/app/oracle/product/11.2.0/db/dbs/arch1_22_906314379.dbf RECID=44 STAMP=906989788

datafile 1 switched to datafile copy

input datafile copy RECID=31 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=32 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=33 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=34 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=35 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/test.dbf

datafile 6 switched to datafile copy

input datafile copy RECID=36 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/store_01.dbf

datafile 7 switched to datafile copy

input datafile copy RECID=37 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/store_02.dbf

datafile 8 switched to datafile copy

input datafile copy RECID=38 STAMP=906989788 file name=/u01/app/oracle/oradata/oradu/pitr01.dbf

contents of Memory Script:

{

   set until scn  2809336;

   recover

   clone database

    delete archivelog

   ;

}

executing Memory Script

executing command: SET until clause

Starting recover at 20-MAR-16

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 22 is already on disk as file /u01/app/oracle/product/11.2.0/db/dbs/arch1_22_906314379.dbf

archived log file name=/u01/app/oracle/product/11.2.0/db/dbs/arch1_22_906314379.dbf thread=1 sequence=22

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

Finished recover at 20-MAR-16

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 =

‘‘ORADU‘‘ 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 =  ‘‘ORADU‘‘ 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     238034944 bytes

Fixed Size                     2227136 bytes

Variable Size                180356160 bytes

Database Buffers              50331648 bytes

Redo Buffers                   5120000 bytes

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

  MAXLOGFILES     16

  MAXLOGMEMBERS      3

  MAXDATAFILES      100

  MAXINSTANCES     8

  MAXLOGHISTORY      292

LOGFILE

  GROUP   1 ( ‘/u01/app/oracle/oradata/oradu/redo01.log‘, ‘/u01/app/oracle/oradata/oradu/redo01_01.log‘ ) SIZE 100 M  REUSE,

  GROUP   2 ( ‘/u01/app/oracle/oradata/oradu/redo02.log‘, ‘/u01/app/oracle/oradata/oradu/redo02_01.log‘ ) SIZE 100 M  REUSE,

  GROUP   3 ( ‘/u01/app/oracle/oradata/oradu/redo03.log‘, ‘/u01/app/oracle/oradata/oradu/redo03_01.log‘ ) SIZE 100 M  REUSE,

  GROUP   4 ( ‘/u01/app/oracle/oradata/oradu/redo04.log‘, ‘/u01/app/oracle/oradata/oradu/redo04_01.log‘ ) SIZE 100 M  REUSE

DATAFILE

  ‘/u01/app/oracle/oradata/oradu/system01.dbf‘

CHARACTER SET ZHS16GBK

contents of Memory Script:

{

   set newname for tempfile  1 to

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

   switch clone tempfile all;

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

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

"/u01/app/oracle/oradata/oradu/users01.dbf",

"/u01/app/oracle/oradata/oradu/test.dbf",

"/u01/app/oracle/oradata/oradu/store_01.dbf",

"/u01/app/oracle/oradata/oradu/store_02.dbf",

"/u01/app/oracle/oradata/oradu/pitr01.dbf";

   switch clone datafile all;

}

executing Memory Script

executing command: SET NEWNAME

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

cataloged datafile copy

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

cataloged datafile copy

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

cataloged datafile copy

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

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/oradu/test.dbf RECID=4 STAMP=906989800

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/oradu/store_01.dbf RECID=5 STAMP=906989800

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/oradu/store_02.dbf RECID=6 STAMP=906989800

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/oradu/pitr01.dbf RECID=7 STAMP=906989800

datafile 2 switched to datafile copy

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

datafile 3 switched to datafile copy

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

datafile 4 switched to datafile copy

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

datafile 5 switched to datafile copy

input datafile copy RECID=4 STAMP=906989800 file name=/u01/app/oracle/oradata/oradu/test.dbf

datafile 6 switched to datafile copy

input datafile copy RECID=5 STAMP=906989800 file name=/u01/app/oracle/oradata/oradu/store_01.dbf

datafile 7 switched to datafile copy

input datafile copy RECID=6 STAMP=906989800 file name=/u01/app/oracle/oradata/oradu/store_02.dbf

datafile 8 switched to datafile copy

input datafile copy RECID=7 STAMP=906989800 file name=/u01/app/oracle/oradata/oradu/pitr01.dbf

Reenabling controlfile options for auxiliary database

Executing: alter database add supplemental log data

contents of Memory Script:

{

   Alter clone database open resetlogs;

}

executing Memory Script

database opened

Finished Duplicate Db at 20-MAR-16

RMAN>

5、验证是否迁移成功

--在auxiliary db 执行

SQL> select name,open_mode from v$database;

 

NAME      OPEN_MODE

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

test     READ WRITE

以上迁移就完成

数据库迁移(分享十一续集)

标签:init   max   备份   none   char   fixed   lease   set   rod   

原文地址:http://www.cnblogs.com/zywu-king/p/7903592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!