Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2556066
  • 博文数量: 632
  • 博客积分: 10716
  • 博客等级: 上将
  • 技术积分: 8413
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-01 22:35
文章分类

全部博文(632)

文章存档

2019年(21)

2018年(4)

2017年(37)

2016年(22)

2015年(1)

2013年(12)

2012年(20)

2011年(19)

2010年(20)

2009年(285)

2008年(191)

分类: Oracle

2012-11-07 10:58:40

二、使用RMAN复制数据库

1、环境介绍:

主机1

操作系统

REDHAT5.5

IP地址

172.16.1.120

主机名

sigle

数据库版本

10.2.0.4

数据库名

orcl

DBID

1305151947

catalog

win_yjr

catalog用户

sigle/sigle

 

主机2

操作系统

REDHAT5.5

IP地址

172.16.1.121

主机名

clone_sigle

数据库版本

10.2.0.4

 

 

 

 

 

    本次试验的数据库系统文件存储采用raw方式,因此在进行复制前,为了确保恢复的有效性,已使用dd命令将clone_sigle上的raw设备原有数据信息全部清空一次。

源数据库SIDorcl

目标数据库SIDorclaux

2、本次复制试验目录:

    试验在同平台,同版本之间的数据快速迁移复制的另一种途径,保证在复制后的数据库中有源数据库中的数据。

3、实际操作过程:

    为了验证复制的完整性,在热备之前先创建一张验证表:sys.test_rman里面有一条数据。

SQL> select * from test_rman;

 

        T1 T2

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

         1 23-3 -12

 

SQL>

 

1)、启动源数据库到open状态

SQL*Plus: Release 10.2.0.4.0 - Production on 星期一 3 26 23:29:16 2012

 

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

 

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area  486539264 bytes

Fixed Size                  1268196 bytes

Variable Size             171968028 bytes

Database Buffers          306184192 bytes

Redo Buffers                7118848 bytes

Database mounted.

SQL> alter database open;

 

Database altered.

 

SQL>

 

2)、热备份源数据库

RMAN>  run {

2> configure controlfile autobackup on;

3> CONFIGURE BACKUP OPTIMIZATION on;

4>   backup as compressed backupset 

5>        format '/oracle/backup/backdb<%d_%s:%t:%p>.dbf'

6>        database

7>        include current controlfile;

8>  # Archive log Backup

9>  backup as compressed backupset

10>        format '/oracle/backup/archive<%d_%s:%t:%p>.dbf'

11>        archivelog all delete all input;

12>  }

 

old RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

 

old RMAN configuration parameters:

CONFIGURE BACKUP OPTIMIZATION ON;

new RMAN configuration parameters:

CONFIGURE BACKUP OPTIMIZATION ON;

new RMAN configuration parameters are successfully stored

 

Starting backup at 26-3 -12

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=1628 devtype=DISK

channel ORA_DISK_1: starting compressed full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=/dev/raw/raw1

input datafile fno=00002 name=/dev/raw/raw3

input datafile fno=00003 name=/dev/raw/raw2

input datafile fno=00004 name=/dev/raw/raw4

channel ORA_DISK_1: starting piece 1 at 26-3 -12

channel ORA_DISK_1: finished piece 1 at 26-3 -12

piece handle=/oracle/backup/backdb.dbf tag=TAG20120326T234601 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55

channel ORA_DISK_1: starting compressed full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

channel ORA_DISK_1: starting piece 1 at 26-3 -12

channel ORA_DISK_1: finished piece 1 at 26-3 -12

piece handle=/oracle/backup/backdb.dbf tag=TAG20120326T234601 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

Finished backup at 26-3 -12

 

Starting backup at 26-3 -12

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting compressed archive log backupset

channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=41 recid=7 stamp=778981619

channel ORA_DISK_1: starting piece 1 at 26-3 -12

channel ORA_DISK_1: finished piece 1 at 26-3 -12

piece handle=/oracle/backup/archive.dbf tag=TAG20120326T234659 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

channel ORA_DISK_1: deleting archive log(s)

archive log filename=/oracle/arch/1_41_777371211.dbf recid=7 stamp=778981619

Finished backup at 26-3 -12

 

Starting Control File and SPFILE Autobackup at 26-3 -12

piece handle=/oracle/db10g/dbs/c-1305151947-20120326-02 comment=NONE

Finished Control File and SPFILE Autobackup at 26-3 -12

 

RMAN>

 

3)、配置监听

    为了确保复制数据库时,在数据库没有启动的情况下能正常连接数目标数据库,需要对监听进行配置,进行静态注册,可以在两端都进行配置,为了保证配置正确,推荐使用oracle net mamager进行配置。使用命令netmgr来启动OUI。在LISTENER中配置数据库服务,如下图:

配置完成后,重启监听。

4)、并配置密码文件及创建相应的参数目录

 

5)、创建启动pfile文件

SQL> create pfile='/oracle/backup/initorclaux.ora' from spfile;

 

File created.

 

SQL>

 

6)、修改pfile文件

将其中的db_name 修改为:db_name='orclaux'

其他参数使用和源数据一样的路径和配置,因此不做修改。

 

7)、启动目标数据到nomount状态

[oracle@sigle backup]$ hostname
clone_sigle

[oracle@sigle backup]$ sq

[uniread] Loaded history (132 lines)

SQL*Plus: Release 10.2.0.4.0 - Production on 星期二 3 27 00:59:56 2012

 

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

 

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup nomount pfile='/oracle/backup/initorclaux.ora';

ORACLE instance started.

 

Total System Global Area  486539264 bytes

Fixed Size                  1268196 bytes

Variable Size             171968028 bytes

Database Buffers          306184192 bytes

Redo Buffers                7118848 bytes

SQL> show parameter name

 

NAME                                 TYPE                   VALUE

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

db_file_name_convert                 string

db_name                              string                 orclaux

db_unique_name                       string                 orclaux

global_names                         boolean                FALSE

instance_name                        string                 orclaux

lock_name_space                      string

log_file_name_convert                string

service_names                        string                 orclaux

SQL>

 

8)、连接源数据库及目标数据库

在源数据库端连接

[oracle@sigle backup]$ hostname

sigle

[oracle@sigle backup]$

[oracle@sigle ~]$ rman target /

[uniread] Loaded history (181 lines)

 

Recovery Manager: Release 10.2.0.4.0 - Production on 星期二 3 27 01:04:58 2012

 

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

 

connected to target database: ORCL (DBID=1305151947)

 

RMAN> CONNECT AUXILIARY sys/sysadmin@sigleaux

 

connected to auxiliary database: ORCLAUX (not mounted)

 

RMAN>

 

9)、复制数据库

    需要注意的是,如果目标数据库的数据文件位置与源数据库数据文件位置相同,在执行

DUPLICATE TARGET DATABASE TO orclaux后要加nofilenamecheck参数,否则报错:

RMAN-05001: auxiliary filename/dev/raw/raw1 conflicts with a file used by the target database

如果目标数据库的数据文件位置与源数据库数据文件位置不同,则需要加上DB_FILE_NAME_CONVERT参数来转换数据文件位置,例如:

DB_FILE_NAME_CONVERT=('/h1/oracle/dbs/trgt/','/h2/oracle/oradata/newdb/')

    注意,在命令执行过程中,目标数据库必须要保证没有连接,否则脚本执行到整个过程快结束,需要重启目标数据库时候挂住,直到现有连接全部退出。

RMAN> DUPLICATE TARGET DATABASE TO orclaux nofilenamecheck;

 

Starting Duplicate Db at 27-3 -12

using channel ORA_AUX_DISK_1

 

contents of Memory Script:

{

   set until scn  555341;

   set newname for datafile  1 to

 "/dev/raw/raw1";

   set newname for datafile  2 to

 "/dev/raw/raw3";

   set newname for datafile  3 to

 "/dev/raw/raw2";

   set newname for datafile  4 to

 "/dev/raw/raw4";

   restore

   check readonly

   clone database

   ;

}

executing Memory Script

 

executing command: SET until clause

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

Starting restore at 27-3 -12

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: starting datafile backupset restore

channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /dev/raw/raw1

restoring datafile 00002 to /dev/raw/raw3

restoring datafile 00003 to /dev/raw/raw2

restoring datafile 00004 to /dev/raw/raw4

channel ORA_AUX_DISK_1: reading from backup piece /oracle/backup/backdb.dbf

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/oracle/backup/backdb.dbf tag=TAG20120326T234601

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:35

Finished restore at 27-3 -12

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

  MAXLOGFILES     16

  MAXLOGMEMBERS      3

  MAXDATAFILES     1024

  MAXINSTANCES     8

  MAXLOGHISTORY      292

 LOGFILE

  GROUP  1 ( '/dev/raw/raw10', '/dev/raw/raw11' ) SIZE 50 M  REUSE,

  GROUP  2 ( '/dev/raw/raw12', '/dev/raw/raw13' ) SIZE 50 M  REUSE

 DATAFILE

  '/dev/raw/raw1'

 CHARACTER SET ZHS16GBK

 

 

contents of Memory Script:

{

   switch clone datafile all;

}

executing Memory Script

 

released channel: ORA_AUX_DISK_1

datafile 2 switched to datafile copy

input datafile copy recid=1 stamp=778987671 filename=/dev/raw/raw3

datafile 3 switched to datafile copy

input datafile copy recid=2 stamp=778987671 filename=/dev/raw/raw2

datafile 4 switched to datafile copy

input datafile copy recid=3 stamp=778987671 filename=/dev/raw/raw4

 

contents of Memory Script:

{

   set until scn  555341;

   recover

   clone database

    delete archivelog

   ;

}

executing Memory Script

 

executing command: SET until clause

 

Starting recover at 27-3 -12

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=1640 devtype=DISK

 

starting media recovery

 

channel ORA_AUX_DISK_1: starting archive log restore to default destination

channel ORA_AUX_DISK_1: restoring archive log

archive log thread=1 sequence=41

channel ORA_AUX_DISK_1: reading from backup piece /oracle/backup/archive.dbf

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/oracle/backup/archive.dbf tag=TAG20120326T234659

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

archive log filename=/oracle/arch/1_41_777371211.dbf thread=1 sequence=41

channel clone_default: deleting archive log(s)

archive log filename=/oracle/arch/1_41_777371211.dbf recid=1 stamp=778987673

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

Finished recover at 27-3 -12

 

contents of Memory Script:

{

   shutdown clone;

   startup clone nomount ;

}

executing Memory Script  --如果目标数据库还有会话,复制过程将在这里一直等待所有会话结束

 

database dismounted

Oracle instance shut down

 

connected to auxiliary database (not started)

Oracle instance started

 

Total System Global Area     486539264 bytes

 

Fixed Size                     1268196 bytes

Variable Size                138413596 bytes

Database Buffers             339738624 bytes

Redo Buffers                   7118848 bytes

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

  MAXLOGFILES     16

  MAXLOGMEMBERS      3

  MAXDATAFILES     1024

  MAXINSTANCES     8

  MAXLOGHISTORY      292

 LOGFILE

  GROUP  1 ( '/dev/raw/raw10', '/dev/raw/raw11' ) SIZE 50 M  REUSE,

  GROUP  2 ( '/dev/raw/raw12', '/dev/raw/raw13' ) SIZE 50 M  REUSE

 DATAFILE

  '/dev/raw/raw1'

 CHARACTER SET ZHS16GBK

 

 

contents of Memory Script:

{

   set newname for tempfile  1 to

 "/dev/raw/raw5";

   switch clone tempfile all;

   catalog clone datafilecopy  "/dev/raw/raw3";

   catalog clone datafilecopy  "/dev/raw/raw2";

   catalog clone datafilecopy  "/dev/raw/raw4";

   switch clone datafile all;

}

executing Memory Script

 

executing command: SET NEWNAME

 

renamed temporary file 1 to /dev/raw/raw5 in control file

 

cataloged datafile copy

datafile copy filename=/dev/raw/raw3 recid=1 stamp=778987902

 

cataloged datafile copy

datafile copy filename=/dev/raw/raw2 recid=2 stamp=778987902

 

cataloged datafile copy

datafile copy filename=/dev/raw/raw4 recid=3 stamp=778987902

 

datafile 2 switched to datafile copy

input datafile copy recid=1 stamp=778987902 filename=/dev/raw/raw3

datafile 3 switched to datafile copy

input datafile copy recid=2 stamp=778987902 filename=/dev/raw/raw2

datafile 4 switched to datafile copy

input datafile copy recid=3 stamp=778987902 filename=/dev/raw/raw4

 

contents of Memory Script:

{

   Alter clone database open resetlogs;

}

executing Memory Script

 

database opened

Finished Duplicate Db at 27-3 -12

 

RMAN>

 

10)、验证数据库复制

[oracle@clone_sigle /]$ hostname

clone_sigle

[oracle@clone_sigle /]$ sq

[uniread] Loaded history (423 lines)

 

SQL*Plus: Release 10.2.0.4.0 - Production on 星期二 3 27 01:36:32 2012

 

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

 

SQL> conn /as sysdba

Connected.

SQL> show parameter name

 

NAME                                 TYPE        VALUE

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

db_file_name_convert                 string

db_name                              string      orclaux

db_unique_name                       string      orclaux

global_names                         boolean     FALSE

instance_name                        string      orclaux

lock_name_space                      string

log_file_name_convert                string

service_names                        string      orclaux

SQL> select * from test_rman;

 

        T1 T2

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

         1 23-3 -12

 

SQL>

 

重启数据库后再进行一次验证

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

 

Total System Global Area  486539264 bytes

Fixed Size                  1268196 bytes

Variable Size             138413596 bytes

Database Buffers          339738624 bytes

Redo Buffers                7118848 bytes

Database mounted.

Database opened.

SQL> show parameter name

 

NAME                                 TYPE        VALUE

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

db_file_name_convert                 string

db_name                              string      orclaux

db_unique_name                       string      orclaux

global_names                         boolean     FALSE

instance_name                        string      orclaux

lock_name_space                      string

log_file_name_convert                string

service_names                        string      orclaux

SQL>

SQL> select * from test_rman;

 

        T1 T2

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

         1 23-3 -12

 

SQL>

 

    至此,使用RMAN来进行数据库复制的试验结束,试验达到了预期目标。

 

阅读(5042) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册