当前位置:  数据库>oracle

RMAN实例入门,备份与恢复

    来源: 互联网  发布时间:2017-04-19

    本文导语: 本文用step by step的方式介绍一下RMAN的入门使用,通常保存备份目录的目录数据库和目标数据库应该在不同的机器上,这里两个数据库在同一台机器上. 在listener.ora中加入     (SID_DESC =      (GLOBAL_DBNAME = rmtgt)      (Oracle_HOME = D:o...

本文用step by step的方式介绍一下RMAN入门使用,通常保存备份目录的目录数据库和目标数据库应该在不同的机器上,这里两个数据库在同一台机器上.

listener.ora中加入

    (SID_DESC =
      (GLOBAL_DBNAME = rmtgt)
      (Oracle_HOME = D:oracleproduct10.2.0db_1)
      (SID_NAME = but)
    )



tns配置如下:(让target静态注册,这样startup nomount的时候才能从rman连上)

target =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (address = (protocol = tcp)(host = nbk-dal-625040.ap.bt.com)(port = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rmtgt)
    )
  )
catalog =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = NBK-DAL-625040.ap.bt.com)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )


















1,在保存备份目录的目录数据库建立一个rman用户并创建相应的权限

sqlplus sys/sys@catalog as sysdba

create tablespace rmants datafile 'D:oracleproduct10.2.0oradataorclrmants.dbf' size 20M;

create user rman identified by rman default tablespace rmants temporary tablespace temp quota unlimited on rmants;
grant recovery_catalog_owner to rman;
grant connect, resource to rman;

2,在目录数据库中创建恢复目录

C:>rman catalog rman/rman@catalog
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jan 12 15:02:22 2012
Copyright (c) 1982, 2005, Oracle.  All rights key iis7站长之家.
connected to recovery catalog database
RMAN> create catalog tablespace rmants;
recovery catalog created




注册目标数据库到恢复目录,注意这里的连接串是targe
C:>rman target sys/sys@target
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jan 12 15:08:42 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: BUT (DBID=1215064705)



连接到目录数据库,注册目标数据库
RMAN> connect catalog rman/rman@catalog;
connected to recovery catalog database

RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete


到此为止前面的准备工作都做好了,下面就可以使用RMAN 来进行备份和恢复了。

下面来进行备份:

1,创建一个目录 D:oraclermanrep

2,C:>rman target sys/sys@target catalog rman/rman@catalog
3,RMAN> run{
2>  allocate channel c1 type disk;
3>  backup database format 'D:oraclermanrepbutdb.dmp';
4> }



目标数据库备份为D:oraclermanrepbutdb.dmp

RMAN> list backup; 可以查看备份的信息.

如果想删掉备份,(194 为备份的BS key)

RMAN> allocate channel for delete type disk;
RMAN> change backupset 194 delete;

下面来做恢复

1,将目标数据库shutdown,将UNDOTBS01.DBF文件重命名为UNDOTBS01.DBF.bak模拟数据文件丢失.

2,将目标数据库 startup mount

3,在rman下恢复

a,C:>rman target sys/sys@target
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jan 12 17:59:50 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: BUT (DBID=3712141887, not open)


注意这里可以看到数据库不是open状态,网络字符串'target'必须是通过静态注册的才能连接上.

这时候open数据库
b,RMAN> alter database open;
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 01/12/2012 18:01:42
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: 'D:ORACLEPRODUCT10.2.0ORADATABUTUSERS01.DBF'







可以看到datafile 4找不到

c,
RMAN> restore datafile 4;

Starting restore at 12-JAN-12
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 00004 to D:ORACLEPRODUCT10.2.0ORADATABUTUSERS01.DBF
channel ORA_DISK_1: reading from backup piece D:ORACLERMANREPBUTDB.DMP
channel ORA_DISK_1: restored backup piece 1
piece handle=D:ORACLERMANREPBUTDB.DMP tag=TAG20120112T172743
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03





Finished restore at 12-JAN-12

d,

RMAN> recover datafile 4;

Starting recover at 12-JAN-12
using channel ORA_DISK_1

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

Finished recover at 12-JAN-12

e,恢复成功,打开数据库,

RMAN> alter database open;

database opened


    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • Oracle RMAN快速入门指南
  • rman配置及rman常用命令操作
  • Oracle相关:Rman Crosscheck删除失效归档
  • rman恢复方案和oracle异机恢复


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3