RMAN实例入门,备份与恢复

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

cuug本周五晚8点免费Oracle网络公开课《人生最痛苦的事:人还在钱没了――守护数据库的备份信息》

在listener.ora中加入


    (SID_DESC =

      (GLOBAL_DBNAME = rmtgt)

      (Oracle_HOME = D:\oracle\product\10.2.0\db_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:\oracle\product\10.2.0\oradata\orcl\rmants.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 reserved.

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:\oracle\rmanrep


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:\oracle\rmanrep\butdb.dmp';

4> }


目标数据库备份为D:\oracle\rmanrep\butdb.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:\ORACLE\PRODUCT\10.2.0\ORADATA\BUT\USERS01.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:\ORACLE\PRODUCT\10.2.0\ORADATA\BUT\USERS01.DBF

channel ORA_DISK_1: reading from backup piece D:\ORACLE\RMANREP\BUTDB.DMP

channel ORA_DISK_1: restored backup piece 1

piece handle=D:\ORACLE\RMANREP\BUTDB.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


你可能感兴趣的:(oracle学习,OCP,ocm,cuug官网,oracle官网)