Oracle恢复目录的管理使用简要

I. 使用恢复目录存储RMAN备份记录

  1. Oracle 官方建议把恢复目录建议于独立的数据库中。如果把恢复目录与其他一些数据混杂在某库中,若该库失败则恢复目录一起丢失,这将导致恢复异常困难。
  2. 在恢复目录中登记某个库被称作注册(registration).可以在恢复目录中注册多个目标库。举例来说,你可以注册数据库 prod1,prod2,和prod3在一个单独的由用户catowner拥有的目录中,而该目录位于一个叫catdb的数据库中。 因为RMAN通过DBID即数据库的身份证来分辨各个库。每个在恢复目录中注册过的目标库都有一个唯一的DBID.
  3. 恢复目录主要包括以下RMAN的使用情况信息:

l  数据文件和归档日志的备份集和备份片

l  数据文件的拷贝

l  归档日志及其拷贝

l  目标库中的表空间和数据文件

l  储存的脚本

l  RMAN的永久性配置

  1. 恢复目录保存了目标库控制文件中重要的RMAN操作原数据。同步恢复目录保证与控制文件中当前信息同步。
  2. RMAN 创建快照控制文件,即临时控制文件,当每次需要做全局同步时。快照临时文件保证了RMAN同步时的一致性读。数据库服务进程保证同时只有一个快照临时文件的存在,这对于保证RMAN操作不受其他进程干扰是必要的。
  3. 丢失恢复目录将导致严重的恢复问题。如何备份恢复目录可参考一般数据库的备份方式。
  4. 关于恢复目录的兼容性,可以通过查询恢复目录用户模式下的rcver表了解参与恢复目录使用端的版本号,示例:
SQL> SELECT * FROM rcver;

VERSION
------------
08.01.05.00
09.00.01.00
10.02.01.00

只要是8i之后版本一般不存在兼容性问题。

II 管理恢复目录

创建恢复目录

管理恢复目录中的目标库记录

同步恢复目录

恢复目录模式下的控制文件管理

备份恢复目录

导入和导出恢复目录

增强恢复目录可用性

查询恢复目录视图

更新恢复目录

删除恢复目录

  1. 创建恢复目录,创建恢复目录分成三步:
  • 配置恢复目录所在数据库
  • 创建恢复目录拥有者
  • 创建恢复目录本身

配置恢复目录数据库

若使用恢复目录,RMAN要求维护恢复目录所在模式。恢复目录储存在当前模式的默认表空间中,注意SYS不能是恢复目录的拥有者。我们强烈建议恢复目录数据库使用归档模式。同时必须分配足够的空间给恢复目录所在模式,恢复目录所占用的空间取决于使用恢复目录的目标数据库的数量。适当地为恢复目录库规划容量是必要的。应当保证恢复目录库和目标数据库的不占用同一磁盘。

创建目录拥有者

在合理配置恢复目录库后,我们来创建目录拥有者

使用目录库上的SYS帐号登录

假定当前有一个tool表空间来保存目录

使用temp临时表空间为用户默认临时表空间

如下步骤:

     CONNECT SYS/oracle@catdb AS SYSDBA
 SQL> CREATE USER rman IDENTIFIED BY cat
       TEMPORARY TABLESPACE temp
       DEFAULT TABLESPACE tools
    QUOTA UNLIMITED ON tools;

同时我们要授予 recovery_catalog_owner 权限给用户,该角色拥有管理创建恢复目录的权限。

   SQL> GRANT RECOVERY_CATALOG_OWNER TO rman;

创建恢复目录

在创建恢复目录用户后,使用RMAN建立恢复目录,操作如下:

$ rman

RMAN> CONNECT CATALOG rman/cat@catdb   --以目录用户连接恢复目录库

RMAN> create catalog                         — 建议恢复目录

当然也可以指定使用的表空间:

RMAN> create catalog  tablespace users;

成功建立恢复目录后,可以查询目录下已经存在的目录使用的基表。

SQL>select table_name from user_tables;

2. 管理恢复目录中的目标库记录

ü  在恢复目录中注册目标数据库

ü  在恢复目录中注销目标数据库

ü  在恢复目录中重置数据库

ü  在恢复目录中移除已删除的记录

在恢复目录中注册目标数据库

首先确定恢复目录库已经打开,从目标库主机登录:

$ rman TARGET / CATALOG rman/cat@catdb

若目标库未启动,首先启动到加载模式:

RMAN> STARTUP MOUNT;

注册目标库:

RMAN> REGISTER DATABASE;

RMAN会自动在恢复目录中记录目标库的各种信息,将目标库控制文件中的

元信息复制到恢复目录中,可以使用以下命令确认注册情况:

RMAN> REPORT SCHEMA;

Report of database schema
File Size(MB)   Tablespace       RB segs Datafile Name
---- ---------- ---------------- ------- -------------------
1        307200 SYSTEM             NO    /oracle/oradata/trgt/system01.dbf
2         20480 UNDOTBS            YES   /oracle/oradata/trgt/undotbs01.dbf
3         10240 CWMLITE            NO    ...

在恢复目录中登记备份文件

若有备份文件未在控制文件或恢复目录中存在对应的记录,则需要登记该文件,此处的(control file 为目标数据库control file)。

示例:

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';

在恢复目录中登记多个目标库

可以在一个恢复目录中注册多个目标库,前提是目标库的DBID唯一。

在恢复目录中注销目标库

可以使用命令: unregister database 在RMAN中注销目标数据库。当数据库被

注销,所有的RMAN记录都会丢失,所以要小心操作。

在恢复目录中移除已经删除的记录

在9i之后版本,RMAN在删除备份文件的同时会删除在恢复目录中的对应物记

录,而9i以前版本则只将对应物记录标志为delete.可以通过运行脚本

prgrmanc.sql来删除对应物记录,该脚本储存在($ORACLE_HOME/rdbms/admin)

录下。示例如下:

% sqlplus rman/cat@catdb
SQL> @?/rdbms/admin/prgrmanc.sql删过期备份信息

同步恢复目录

当恢复目录当前状态晚于数据库控制文件中的备份信息时,则需要使用同步恢复

目录,这种情况只会出现在一段时间使用恢复目录而一段时间不使用恢复目录的

情况下,造成的时间段差异。RMAN会在您做某些操作时自动完成同步,例如

Backup命令,当然你也可以手动同步: resync catalog .

管理控制文件

数据库参数CONTROL_FILE_RECORD_KEEP_TIME决定了控制文件中记录可能被复

用的最短自然天数,因此你保证恢复目录在此期间完成同步,否则可能控制文件

中的记录丢失,则需要手动登记备份文件。CONTROL_FILE_RECORD_KEEP_TIME有

效期内需要定期同步。

备份恢复目录

备份恢复目录数据库十分重要,若恢复目录数据库丢失则所有的备份信息将丢

失,导致恢复十分困难。

备份恢复目录数据库与一般的数据库没有大的区别,以下为注意事项:

恢复目录数据库因该运行在归档模式下

使用备份策略冗余量大于一

在不同的介质上备份

不使用恢复目录记录备份信息

使用控制文件自动备份,rman中可以自动完成

结构图:

catalog

更新恢复目录

若您使用的恢复目录版本低于使用的客户端,则您需要更新恢复目录。举例来说

当前您使用了8.1版的客户端RMAN,而恢复目录是8.0版本的,则需要更新。

当恢复目录版本高于您使用的客户端,则upgrade catalog报错。更新操作实例如

下:

sqlplus> connect sys/oracle@catdb as sysdba;
sqlplus> grant TYPE to rman;
% rman TARGET / CATALOG rman/cat@catdb
UPGRADE CATALOG;

recovery catalog owner is rman

enter UPGRADE CATALOG command again to confirm catalog upgrade

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 TARGET / CATALOG rman/cat@catdb

Issue the DROP CATALOG command twice to confirm:

DROP CATALOG;

recovery catalog owner is rman
enter DROP CATALOG command again to confirm catalog removal

DROP CATALOG;

Comments

  1. admin says

    RMAN: How to Query the RMAN Recovery Catalog

    PURPOSE
    ——-

    This document describes how to query the RMAN recovery catalog through
    data dictionary views, the list command, and the report command.

    SCOPE & APPLICATION
    ——————-

    This document is intended for users who are or want to be familiar
    with the recovery catalog of Recovery Manager(RMAN). It goes into
    moderate detail on some of the ways you can gather information about
    the recover catalog but should not be used as the ultimate source of
    information on the recovery catalog since it only covers some of the
    more popular data dictionary views.

    HOW TO QUERY THE RMAN RECOVERY CATALOG
    =======================================

    RMAN Data Dictionary Views
    ————————–

    When the “catrman.sql” script is run, several views are created in the recovery
    catalog owner schema. Here are some of the more important views.

    RC_DATABASE
    This view gives information about the databases registered in the
    recovery catalog.
    COLUMN DESCRIPTION
    DB_KEY The primary key for the database.
    DBINC_KEY The primary key for the current incarnation.
    DBID Unique identifier for the database.
    NAME The DB_NAME for the current incarnation.
    RESETLOGS_CHANGE# The SCN of the most recent RESETLOGS operation.
    RESETLOGS_TIME The timestamp of the most recent RESETLOGS
    operation.

    RC_TABLESPACE
    This view lists information about all tablespaces registered in the
    recovery catalog, all dropped tablespaces, and tablespaces that
    belong to old database incarnations. It corresponds to the
    V$TABLESPACE dynamic performance view. The current value is shown
    for tablespace attributes.
    COLUMN DESCRIPTION
    DB_KEY The primary key for the target database.
    DBINC_KEY The primary key for the incarnation of the target
    database.
    DB_NAME The DB_NAME of the database incarnation this
    record belongs to.
    TS# The tablespace identifier in the target database.
    NAME The tablespace name.
    CREATION_CHANGE# The creation SCN (from the first datafile).
    CREATION_TIME The creation time of the tablespace.
    DROP_CHANGE# The SCN recorded when the tablespace was dropped.
    DROP_TIME The date when the tablespace was dropped.

    RC_DATAFILE
    This view lists information about all datafiles registered in the
    recovery catalog. It corresponds to the V$DATAFILE dynamic
    performance view. A datafile is shown as dropped if its tablespace
    was dropped.
    COLUMN DESCRIPTION
    DB_KEY The primary key for the target database.
    DBINC_KEY The primary key for the incarnation of the target
    database.
    DB_NAME The DB_NAME of the database incarnation this
    record belongs to.
    TS# The tablespace identifier in the target database.
    TABLESPACE_NAME The tablespace name.
    FILE# The absolute file number of the datafile.
    CREATION_CHANGE# The SCN at datafile creation.
    CREATION_TIME The time of datafile creation.
    DROP_CHANGE# The SCN recorded when the datafile was dropped.
    DROP_TIME The time when the datafile was dropped.
    BYTES The size of the datafile in bytes.
    BLOCKS The number of blocks in the datafile.
    BLOCK_SIZE The size of the data blocks.
    NAME The datafile filename.
    STOP_CHANGE# SCN for datafile if offline normal or read-only.
    READ_ONLY 1 if STOP_CHANGE# is read-only; otherwise 0.

    RC_STORED_SCRIPT
    This view lists information about scripts stored in the recovery
    catalog. The view contains one row for each stored script.
    COLUMN DESCRIPTION
    DB_KEY The primary key for the database that owns this
    script.
    DB_NAME The DB_NAME of the database incarnation this
    record belongs to.
    SCRIPT_NAME The name of the script.

    RC_STORED_SCRIPT_LINE
    This view lists information about lines of the scripts stored in the
    recovery catalog. The view contains one row for each line of each
    stored script.
    COLUMN DESCRIPTION
    DB_KEY The primary key for the database that owns this
    script.
    SCRIPT_NAME The name of the stored script.
    LINE The number of the line in the script.
    TEXT The text of the line of the script.

    To determine which databases are currently registered in the recovery catalog:
    SQL> SELECT * FROM RC_DATABASE;

    DB_KEY DBINC_KEY DBID NAME CHANGE# RESETLOGS
    ——– ———– ———— —— ——— ———–
    1 2 1943591421 DB00 1 20-OCT-97

    To determine which tablespaces are currently stored in the recovery catalog for the target database:
    SQL> SELECT DB_KEY, DBINC_KEY, DB_NAME, TS#, NAME,
    CREATION_CHANGE#, CHANGE#, CREATION_TIME, CRE_DATE
    FROM RC_TABLESPACE;

    DB_KEY DBINC_KEY DB_NAME TS# NAME CHANGE# CRE_DATE
    ——– ———– ——— —– ——– ——— ———-
    1 2 DB00 3 DATA01 9611 20-OCT-97
    1 2 DB00 1 RBS 9599 20-OCT-97
    1 2 DB00 4 RMAN_TS 14023 29-OCT-97
    1 2 DB00 0 SYSTEM 3 20-OCT-97
    1 2 DB00 2 TEMP 9605 20-OCT-97

    To determine which scripts are currently stored in the recovery catalog for the target database:
    SQL> SELECT * FROM RC_STORED_SCRIPT;

    DB_KEY DB_NAME SCRIPT_NAME
    ——– ——— —————
    1 DB00 nightlybackup
    1 DB00 archivebackup

    RMAN DATA DICTIONARY VIEWS used to query the control file
    ==========================================================

    If you are not using a recovery catalog, RMAN information is stored in the
    target database’s control file .

    V$ARCHIVED_LOG
    This view displays archived log information from the controlfile
    including archive log names. An archive log record is inserted after
    the online redo log is successfully archived or cleared (name column
    is NULL if the log was cleared). If the log is archived twice, there
    will be two archived log records with the same THREAD#, SEQUENCE#,
    and FIRST_CHANGE#, but with a different name. An archive log record
    is also inserted when an archive log is restored from a backup set
    or a copy.
    COLUMN DESCRIPTION
    RECID Archived log record ID
    STAMP Archived log record stamp
    NAME Archived log file name
    THREAD# Redo thread number
    SEQUENCE# Redo log sequence number
    RESETLOGS_CHANGE# Resetlogs change# of database when written
    RESETLOGS_TIME Resetlogs time of database when written
    FIRST_CHANGE# First change# in the archived log
    FIRST_TIME Timestamp of the first change
    NEXT_CHANGE# First change in the next log
    NEXT_TIME Timestamp of the next change
    BLOCKS Size of the archived log in blocks
    BLOCK_SIZE Redo log block size
    COMPLETION_TIME Time when the archiving completed
    DELETED YES/NO

    V$BACKUP_CORRUPTION
    This view displays information about corruptions in datafile backups
    from the controlfile. Note that corruptions are not tolerated in the
    controlfile and archived log backups.
    COLUMN DESCRIPTION
    RECID Backup corruption record ID
    STAMP Backup corruption record stamp
    SET_STAMP Backup set stamp
    SET_COUNT Backup set count
    PIECE# Backup piece number
    FILE# Datafile number
    BLOCK# First block of the corrupted range
    BLOCKS Number of contiguous blocks in corrupted range
    CORRUPTION_CHANGE# Change# where logical corruption was detected.
    MARKED_CORRUPT YES/NO. If YES the blocks were not marked
    corrupted in datafile, but were detected and
    marked while making backup

    V$COPY_CORRUPTION
    This view displays information about datafile copy corruptions from
    the controlfile.
    COLUMN DESCRIPTION
    RECID Copy corruption record ID
    STAMP Copy corruption record stamp
    COPY_RECID Datafile copy record ID
    COPY_STAMP Datafile copy record stamp
    FILE# Datafile number
    BLOCK# First block of the corrupted range
    BLOCKS Number of contiguous blocks in corrupted range
    CORRUPTION_CHANGE# Change# where logical corruption was detected.
    MARKED_CORRUPT YES/NO. If YES the blocks were not marked
    corrupted in datafile, but were detected and
    marked while making the datafile copy

    V$BACKUP_DATAFILE
    Useful for creating equal sized backup sets by determining the
    number of blocks in each datafile. Can also find the number of
    corrupt blocks for the datafile.
    COLUMN DESCRIPTION
    RECID Backup datafile record ID
    STAMP Backup datafile record stamp
    SET_STAMP Backup set stamp
    SET_COUNT Backup set count
    FILE# Datafile number. Set to 0 for controlfile
    CREATION_CHANGE# Creation change of the datafile
    CREATION_TIME Creation timestamp of the datafile
    RESETLOGS_CHANGE# Resetlogs change# of datafile when backed up
    RESETLOGS_TIME Resetlogs timestamp of datafile when backed up
    INCREMENTAL_LEVEL (0-4) incremental backup level
    INCREMENTAL_CHANGE# All blocks changed after incremental change# is
    included in this backup.
    CHECKPOINT_CHANGE# All changes up to checkpoint change# are included
    in this backup
    CHECKPOINT_TIME Timestamp of the checkpoint
    ABSOLUTE_FUZZY_CHANGE# Highest change# in this backup
    MARKED_CORRUPT Number of blocks marked corrupt
    MEDIA_CORRUPT Number of blocks media corrupt
    LOGICALLY_CORRUPT Number of blocks logically corrupt
    DATAFILE_BLOCKS Size of the datafile in blocks at backup time.
    BLOCKS Size of the backup datafile in blocks.
    BLOCK_SIZE Block size
    OLDEST_OFFLINE_RANGE The RECID of the oldest offline range record in
    this backup controlfile.
    COMPLETION_TIME The time completed.

    V$BACKUP_REDOLOG
    This view displays information about archived logs in backup sets
    from the controlfile. Note that online redo logs cannot be backed up
    directly; they must be archived first to disk and then backed up. An
    archive log backup set can contain one or more archived logs.
    COLUMN DESCRIPTION
    RECID Record ID for this row.
    STAMP Timestamp used with RECID to identify this row
    SET_STAMP One foreign key for the row of the V$BACKUP_SET
    table that identifies backup set
    SET_COUNT One foreign key for the row of the V$BACKUP_SET
    table that identifies this backup set
    THREAD# Thread number for the log
    SEQUENCE# Log sequence number
    RESETLOGS_CHANGE# Change number of the last resetlogs
    RESETLOGS_TIME Change time of the last resetlogs
    FIRST_CHANGE# SCN when the log was switched into.
    FIRST_TIME Time allocated when the log was switched into
    NEXT_CHANGE# SCN when the log was switched out of.
    NEXT_TIME Time allocated when the log was switched out of
    BLOCKS Size of the log in logical blocks
    BLOCK_SIZE Size of the log blocks in bytes

    V$BACKUP_SET
    This view displays backup set information from the controlfile. A
    backup set record is inserted after the backup set is successfully
    completed.
    COLUMN DESCRIPTION
    RECID Backup set record ID
    STAMP Backup set record timestamp
    SET_STAMP Backup set stamp.
    SET_COUNT Backup set count. The backup set count is
    incremented by one every time a new backup set
    is started
    BACKUP_TYPE Type of files that are in this backup.
    archived redo logs = \QL
    datafile full backup = \QD
    incremental backup = \QI
    CONTROLFILE_INCLUDED YES/NO
    INCREMENTAL_LEVEL Location where this backup set fits into the
    database’s backup strategy.
    0 = full datafile backups
    non-zero = incremental datafile backups
    NULL = archivelog backups
    PIECES Number of distinct backup pieces in backup set
    COMPLETION_TIME Time when the backup completes successfully
    ELAPSED_SECONDS The number of elapsed seconds.
    BLOCK_SIZE Block size of the backup set

    V$BACKUP_PIECE
    This view displays information about backup pieces from the
    controlfile. Each backup set consist of one or more backup pieces.
    COLUMN DESCRIPTION
    RECID Backup piece record ID
    STAMP Backup piece record stamp
    SET_STAMP Backup set stamp
    SET_COUNT Backup set count
    PIECE# Backup piece number (1-N)
    DEVICE_TYPE Type of device where backup piece resides.
    HANDLE Identifies the backup piece on restore
    COMMENTS Comment returned by OS or storage subsystem.
    MEDIA Name of the media where backup piece resides.
    CONCUR YES/NO, Whether piece on media can be accessed
    concurrently
    TAG Backup piece tag. The tag is specified at backup
    set level, but stored at piece level
    DELETED If set to YES indicates the piece is deleted
    START_TIME The starting time.
    COMPLETION_TIME The completion time.
    ELAPSED_SECONDS The number of elapsed seconds.

    Querying the Recovery Catalog Through RMAN
    ———————————————

    While inside RMAN you can use the list command to query the contents of
    the recovery catalog, or the target database control file if no
    recovery catalog is used.

    Examples:
    To list all backups of files in tablespace tbs_1 that were made since November
    first:

    RMAN> list until time ‘Nov 1 1996 00:00:00’ backupset of tablespace tbs_1;

    To list all backups on device type ‘sbt_tape’:

    RMAN> list device type ‘sbt_tape’ backupset of database;

    To list all copies of a datafile, qualified by tag and directory:

    RMAN> list tag foo like ‘/somedir/%’ copy of datafile 21;

    To list all database incarnations registered in the recovery catalog:

    RMAN> list incarnation of database;

    You can also use the list command to determine which copies and backups can be
    deleted. For example, if a full backup of the database was created on November
    2, and it will not be necessary to recover the database to an earlier
    point-in-time, then the backup sets listed in the following report can be
    deleted:

    RMAN> list until time ‘Nov 1 1996 00:00:00’ backupset of database;

    9i New List Functionality
    ————————-

    This command will allow you to list be either backup or file. The BY BACKUP
    output shows backup sets and the contents of each backup set. The BY FILE
    shows the file name, backup sets where the file appears and backup copies of
    this file. A SUMMARY option is available with the BY BACKUP option which gives
    a one-line summary for each file or backup set. Also note that SUMMARY and
    VERBOSE options only apply to the LIST BACKUP, not to LIST COPY. The defaults
    are BY BACKUP, VERBOSE.

    RMAN> list backup .. [listoptions];

    listoptions: [BY report unrecoverable database;

    To report on all datafiles which need a new backup because 3 or more
    incremental backups have been taken since the last full backup.

    RMAN> report need backup incremental 3 database;

    To report on all datafiles in tablespace tbs_1 which need a new backup
    because the last full or incremental backup was taken more than 5 days
    ago.

    RMAN> report need backup days 5 database;

    9i New Report Functionality
    —————————-

    This command shows which backups are no longer needed according to the
    retention policy. The RECOVERY WINDOW has been added to specify a window
    of time during which the database must be recoverable.

    RMAN> report obsolete ;

    This command will delete files that would be reported by REPORT OBSOLETE.

    RMAN> delete obsolete;

    NEW 9i SHOW COMMAND
    ——————–

    There is a new command similar to the SHOW PARAMETER command in svrmgrl which
    allows you to display the current values for various CONFIGURE commands.

    RMAN> show show_operand [,show_operand …];

    show_operand: RETENTION POLICY |
    EXCLUDE |
    BACKUP COPIES |
    CHANNEL |
    DEFAULT DEVICE TYPE |
    SNAPSHOT CONTROLFILE |
    AUXNAME |
    MAXSETSIZE |
    BACKUP OPTIMIZATION |
    ALL
    NOTE: for additional table and views please refer to the 9i and 10g documentation as a reference

Comment

*

沪ICP备14014813号-2

沪公网安备 31010802001379号