recovery catalog详解及实践步骤

http://blog.csdn.net/found2008/article/details/3583825

RMAN可以在没有恢复目录(NOCATALOG)下运行,这个时候备份信息保存在控制文件中。
保存在控制文件中的备份信息是很危险的,如果控制文件的破坏将导致备份信息的丢失与恢复目录的失败,
而且,没有恢复目录,很多RMAN的命令将不被支持。所以对于重要的数据库,建议创建恢复目录,
恢复目录也是一个数据库,只不过这个数据库用来保存备份信息,一个恢复目录可以用来备份多个数据库。
       创建RMAN目录,一下步骤说明了在一个数据库中创建RMAN目录的过程

1.连接数据库
 SQL> startup
 ORACLE 例程已经启动。
 
 Total System Global Area  135338868 bytes
 Fixed Size                   453492 bytes
 Variable Size             109051904 bytes
 Database Buffers           25165824 bytes
 Redo Buffers                 667648 bytes
 数据库装载完毕。
 数据库已经打开。
 SQL> show user;
 USER 为"SYS"
 SQL> create tablespace rman_ts datafile 'e:/oracle/oradata/test/gejun/rman_ts.db
 f' size 10M;
 
 表空间已创建。
 
 SQL> create user rman_ts identified by rman_ts default tablespace rman_ts tempor
 ary tablespace temp quota unlimited on rman_ts;
 
 用户已创建
 
 SQL> grant connect,resource,recovery_catalog_owner to rman_ts;
 
 授权成功。

2.在目录数据库中创建恢复目录
 C:/Documents and Settings/Administrator>rman catalog rman_ts/rman_ts
 
 恢复管理器: 版本9.2.0.1.0 - Production
 
 Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
 
 连接到恢复目录数据库
 未安装恢复目录
 
 RMAN> create catalog tablespace rman_ts;
 
 恢复目录已创建

3.登记目标数据库:
 说明:一个恢复目录可以注册多个目标数据库,注册目标数据库的命令为:
 
 C:/Documents and Settings/Administrator>rman catalog rman_ts/rman_ts target scot
 t/tiger@test
 
 恢复管理器: 版本9.2.0.1.0 - Production
 
 Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
 
 连接到目标数据库: TEST (DBID=1961217676)
 连接到恢复目录数据库
 
 RMAN> register database;

4.Verify that the registration was successful by running REPORT SCHEMA:
 C:/Documents and Settings/Administrator>rman target / catalog rman_ts/rman_ts@test
 恢复管理器: 版本9.2.0.1.0 - Production
 Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
 连接到目标数据库: TEST (DBID=1961217676)
 连接到恢复目录数据库
 
 RMAN> report schema;
 
 数据库方案报表
 文件 KB    表空间           RB segs 数据文件名称
 ---- ---------- -------------------- ------- -------------------
 1        419840 SYSTEM               YES     E:/ORACLE/ORADATA/TEST/SYSTEM01.DBF
 2        204800 UNDOTBS1             YES     E:/ORACLE/ORADATA/TEST/UNDOTBS01.DBF
 3         20480 CWMLITE              NO      E:/ORACLE/ORADATA/TEST/CWMLITE01.DBF
 4         20480 DRSYS                NO      E:/ORACLE/ORADATA/TEST/DRSYS01.DBF
 5        152960 EXAMPLE              NO      E:/ORACLE/ORADATA/TEST/EXAMPLE01.DBF
 6         25600 INDX                 NO      E:/ORACLE/ORADATA/TEST/INDX01.DBF
 7         20480 ODM                  NO      E:/ORACLE/ORADATA/TEST/ODM01.DBF
 8         10240 TOOLS                NO      E:/ORACLE/ORADATA/TEST/TOOLS01.DBF
 9         25600 USERS                NO      E:/ORACLE/ORADATA/TEST/USERS01.DBF
 10        39040 XDB                  NO      E:/ORACLE/ORADATA/TEST/XDB01.DBF
 11        10240 RMAN_TS              NO      E:/ORACLE/ORADATA/TEST/GEJUN/RMAN_TS.DBF
  If you have datafile copies, backup pieces or archive logs on disk, you can catalog them in the recovery catalog using 
  the CATALOG command. When using a recovery catalog, cataloging older backups 
  that have aged out of the control file lets RMAN use the older backups during restore operations. 
  For example:(通过下面语句进行恢复)
   RMAN> CATALOG DATAFILECOPY '/disk1/old_datafiles/01_01_2003/users01.dbf';
   RMAN> CATALOG ARCHIVELOG '/disk1/arch_logs/archive1_731.dbf', 
        '/disk1/arch_logs/archive1_732.dbf';
   RMAN> CATALOG BACKUPPIECE '/disk1/backups/backup_820.bkp';
  You can also catalog multiple backup files in a directory at once, 
  using the CATALOG START WITH command, as shown in this example:  
   RMAN> CATALOG START WITH '/disk1/backups/';
   RMAN> CATALOG START WITH '/disk1/backups';
5.注销数据库
 DELETE BACKUP DEVICE TYPE sbt;
 DELETE BACKUP DEVICE TYPE DISK;
 DELETE COPY;
 UNREGISTER DATABASE;
 
6.To reset the recovery catalog to an older incarnation
 a.Determine the incarnation key of the desired database incarnation. 
  Obtain the incarnation key value by issuing a LIST command: 
  RMAN>LIST INCARNATION OF DATABASE trgt;
  List of Database Incarnations
  DB Key  Inc Key   DB Name   DB ID       STATUS     Reset SCN    Reset Time
  ------- -------   -------   ------      -------    ----------   ----------
  1       2         TRGT      1224038686  PARENT     1            02-JUL-02
  1       582       TRGT      1224038686  CURRENT    59727        10-JUL-02
  The incarnation key is listed in the "Inc Key" column.

 b.Reset the database to the old incarnation. For example, enter: 
  RMAN>RESET DATABASE TO INCARNATION 2;

 c.If the control file of the previous incarnation is available and mounted, 
   then skip to step 6 of this procedure. Otherwise, 
   shut down the database and start it without mounting. For example: 
  RMAN>SHUTDOWN IMMEDIATE
  RMAN>STARTUP NOMOUNT

 d.Restore a control file from the old incarnation. 
   If you have a control file tagged, then specify the tag. 
   Otherwise, you can run the SET UNTIL command, as in this example: 
  RMAN>RUN 
  {
    SET UNTIL 'SYSDATE-45';
    RESTORE CONTROLFILE; # only if current control file is not available
  }

 e.Mount the restored control file: 
  RMAN>ALTER DATABASE MOUNT;

 f.Run RESTORE and RECOVER commands to restore and recover 
 the database files from the prior incarnation, then open the
 database with the RESETLOGS option. For example, enter: 
  RMAN>RESTORE DATABASE;
  RMAN>RECOVER DATABASE;
  RMAN>ALTER DATABASE OPEN RESETLOGS;

7.Working with RMAN Stored Scripts in the Recovery Catalog
 a.Creating Stored Scripts: CREATE SCRIPT
  RMAN> create script full_backup
  2> {
  3> backup database plus archivelog;
  4> delete obsolete;
  5> }
  已创建脚本 full_backup
 b.global CREATE SCRIPT
  Examine the output. If no errors are displayed, 
  then the script was successfully created and stored in the recovery catalog.
  For a global script, the syntax is similar:
  
  RMAN>CREATE GLOBAL SCRIPT global_full_backup 
  >{     
  >  BACKUP DATABASE PLUS ARCHIVELOG;
  >DELETE OBSOLETE;
  >}
      You can also provide a COMMENT with descriptive information:
  RMAN>CREATE GLOBAL SCRIPT global_full_backup 
  >COMMENT 'use only with ARCHIVELOG mode databases'
  >{     
  > BACKUP DATABASE PLUS ARCHIVELOG;
  >DELETE OBSOLETE;
  >}
       Print script:
        RMAN> print script full_backup;
  正在打印存储的脚本: full_backup
  {
  backup database plus archivelog;
  delete obsolete;
  }
       Replace script:
         RMAN>REPLACE SCRIPT full_backup 
  {
    BACKUP DATABASE PLUS ARCHIVELOG;
  }
       Delete script:
       RMAN> delete script 'full_backup';
  已删除脚本: full_backup
 
 
 c.execute
  RUN { EXECUTE GLOBAL SCRIPT global_full_backup; }
  RUN { EXECUTE SCRIPT global_full_backup; }
    下面操作是本人本机:
  RMAN> run
  2> {
  3> execute script full_backup;
  4> }
  

#说明:下面是我自己电脑的测试,但之前做了其他测试才引起,并不影响这次测试
  正在执行脚本: full_backup
  
  启动 backup 于 22-12月-08
  源文件中出现错误: krmk.pc,行: 7519
  SQL 语句失败的文本: alter system archive log current
  来自目标数据库的 ORACLE 错误:
  ORA-16038: 日志 2 序列号 5 无法归档
  ORA-19504: 无法创建文件""
  ORA-00312: 联机日志 2 线程 1: 'E:/ORACLE/ORADATA/TEST/REDO02.LOG'
  
  分配的通道: ORA_DISK_1
  通道 ORA_DISK_1: sid=14 devtype=DISK
  说明与恢复目录中的任何存档日志均不匹配
  完成 backup 于 22-12月-08
  
  启动 backup 于 22-12月-08
  使用通道 ORA_DISK_1
  通道 ORA_DISK_1: 正在启动 full 数据文件备份集
  通道 ORA_DISK_1: 正在指定备份集中的数据文件
  输入数据文件 fno=00001 name=E:/ORACLE/ORADATA/TEST/SYSTEM01.DBF
  输入数据文件 fno=00002 name=E:/ORACLE/ORADATA/TEST/UNDOTBS01.DBF
  输入数据文件 fno=00005 name=E:/ORACLE/ORADATA/TEST/EXAMPLE01.DBF
  输入数据文件 fno=00010 name=E:/ORACLE/ORADATA/TEST/XDB01.DBF
  输入数据文件 fno=00006 name=E:/ORACLE/ORADATA/TEST/INDX01.DBF
  输入数据文件 fno=00009 name=E:/ORACLE/ORADATA/TEST/USERS01.DBF
  输入数据文件 fno=00003 name=E:/ORACLE/ORADATA/TEST/CWMLITE01.DBF
  输入数据文件 fno=00004 name=E:/ORACLE/ORADATA/TEST/DRSYS01.DBF
  输入数据文件 fno=00007 name=E:/ORACLE/ORADATA/TEST/ODM01.DBF
  输入数据文件 fno=00008 name=E:/ORACLE/ORADATA/TEST/TOOLS01.DBF
  输入数据文件 fno=00011 name=E:/ORACLE/ORADATA/TEST/GEJUN/RMAN_TS.DBF
  通道 ORA_DISK_1: 正在启动段 1 于 22-12月-08
  通道 ORA_DISK_1: 已完成段 1 于 22-12月-08
  段 handle=E:/ORACLE/ORADATA/RMAN1/0NK2T6L6_1_1 comment=NONE
  通道 ORA_DISK_1: 备份集已完成, 经过时间:00:00:55
  完成 backup 于 22-12月-08
  
  启动 backup 于 22-12月-08
  源文件中出现错误: krmk.pc,行: 7519
  SQL 语句失败的文本: alter system archive log current
  来自目标数据库的 ORACLE 错误:
  ORA-16014: 日志 2 的序列号 5 未归档,没有可用的目的地
  ORA-00312: 联机日志 2 线程 1: 'E:/ORACLE/ORADATA/TEST/REDO02.LOG'
  
  使用通道 ORA_DISK_1
  说明与恢复目录中的任何存档日志均不匹配
  完成 backup 于 22-12月-08
  
  启动 Control File and SPFILE Autobackup 于 22-12月-08
  段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081222-02 comment=NONE
  完成 Control File and SPFILE Autobackup 于 22-12月-08
  
  RMAN 保留策略将应用于该命令
  将 RMAN 保留策略设置为冗余 5
  使用通道 ORA_DISK_1
  删除以下已废弃的备份和副本:
  类型                 关键字 完成时间           文件名/句柄
  -------------------- ------ ------------------ --------------------
  备份集               26     01-12月-08
  备份段       45     01-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81201-00
  备份集               27     02-12月-08
  备份段       46     02-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81202-00
  备份集               28     02-12月-08
  备份段       47     02-12月-08         E:/ORACLE/ORADATA/RMAN1/05K18O2K_1_1
  备份集               29     02-12月-08
  备份段       48     02-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81202-01
  备份集               30     04-12月-08
  备份段       49     04-12月-08         E:/ORACLE/ORADATA/RMAN1/07K1E550_1_1
  备份集               31     04-12月-08
  备份段       50     04-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81204-00
  备份集               32     08-12月-08
  备份段       51     08-12月-08         E:/ORACLE/ORADATA/RMAN1/09K1O0LO_1_1
  备份集               33     08-12月-08
  备份段       52     08-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81208-00
  备份集               34     08-12月-08
  备份段       53     08-12月-08         E:/ORACLE/ORADATA/RMAN1/0BK1O0ON_1_1
  备份集               35     08-12月-08
  备份段       54     08-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81208-01
  备份集               36     10-12月-08
  备份段       55     10-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81210-00
  备份集               37     15-12月-08
  备份段       56     15-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81215-00
  备份集               38     16-12月-08
  备份段       57     16-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81216-00
  备份集               39     19-12月-08
  备份段       58     19-12月-08         E:/ORACLE/ORA92/DATABASE/C-1961217676-200
  81219-00
  
  是否确定要删除以上对象 (输入 YES 或 NO)? yes
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081201-00 recid=2 stamp=67
  2337701
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081202-00 recid=3 stamp=67
  2420262
  已删除备份段
  备份段 handle=E:/ORACLE/ORADATA/RMAN1/05K18O2K_1_1 recid=4 stamp=672424020
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081202-01 recid=5 stamp=67
  2424075
  已删除备份段
  备份段 handle=E:/ORACLE/ORADATA/RMAN1/07K1E550_1_1 recid=6 stamp=672601248
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081204-00 recid=7 stamp=67
  2601304
  已删除备份段
  备份段 handle=E:/ORACLE/ORADATA/RMAN1/09K1O0LO_1_1 recid=8 stamp=672924344
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081208-00 recid=9 stamp=67
  2924399
  已删除备份段
  备份段 handle=E:/ORACLE/ORADATA/RMAN1/0BK1O0ON_1_1 recid=10 stamp=672924439
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081208-01 recid=11 stamp=6
  72924495
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081210-00 recid=12 stamp=6
  73102004
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081215-00 recid=13 stamp=6
  73528592
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081216-00 recid=14 stamp=6
  73609992
  已删除备份段
  备份段 handle=E:/ORACLE/ORA92/DATABASE/C-1961217676-20081219-00 recid=15 stamp=6
  73883336
  14 对象已删除

7.Determining the Schema Version of the Recovery Catalog
 SQL> conn rman_ts/rman_ts@test;
 已连接。
 SQL> select * from rcver;
 
 VERSION
 ------------
 09.02.00

8.Upgrading the Recovery Catalog
 a.To install the new recovery catalog schema, the recovery catalog user must have TYPE privilege: 
  sqlplus> connect sys/oracle@catdb as sysdba;
  sqlplus> grant TYPE to rman;

 b.Use RMAN to connect to the target and recovery catalog databases. For example, enter: 
  % rman TARGET / CATALOG rman/cat@catdb
  
 c.connected to recovery catalog database 
   PL/SQL package rcat.DBMS_RCVCAT version 08.00.04 in RCVCAT database is too old
   Issue the UPGRADE CATALOG command: 
     RMAN>UPGRADE CATALOG;
 
 d.recovery catalog owner is rman 
   enter UPGRADE CATALOG command again to confirm catalog upgrade 
   Enter the UPDATE CATALOG command again to confirm: 
  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
   
9.Dropping the Recovery Catalog
 %rman target / catalog rman_ts/rman_ts@test
 RMAN>drop catalog;

 


 
 注册在恢复目录中的数据库
 正在启动全部恢复目录的 resync
 完成全部 resync

  rman help:
    参数       值          说明
   -----------------------------------------------------------------------------
   target       加引号的字符串  目标数据库连接字符串
   目录      加引号的字符串  恢复目录的连接字符串
   nocatalog    无           如果已指定, 则没有恢复目录
   cmdfile      加引号的字符串  输入命令文件的名称
   log        加引号的字符串  输出消息日志文件的名称
   跟踪        加引号的字符串  输出调试信息日志文件的名称
   append       无           如果已指定, 日志将以附加模式打开
   debug        可选参数  激活调试
   msgno        无           对全部消息显示 RMAN-nnnn 前缀
   send         加引号的字符串  将命令发送到介质管理器
   pipe         字符串         管道名称的构建块
   timeout      整数        等待管道输入的秒数
   -----------------------------------------------------------------------------
   单引号和双引号(“或/”)均可用于加引号的字符串。
   除非字符串中有空格,否则不用引号。

4.全备份
rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile /export/home/oracle/backup_level0.rcv 
 log /export/home/oracle/backup.log $more backup_level0.rcv  resync catalog;

run {
allocate channel t1 type disk;
backup
incremental level 0
skip inAccessible
tag hot_db_bk_level0
filesperset 3
format '/export/home/oracle/bk_%s_%p_%t.bk'
(database);
sql 'alter system archive log current';
backup
filesperset 10
format '/export/home/oracle/a1_%s_%p_%t.ac'
(archivelog all delete input);
backup format '/export/home/oracle/df_t%t_s%s_p%p.ct' current controlfile ;
}
 
5.增备份
rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile backup_level1.rcv 
log backup.log $more backup_level1.rcv resync catalog;

run {
allocate channel t1 type disk;
backup
incremental level 1
skip inaccessible
tag hot_db_bk_level1
filesperset 3
format 'bk_%s_%p_%t.bk1'
(database);
sql 'alter system archive log current';
backup
filesperset 10
format 'a1_%s_%p_%t.ac1'
(archivelog all delete input);
backup current controlfile;
}

 

x.删除旧的全备  
 RMAN> list backupset;
  备份集列表
  ===================
  BS 关键字  类型 LV 大小       设备类型 经过时间 完成时间
  ------- ---- -- ---------- ----------- ------------ ----------
  25      Full    507M       DISK        00:00:47     28-11月-08
  BP 关键字: 44   状态: AVAILABLE   标记:TAG20081128T161820
  段名:E:/ORACLE/ORA92/DATABASE/01K0RHMC_1_1
    包含的 SPFILE: 修改时间: 27-11月-08
    备份集 25 中的数据文件列表
    文件 LV 类型 Ckp SCN    Ckp 时间   名称
    ---- -- ---- ---------- ---------- ----
    1       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/SYSTEM01.DBF
    2       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/UNDOTBS01.DBF
    3       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/CWMLITE01.DBF
    4       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/DRSYS01.DBF
    5       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/EXAMPLE01.DBF
    6       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/INDX01.DBF
    7       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/ODM01.DBF
    8       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/TOOLS01.DBF
    9       Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/USERS01.DBF
    10      Full 11466766   28-11月-08 E:/ORACLE/ORADATA/TEST/XDB01.DBF  
  BS 关键字  类型 LV 大小       设备类型 经过时间 完成时间
  ------- ---- -- ---------- ----------- ------------ ----------
  27      Full    1M         DISK        00:00:00     02-12月-08
  BP 关键字: 46   状态: AVAILABLE   标记:
  段名:E:/ORACLE/ORA92/DATABASE/C-1961217676-20081202-00
    包含的 SPFILE: 修改时间: 02-12月-08 
  
      根据key(关键字)来删除旧的备份
 RMAN> allocate channel for maintenance type disk;
 RMAN> change backupset 169 delete; ----------THIS IS THE COMMAND TO REMOVE THE ENTRY & OS FILE 做完后可以看到list backupset和操作系统的文件都没有了

 

 

 

###版权-----found2008 ------邮箱:hiho1128@126.com


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值