使用RMAN DUPLICATE命令创建备用数据库

作者 阿九【转载时请务必以超链接形式标明文章原始出处和作者信息】


使用RMANDUPLICATE命令创建备用数据库

 

说明:在做这些操作之前需要配置好tnsnames.ora文件

1、环境说明

OS:RedHat5.5

数据库版本:Oracle 10.2.0.4

主库SID:orcl

备库SID:orclaux

数据文件使用LV,LV配置一样

归档目录地址相同。

 

2、备份主库数据库

    要使用RMAN DUPLICATE命令创建备用数据库,必须有一个可用的、有效的备份集并且在之后创建一个为备库使用的控制文件备份。否则报错:

[oracle@sigle admin]$ rman target / auxiliary sys/sysadmin@sigleaux

[uniread] Loaded history (265 lines)

 

Recovery Manager: Release 10.2.0.4.0 - Production on 星期六 12月 29 21:06:25 2012

 

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

 

connected to target database: ORCL (DBID=1305151947)

connected to auxiliary database: ORCLAUX (not mounted)

 

RMAN> list backupset;

 

using target database control file instead of recovery catalog

 

RMAN>

 

RMAN>

 

RMAN> DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;

 

Starting Duplicate Db at 29-12月-12

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=1644 devtype=DISK

 

contents of Memory Script:

{

   restore clone standby controlfile;

   sql clone 'alter database mount standby database';

}

executing Memory Script

 

Starting restore at 29-12月-12

using channel ORA_AUX_DISK_1

 

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of Duplicate Db command at 12/29/2012 21:06:53

RMAN-03015: error occurred in stored script Memory Script

RMAN-06026: some targets not found - aborting restore

RMAN-06024: no backup or copy of the control file found to restore

 

RMAN>

 

备份主库数据库

[oracle@sigle backup]$ rman target /

[uniread] Loaded history (397 lines)

 

Recovery Manager: Release 10.2.0.4.0 - Production on 星期六 12月 29 22:27:39 2012

 

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

 

connected to target database: ORCL (DBID=1305151947)

 

RMAN> run{

2> allocate channel d1 type disk format='/oracle/backup/full_db_20121229.dbf';

backup as compressed backupset database tag='full_db_20121229';

3> release channel d1;

4> }

5>

using target database control file instead of recovery catalog

allocated channel: d1

channel d1: sid=1632 devtype=DISK

 

Starting backup at 29-12月-12

channel d1: starting compressed full datafile backupset

channel d1: 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 d1: starting piece 1 at 29-12月-12

channel d1: finished piece 1 at 29-12月-12

piece handle=/oracle/backup/full_db_20121229.dbf tag=FULL_DB_20121229 comment=NONE

channel d1: backup set complete, elapsed time: 00:00:45

Finished backup at 29-12月-12

 

Starting Control File and SPFILE Autobackup at 29-12月-12

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

Finished Control File and SPFILE Autobackup at 29-12月-12

 

released channel: d1

 

RMAN> list backupset;

 

 

List of Backup Sets

===================

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

38      Full    192.07M    DISK        00:00:36     29-12月-12    

        BP Key: 38   Status: AVAILABLE  Compressed: YES  Tag: FULL_DB_20121229

        Piece Name: /oracle/backup/full_db_20121229.dbf

  List of Datafiles in backup set 38

  File LV Type Ckp SCN    Ckp Time   Name

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

  1       Full 808208     29-12月-12 /dev/raw/raw1

  2       Full 808208     29-12月-12 /dev/raw/raw3

  3       Full 808208     29-12月-12 /dev/raw/raw2

  4       Full 808208     29-12月-12 /dev/raw/raw4

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

39      Full    13.70M     DISK        00:00:01     29-12月-12    

        BP Key: 39   Status: AVAILABLE  Compressed: NO  Tag: TAG20121229T223711

        Piece Name: /oracle/db10g/dbs/c-1305151947-20121229-03

  Control File Included: Ckp SCN: 808230       Ckp time: 29-12月-12

  SPFILE Included: Modification time: 29-12月-12

 

RMAN> exit

 

Recovery Manager complete.

[uniread] Saved history (403 lines)

[oracle@sigle backup]$

 

3、为备库准备控制文件备份

RMAN> run{

2> allocate channel d1 type disk format '/oracle/backup/stdb.ctl';

3> backup current controlfile for standby;

4> release channel d1;

5> }

 

released channel: ORA_DISK_1

allocated channel: d1

channel d1: sid=1630 devtype=DISK

 

Starting backup at 29-12月-12

channel d1: starting full datafile backupset

channel d1: specifying datafile(s) in backupset

including standby control file in backupset

channel d1: starting piece 1 at 29-12月-12

channel d1: finished piece 1 at 29-12月-12

piece handle=/oracle/backup/stdb.ctl tag=TAG20121229T224013 comment=NONE

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

Finished backup at 29-12月-12

 

Starting Control File and SPFILE Autobackup at 29-12月-12

piece handle=/oracle/db10g/dbs/c-1305151947-20121229-05 comment=NONE

Finished Control File and SPFILE Autobackup at 29-12月-12

 

released channel: d1

 

RMAN>

 

4、创建主库参数文件副本,并将文件拷贝到备库。

文件目录随意,只要oracle用户能访问就行

创建文件

[oracle@sigle backup]$ sqlplus /nolog

[uniread] Loaded history (216 lines)

 

SQL*Plus: Release 10.2.0.4.0 - Production on 星期六 12月 29 22:50:48 2012

 

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

 

SQL> conn /as sysdba

Connected.

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

 

File created.

 

SQL> exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production

With the Partitioning, OLAP, Data Mining Scoring Engine and Real Application Testing options

[uniread] Saved history (219 lines)

[oracle@sigle backup]$

拷贝文件

[oracle@clone_sigle dbs]$ ftp 172.16.1.120

Connected to 172.16.1.120 (172.16.1.120).

220 (vsFTPd 2.0.5)

Name (172.16.1.120:root): root

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> cd /oracle/backup

250 Directory successfully changed.

ftp> lcd /oracle/backup

Local directory now /oracle/backup

ftp> ls

227 Entering Passive Mode (172,16,1,120,24,10)

150 Here comes the directory listing.

-rw-------    1 500      500      14385152 Mar 24  2012 c-1305151947-20120324-01

-rw-------    1 500      500      201408512 Dec 29 14:37 full_db_20121229.dbf

-rw-------    1 500      500           914 Mar 26  2012 initorclaux.ora

-rw-------    1 500      500           884 Dec 29 14:50 pfile_pri.ora

-rw-------    1 500      500      14352384 Dec 29 14:40 stdb.ctl

226 Directory send OK.

ftp> bin

200 Switching to Binary mode.

ftp> get pfile_pri.ora

local: pfile_pri.ora remote: pfile_pri.ora

227 Entering Passive Mode (172,16,1,120,176,142)

150 Opening BINARY mode data connection for pfile_pri.ora (884 bytes).

226 File send OK.

884 bytes received in 7.1e-05 secs (1.2e+04 Kbytes/sec)

ftp> bye

221 Goodbye.

[oracle@clone_sigle dbs]$

 

5、使用主库参数文件副本启动备库到nomount状态

要使用RMAN DUPLICATE复制备库,需要将备库启动到nomount状态

[oracle@clone_sigle backup]$ sqlplus /nolog

[uniread] Loaded history (458 lines)

 

SQL*Plus: Release 10.2.0.4.0 - Production on 星期六 12月 29 22:54:03 2012

 

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

 

SQL> conn /as sysdba

Connected to an idle instance.

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

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> exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production

With the Partitioning, OLAP, Data Mining Scoring Engine and Real Application Testing options

[uniread] Saved history (461 lines)

[oracle@clone_sigle backup]$

 

6、将创建的主库备份拷贝到HOST2上相同的路径位置。

    包括创建的备用控制文件备份。如果备份到磁带机上,则要保证备库能访问到磁带机上的备份集。

 

7、连接主备库执行复制操作

[oracle@sigle backup]$ rman target / auxiliary sys/sysadmin@sigleaux

[uniread] Loaded history (436 lines)

 

Recovery Manager: Release 10.2.0.4.0 - Production on 星期六 12月 29 23:04:39 2012

 

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

 

connected to target database: ORCL (DBID=1305151947)

connected to auxiliary database: ORCL (not mounted)

 

RMAN> DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;

 

Starting Duplicate Db at 29-12月-12

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=1641 devtype=DISK

 

contents of Memory Script:

{

   restore clone standby controlfile;

   sql clone 'alter database mount standby database';

}

executing Memory Script

 

Starting restore at 29-12月-12

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: starting datafile backupset restore

channel ORA_AUX_DISK_1: restoring control file

channel ORA_AUX_DISK_1: reading from backup piece /oracle/backup/stdb.ctl

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/oracle/backup/stdb.ctl tag=TAG20121229T224013

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

output filename=/dev/raw/raw6

output filename=/dev/raw/raw7

output filename=/dev/raw/raw8

Finished restore at 29-12月-12

 

sql statement: alter database mount standby database

released channel: ORA_AUX_DISK_1

 

contents of Memory Script:

{

   set newname for tempfile  1 to

 "/dev/raw/raw5";

   switch clone tempfile all;

   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 NEWNAME

 

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

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

Starting restore at 29-12月-12

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=1641 devtype=DISK

 

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/full_db_20121229.dbf

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/oracle/backup/full_db_20121229.dbf tag=FULL_DB_20121229

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

Finished restore at 29-12月-12

 

contents of Memory Script:

{

   switch clone datafile all;

}

executing Memory Script

 

datafile 1 switched to datafile copy

input datafile copy recid=5 stamp=803343987 filename=/dev/raw/raw1

datafile 2 switched to datafile copy

input datafile copy recid=6 stamp=803343987 filename=/dev/raw/raw3

datafile 3 switched to datafile copy

input datafile copy recid=7 stamp=803343987 filename=/dev/raw/raw2

datafile 4 switched to datafile copy

input datafile copy recid=8 stamp=803343987 filename=/dev/raw/raw4

Finished Duplicate Db at 29-12月-12

 

RMAN>

 

9、创建备库使用的spfile文件

[oracle@clone_sigle dbs]$ sqlplus /nolog

[uniread] Loaded history (492 lines)

 

SQL*Plus: Release 10.2.0.4.0 - Production on 星期六 12月 29 23:23:27 2012

 

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

 

SQL> conn /as sysdba

Connected.

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

 

File created.

 

SQL> exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production

With the Partitioning, OLAP, Data Mining Scoring Engine and Real Application Testing options

[uniread] Saved history (498 lines)

[oracle@clone_sigle dbs]$

 

10、使用创建的spfile文件重启备库到mount状态

[oracle@clone_sigle dbs]$ sqlplus /nolog

[uniread] Loaded history (498 lines)

 

SQL*Plus: Release 10.2.0.4.0 - Production on 星期六 12月 29 23:25:00 2012

 

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

 

SQL> conn /as sysdba

Connected.

SQL> shutdown immediate;

ORA-01109: database not open

 

 

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

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.

SQL> select dbid,name,DB_UNIQUE_NAME,DATABASE_ROLE ,open_mode from v$database;

 

      DBID NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    OPEN_MODE

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

1305151947 ORCL      orcl                           PHYSICAL STANDBY MOUNTED

 

SQL>

 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值