ITPub博客

首页 > 数据库 > 数据库开发技术 > 创建恢复目录、使用恢复目录进行备份和恢复试验

创建恢复目录、使用恢复目录进行备份和恢复试验

原创 数据库开发技术 作者:Steven1981 时间:2007-02-27 08:47:43 0 删除 编辑

转载:http://blog.chinaunix.net/u/7121/showart.php?id=139709

http://www.itpub.net/727601.html

[@more@]

(1)、创建恢复目录

[oracle@a admin]$ sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 - Production on Tue Jul 11 17:46:39 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> connect sys/xueyao as sysdba;
Connected.

SQL> create tablespace cattbs datafile '/opt/oracle/oradata/primary/cattbs.dbf'size 15M;

Tablespace created.

SQL> create user rman identified by rman default tablespace cattbs;

User created.

SQL> grant connect,resource to rman;

Grant succeeded.

SQL> grant recovery_catalog_owner to rman;

Grant succeeded.

SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
[oracle@a admin]$ rman catalog rman/rman

Recovery Manager: Release 9.2.0.4.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to recovery catalog database
recovery catalog is not installed

RMAN> create catalog tablespace cattbs;

recovery catalog created

RMAN> upgrade catalog;

recovery catalog owner is RMAN
enter UPGRADE CATALOG command again to confirm catalog upgrade

RMAN> upgrade catalog;

recovery catalog upgraded to version 09.02.00
DBMS_RCVMAN package upgraded to version 09.02.00
DBMS_RCVCAT package upgraded to version 09.02.00

RMAN>

C:Documents and Settingsw>oradim -startup -sid olive
(2)、将过本地数据库注册远程到primary数据库的恢复目录中
C:Documents and Settingsw>rman target sys/olive catalog rman/rman@primary

Recovery Manager: Release 9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: OLIVE (DBID=1470549339)
connected to recovery catalog database


RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN>
至此,RMAN恢复目录已经与目标数据库连接成功


在primary库上查询结果如下:
[oracle@a admin]$ sqlplus rman/rman

SQL*Plus: Release 9.2.0.4.0 - Production on Tue Jul 11 18:29:18 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select * from db;

DB_KEY DB_ID HIGH_CONF_RECID LAST_KCCDIVTS CURR_DBINC_KEY
---------- ---------- --------------- ------------- --------------
1 1470549339 0 592928667 2

SQL>
查询结果中的DBID为恢复目录库的DBID即olive的DBID,说明在primary数据库中成功注册olive数据库

(3)、取消注册过程如下:
[oracle@a root]$ sqlplus rman/rman

SQL*Plus: Release 9.2.0.4.0 - Production on Wed Jul 12 15:46:04 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> exec dbms_rcvcat.unregisterdatabase(1,1470549339);

PL/SQL procedure successfully completed.

SQL> select * from db;

no rows selected

SQL>

(4)、在本地的恢复目录中注册primary数据库
C:Documents and Settingsw>rman target sys/xueyao@primary catalog rman/rman2

Recovery Manager: Release 9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: PRIMARY (DBID=1432398067)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN>

在本地恢复目录中查询注册的数据库

C:Documents and Settingsw>sqlplus rman/rman2

SQL*Plus: Release 9.2.0.1.0 - Production on Fri Jul 21 10:32:43 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> select * from db;

DB_KEY DB_ID HIGH_CONF_RECID LAST_KCCDIVTS CURR_DBINC_KEY
---------- ---------- --------------- ------------- --------------
437 1470549339 (OLIVE) 0 592928667 438
277 1432398067(PRIMARY ) 0 595618027 408

SQL>


注:在同一个恢复目录中可以注册多个目标数据库,可以在db中查询

在primary中查询数据库的dbid,结果验证在本地恢复目录中成功注册primary数据库
[oracle@a root]$ sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 - Production on Wed Jul 12 16:03:12 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> conn sys/xueyao as sysdba;
Connected.
SQL> select dbid from v$database;

DBID
----------
1432398067

SQL>


使用本地恢复目录备份primary数据库如下:
注:备份结果是保存在primary所在的机器上,默认是在dbs目录下

(5)、以下过程是通过恢复目录备份与恢复数据库

备份的目标数据库是通过rman连接中target来指明的
C:Documents and Settingsw>rman target sys/xueyao@primary catalog rman/rman2

Recovery Manager: Release 9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: PRIMARY (DBID=1432398067)
connected to recovery catalog database


RMAN> backup database format '/opt/oracle/oradata/test';

Starting backup at 12-JUL-06
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=15 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
including current controlfile in backupset
input datafile fno=00001 name=/opt/oracle/oradata/primary/system01.dbf
input datafile fno=00002 name=/opt/oracle/oradata/primary/undotbs01.dbf
input datafile fno=00005 name=/opt/oracle/oradata/primary/example01.dbf
input datafile fno=00011 name=/opt/oracle/oradata/primary/olivenan01.dbf
input datafile fno=00010 name=/opt/oracle/oradata/primary/xdb01.dbf
input datafile fno=00006 name=/opt/oracle/oradata/primary/indx01.dbf
input datafile fno=00009 name=/opt/oracle/oradata/primary/users01.dbf
input datafile fno=00003 name=/opt/oracle/oradata/primary/cwmlite01.dbf
input datafile fno=00004 name=/opt/oracle/oradata/primary/drsys01.dbf
input datafile fno=00007 name=/opt/oracle/oradata/primary/odm01.dbf
input datafile fno=00012 name=/opt/oracle/oradata/primary/cattbs.dbf
input datafile fno=00008 name=/opt/oracle/oradata/primary/tools01.dbf
channel ORA_DISK_1: starting piece 1 at 12-JUL-06
channel ORA_DISK_1: finished piece 1 at 12-JUL-06
piece handle=/opt/oracle/oradata/test comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:17:54
Finished backup at 12-JUL-06

RMAN>


使用恢复目录恢复数据库的过程
RMAN> startup nomount;

connected to target database (not started)
Oracle instance started

Total System Global Area 236000356 bytes

Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes

RMAN> restore controlfile;

Starting restore at 12-JUL-06

allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=13 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: restoring controlfile
output filename=/opt/oracle/oradata/primary/control01.ctl
channel ORA_DISK_1: restored backup piece 1
piece handle=/opt/oracle/oradata/test tag=TAG20060712T165549 params=NULL
channel ORA_DISK_1: restore complete
replicating controlfile
input filename=/opt/oracle/oradata/primary/control01.ctl
output filename=/opt/oracle/oradata/primary/control02.ctl
output filename=/opt/oracle/oradata/primary/control03.ctl
Finished restore at 12-JUL-06
注意:在我测试中使用恢复目录恢复数据发现restore database是在nomount执行。
不使用恢复目录restore database是在mount执行的。此问题需要进一步确认??
RMAN> restore database;

Starting restore at 12-JUL-06

using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /opt/oracle/oradata/primary/system01.dbf
restoring datafile 00002 to /opt/oracle/oradata/primary/undotbs01.dbf
restoring datafile 00003 to /opt/oracle/oradata/primary/cwmlite01.dbf
restoring datafile 00004 to /opt/oracle/oradata/primary/drsys01.dbf
restoring datafile 00005 to /opt/oracle/oradata/primary/example01.dbf
restoring datafile 00006 to /opt/oracle/oradata/primary/indx01.dbf
restoring datafile 00007 to /opt/oracle/oradata/primary/odm01.dbf
restoring datafile 00008 to /opt/oracle/oradata/primary/tools01.dbf
restoring datafile 00009 to /opt/oracle/oradata/primary/users01.dbf
restoring datafile 00010 to /opt/oracle/oradata/primary/xdb01.dbf
restoring datafile 00011 to /opt/oracle/oradata/primary/olivenan01.dbf
restoring datafile 00012 to /opt/oracle/oradata/primary/cattbs.dbf
channel ORA_DISK_1: restored backup piece 1
piece handle=/opt/oracle/oradata/test tag=TAG20060712T165549 params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 12-JUL-06


RMAN> alter database mount;

database mounted
注:以下使用recover database时出现错误,据我分析应该是我没有备份日志且没有最新的日志导致。
RMAN> recover database;

Starting recover at 12-JUL-06
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/12/2006 17:26:57
ORA-06550: line 1, column 166:
PLS-00553: character set name is not recognized
ORA-06550: line 0, column 0:
PL/SQL: Compilation unit analysis terminated
RMAN-06031: could not translate database keyword

RMAN> alter database open resetlogs;

database opened
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN>
至此恢复成功。
查看primary中的数据
[oracle@a primary]$ sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 - Production on Wed Jul 12 17:30:15 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
查看DBID为恢复目录中的DBID
SQL> conn sys/xueyao as sysdba
Connected.
SQL> select dbid from v$database;

DBID
----------
1432398067
日志历史记录中没有数据
SQL> select * from v$log_history;

no rows selected

SQL>

SQL> conn test/ftp123;
Connected.
SQL> select count(*) from olivenan;

COUNT(*)
----------
30798

SQL>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/703656/viewspace-900573/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    127
  • 访问量
    811083