Managing a Recovery Catalog

About Recovery Catalog Maintenance

A recovery catalog is a database schema used by RMAN to store metadata about one or more Oracle databases. A recovery catalog provides the following benefits:

  1. A recovery catalog creates redundancy for the RMAN repository stored in the control file of each target database. If the target control file and all backups are lost, then the RMAN metadata still exists in the recovery catalog.
  2. A recovery catalog centralizes metadata for all your target databases. You can use a recovery catalog in an environment in which you use or have used different versions of Oracle Database.
  3. A recovery catalog can store metadata history much longer than the control file.
  4. RMAN scripts can use only in a recovery catalog. The script is stored in the recovery catalog rather than on the file system
  5. A recovery catalog is required when you use RMAN in a Data Guard environment.

Note:关于DG使用catalog的相关操作见DG相关文档

Basic Concepts for the RMAN Recovery Catalog

  1. Registration

The process of enrolling of a database in a recovery catalog for RMAN use is called registration.

The recommended practice is to register every target database in your environment in a single recovery catalog.

  1. Base RMAN Recovery Catalog & Virtual Private Catalog

Base Catalog为所有注册数据库的catalog,实际数据全部存于base catalog owner下。通过base catalog owner授权catalog database下其它用户,使它可以访问base catalog中部分target database备份元信息,称为virtual private catalog,数据还是存于base catalog不变

The owner of a centralized recovery catalog, which is also called the base recovery catalog, can grant or revoke restricted access to the catalog to other database users. Each restricted user has full read/write access to his own metadata, which is called a virtual private catalog.

  1. Recovery Catalog Resynchronization

For RMAN operations such as backup, restore, and crosscheck, RMAN always first updates the control file and then propagates the metadata to the recovery catalog. 

This flow of metadata from the mounted control file to the recovery catalog, which is known as recovery catalog resynchronization, ensures that the metadata that RMAN obtains from the control file is current.

Creating a Recovery Catalog

1. Configuring the Recovery Catalog Database

Catalog database不要同时作target database,建议开启归档

保存1年RMAN Repository空间需求

Table 13-1 Typical Recovery Catalog Space Requirements for 1 Year

Type of Space

Space Requirement

SYSTEM tablespace

90 MB

Temp tablespace

5 MB

Rollback or undo tablespace

5 MB

Recovery catalog tablespace

15 MB for each database registered in the recovery catalog

Online redo logs

1 MB each (three groups, each with two members)

  1. Creating the Recovery Catalog Schema Owner

To create the recovery catalog schema in the recovery catalog database:

  1. Create a user and schema for the recovery catalog:

CREATE USER rco IDENTIFIED BY rco

  TEMPORARY TABLESPACE temp

  DEFAULT TABLESPACE tools

  QUOTA UNLIMITED ON tools;

  1. Grant the RECOVERY_CATALOG_OWNER role to the schema owner. This role provides the user with all privileges required to maintain and query the recovery catalog.

GRANT RECOVERY_CATALOG_OWNER TO rco;

  1. Executing the CREATE CATALOG Command

To create the recovery catalog:

  1. Start RMAN and connect to the database that will contain the catalog. Connect to the database as the recovery catalog owner.
  2. Run the CREATE CATALOG command to create the catalog. 

RMAN> CREATE CATALOG;   ## 使用默认表空间

RMAN> CREATE CATALOG TABLESPACE cat_tbs;   ## 指定表空间

If the tablespace name for the recovery catalog is an RMAN reserved word, then it must be uppercase and enclosed in quotes.

SQL> SELECT TABLE_NAME FROM USER_TABLES;

  1. DROP CATALOG

Dropping the recovery catalog deletes the recovery catalog record of backups for all target databases registered in the catalog.

RMAN> DROP CATALOG;

recovery catalog owner is rco

enter DROP CATALOG command again to confirm catalog removal

Run the DROP CATALOG command again to confirm:

DROP CATALOG;

Registering a Database in the Recovery Catalog

未注册数据库即使连接到catalog database仍会使用自己的控制文件。非DG环境注册到catalog databasse的数据库要求DBID唯一

If you are not using the recovery catalog in a Data Guard environment, then use the REGISTER command to register each database. Each database must have a unique DBID.

Registering a Database with the REGISTER DATABASE Command:

  1. Start RMAN and connect to a target database and recovery catalog. The recovery catalog database must be open.

$ rman TARGET / CATALOG rco@catdb;

  1. Register the target database in the connected recovery catalog:

REGISTER DATABASE;

此命令会自动将控制文件相关数据复制到catalog

  1. Verify that the registration was successful by running REPORT SCHEMA:

REPORT SCHEMA;

  1. Cataloging Backups in the Recovery Catalog

如果有控制文件已过期备份,使用catalog加入

CATALOG DATAFILECOPY '/disk1/old_datafiles/01_01_2003/users01.dbf';

CATALOG ARCHIVELOG '/disk1/arch_logs/archive1_731.dbf', '/disk1/arch_logs/archive1_732.dbf';

CATALOG BACKUPPIECE '/disk1/backups/backup_820.bkp';

CATALOG START WITH '/disk1/backups/';    

Creating and Managing Virtual Private Catalogs

以上配置后只能通过Base RMAN Recovery Catalog Owner连接,即所有连接catalog用户都可以管理所有target库备份元数据。这时可以再创建virtual private catalogs来进行隔离

在catalog database中创建多个数据库用户,每个用户对应各自virtual private catalogs,virtual private catalogs可使用多个已注册的target数据库

By default, all of the users of an RMAN recovery catalog have full privileges to read, select, insert, update, and delete any metadata in the catalog.

Every RMAN recovery catalog starting with Oracle Database 11g supports virtual private catalogs, but they are not used unless explicitly created. There is no restriction on the number of virtual private catalogs that can be created beneath one recovery catalog.

Each virtual private catalog is owned by a database schema user which is different than the user who owns the recovery catalog.

After you set up a virtual private catalog user, the administrator for the recovery catalog grants each virtual private catalog the privilege to use that catalog for one or more databases that are currently registered in the recovery catalog. The administrator of the recovery catalog can also grant the privilege to register new databases while using a virtual private catalog.

Creating virtual private catalog

  1. Create the database user who will own the virtual private catalog

SQL> CREATE USER vpc1 IDENTIFIED BY password DEFAULT TABLESPACE vpcusers QUOTA UNLIMITED ON vpcusers;

SQL> GRANT CREATE SESSION TO vpc1;

Start RMAN and connect to the recovery catalog database as the base recovery catalog owner. Grant desired privileges to the virtual private catalog owner.

$ rman

RMAN> CONNECT CATALOG rco@catdb;

RMAN> GRANT CATALOG FOR DATABASE prod1 TO vpc1;

RMAN> GRANT CATALOG FOR DATABASE prod2 TO vpc1;

注:recovery catalog中注册的数据库名可能同名,但DBID不会,建议用DBID操作,DBID在RMAN连接target库时显示或通过查询V$DATABASE查询

You can also use a DBID rather than a database name.

授予注册权限就不用使用base catalog owner来授予注册的数据库了,直接连接相应target database及vpc1后执行REGISTER DATABASE即可

RMAN> GRANT REGISTER DATABASE TO vpc1;

注如果是CDB common user需要用单引号引起,如GRANT REGISTER DATABASE TO 'c##vpc1';

关于UNREGISTER DATABASE:

REGISTER DATABASE权限可使用UNREGISTER DATABASE命令,使用此命令会删除数据库在CATALOG下元信息,如果上面VPC1被授予了REGISTER DATABASE权限,它可以把prod1数据库从catalog中移除!

It is not necessary to connect to the target database, but if you do not, then you must specify the name of the target database in the UNREGISTER command. If multiple databases have the same name in the recovery catalog, then you must create a RUN block around the command and use SET DBID to set the DBID for the database.

  1. Create the virtual private catalog.

Start RMAN and connect to the recovery catalog database as the virtual private catalog owner: 

$ rman

RMAN> CONNECT CATALOG vpc1@catdb;

Create the virtual private catalog.

RMAN> CREATE VIRTUAL CATALOG;

If you intend to use a 10.2 or earlier release of RMAN with this virtual private catalog, then execute the following PL/SQL procedure (where base_catalog_owner is the database user who owns the base recovery catalog):

SQL> EXECUTE base_catalog_owner.DBMS_RCVCAT.CREATE_VIRTUAL_CATALOG;

(Optional) Enable the VPD model for the virtual private catalog by running the dbmsrmanvpc.sql script with the vpd option.

  1. Registering a Database with a Virtual Private Catalog

Start RMAN and connect to the recovery catalog database as the virtual private catalog owner. Connect to the database that you want to register as TARGET.

$ rman

RMAN> CONNECT TARGET /

RMAN> CONNECT CATALOG vpc1@catdb;

RMAN> REGISTER DATABASE;

  1. Revoking Privileges from a Virtual Private Catalog Owner

Start RMAN and connect to the recovery catalog database as the recovery catalog owner

$ rman

RMAN> CONNECT CATALOG rco@catdb;

RMAN> REVOKE CATALOG FOR DATABASE prod1 FROM vpc1;

You can also specify a DBID rather than a database name.

RMAN> REVOKE REGISTER DATABASE FROM vpc1;

  1. Dropping a Virtual Private Catalog

Start RMAN and connect to the recovery catalog database as the virtual private catalog owner

$ rman

RMAN> CONNECT CATALOG vpc1@catdb;

If you are using an Oracle Database 11g or later RMAN executable, then drop the virtual private catalog with the DROP CATALOG command:

RMAN> DROP CATALOG;

If you are using an Oracle Database 10g or earlier RMAN executable, then you cannot use the DROP CATALOG command. Instead, connect SQL*Plus to the catalog database as the virtual private catalog user, then execute the following PL/SQL procedure (where base_catalog_owner is the database user who owns the base recovery catalog):

SQL> EXECUTE base_catalog_owner.DBMS_RCVCAT.DELETE_VIRTUAL_CATALOG;

)Maintaining a Recovery Catalog

1. Resynchronizing the Recovery Catalog

Resynchronization指从controlfile同步到catalog

RMAN会在连接target及catalog后执行RMAN命令自动重同步,即生产一般只在每天定时脚本时进行重同步,这期间备份库的更改并未体现到catalog

RMAN automatically resynchronizes the recovery catalog when RMAN is connected to a target database and recovery catalog and you have executed RMAN commands.

When RMAN performs a resynchronization, it compares the recovery catalog to either the current or backup control file of the target database and updates the catalog with metadata that is missing or changed.

Resynchronizations can be full or partial.

  1. In a partial resynchronization, RMAN reads the current control file of the target database to update changed metadata about new backups, new archived redo logs, and so on. RMAN does not resynchronize metadata about the database physical schema.
  2. In a full resynchronization, RMAN updates all changed records, including those for the database schema. RMAN performs a full resynchronization after structural changes to database (adding or dropping database files, creating new incarnation, and so on) or after changes to the RMAN persistent configuration.

Resynchronization会先创建控制文件快照以保证控制文件数据一致

RMAN creates a snapshot control file, which is a temporary backup control file, when it performs a full resynchronization. The database ensures that only one RMAN session accesses a snapshot control file at any point in time.

This snapshot control file ensures that RMAN has a consistent view of the control file. Because the control file is intended for short-term use, it is not registered in the catalog. RMAN records the control file checkpoint in the recovery catalog to indicate the currency of the catalog

## full resynchronization

RESYNC CATALOG;   

  1. Resetting the Database Incarnation in the Recovery Catalog

在执行RESETLOGS后会自动在CATALOG中记录

If you open the database with the RESETLOGS option, then a new database incarnation record is automatically created in the recovery catalog. 

The database also implicitly and automatically issues a RESET DATABASE command, which specifies that this new incarnation of the database is the current incarnation. All subsequent backups and log archiving done by the target database is associated with the new database incarnation.

如果恢复之前incarnation需要执行RESET DATABASE TO INCARNATION命令

Whenever RMAN returns the database to an SCN before the current RESETLOGS SCN, either with RESTORE and RECOVER or FLASHBACK DATABASE, the RESET DATABASE TO INCARNATION command is required.

以下情况并不需要执行RESET DATABASE TO INCARNATION命令

However, you do not need to execute RESET DATABASE TO INCARNATION explicitly in the following scenarios because RMAN runs the command implicitly with Flashback.

  1. You use FLASHBACK DATABASE to rewind the database to an SCN in the direct ancestral path.

直接祖先路径只包含当前及父、第一个祖先

  1. You use FLASHBACK DATABASE to rewind the database to a restore point.

To reset the recovery catalog to an older incarnation for media recovery:

  1. Determine the incarnation key of the desired database incarnation. Obtain the incarnation key value by issuing a LIST command:

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-12

1       582       TRGT      1224038686  CURRENT    59727        10-JUL-12

  1. Reset the database to the old incarnation. For example, enter:

RESET DATABASE TO INCARNATION 2;

  1. shut down the database and start it without mounting. For example:

SHUTDOWN IMMEDIATE

STARTUP NOMOUNT

  1. 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:

RUN

{ SET UNTIL 'SYSDATE-45';

  RESTORE CONTROLFILE; # only if current control file is not available}

  1. Mount the restored control file:

ALTER DATABASE MOUNT;

  1. 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:

RESTORE DATABASE;

RECOVER DATABASE;

ALTER DATABASE OPEN RESETLOGS;

  1. Upgrading the Recovery Catalog

Target database, catalog database及catalog schema版本可以不同,如果Catalog schema版本低于RMAN client时需要进行升级

A target database, recovery catalog database, and recovery catalog schema can be at different database versions. If you use a version of the recovery catalog schema that is older than that required by the RMAN client, then you must upgrade it. For example, you must upgrade the catalog if you use an Oracle Database 11g RMAN client with a release 10.2 version of the recovery catalog schema.

在升级时执行UPGREAD CATALOG的RMAN客户端版本应该跟升级后版本一致

You receive an error when issuing UPGRADE CATALOG if the recovery catalog is at a version greater than that required by the RMAN client.

Determining the Schema Version of the Recovery Catalog

  1. Start SQL*Plus and connect to the recovery catalog database as the catalog owner.
  2. Query the RCVER table to obtain the schema version, as in the following example (sample output included):

If the table displays multiple rows, then the highest version in the RCVER table is the current catalog schema version. The table stores only the major version numbers and not the patch numbers

SQL> SELECT * FROM rcver;

VERSION

------------

10.02.00

11.02.00

12.01.00.01

These rows indicate that the catalog was created with a release 10.2.0 executable, then upgraded to release 11.2.0, and finally upgraded to release 12.1.0.1. The current version of the catalog schema is 12.1.0.1.

Using the UPGRADE CATALOG Command

下面是catalog schema版本低于catalog database版本,不需要执行相关存储过程包

This scenario assumes that you are upgrading a recovery catalog schema to the current version.

To upgrade the recovery catalog to Oracle Database 12c Release 1 (12.1.0.1):

  1. If you created the recovery catalog owner in a release before 10gR1, and if the RECOVERY_CATALOG_OWNER role did not include the CREATE TYPE privilege, then grant it.

SQL> GRANT CREATE TYPE TO rman;

  1. Start RMAN and connect RMAN to the recovery catalog database.
  2. Run the UPGRADE CATALOG command:

RMAN> UPGRADE CATALOG;

recovery catalog owner is rman

enter UPGRADE CATALOG command again to confirm catalog upgrade

  1. Run the UPGRADE CATALOG command again to confirm:

RMAN> UPGRADE CATALOG;

recovery catalog upgraded to version 12.01.00.01

DBMS_RCVMAN package upgraded to version 12.01.00.01

DBMS_RCVCAT package upgraded to version 12.01.00.01

下面是catalog database版本低需要升级相关存储过程

To upgrade the recovery catalog to Oracle Database 12c Release 1 (12.1.0.2) or higher:

  1. Use SQL*Plus to connect to the recovery catalog database as the SYS user with the SYSDBA privilege.
  2. Run the dbmsrmansys.sql script to grant additional privileges that are required for the RECOVERY_CATALOG_OWNER role.

SQL> @$ORACLE_HOME/rdbms/admin/dbmsrmansys.sql

  1. Start RMAN and connect RMAN to the recovery catalog database.
  2. Run the UPGRADE CATALOG command:

RMAN> UPGRADE CATALOG;

recovery catalog owner is rman

enter UPGRADE CATALOG command again to confirm catalog upgrade

  1. Run the UPDATE CATALOG command again to confirm:

RMAN> UPGRADE CATALOG;

recovery catalog upgraded to version 12.01.00.01

DBMS_RCVMAN package upgraded to version 12.01.00.01

DBMS_RCVCAT package upgraded to version 12.01.00.01

  1. Use SQL*Plus to connect to the recovery catalog database as the SYS user with SYSDBA privilege.

Run the dbmsmanvpc.sql script to upgrade virtual private catalog schemas to the VPD model.

The base recovery catalog schema name must be provided as an input parameter to this script.

The following command upgrades the virtual private catalog schemas of the base recovery catalog owned by rco:

SQL> @$ORACLE_HOME/rdbms/admin/dbmsrmanvpc.sql rco

About dbmsrmanvpc.sql and dbmsrmansys.sql

dbmsrmansys.sql用于创建相关权限角色,也会更新已授予相应角色的用户权限,dbmsrmanvpc.sql用于升级VPC,

SQL> @$ORACLE_HOME/rdbms/admin/dbmsrmansys.sql

SQL> @$ORACLE_HOME/rdbms/admin/dbmsrmanvpc.sql

Checking the operating user... Passed

Usage: dbmsrmanvpc.sql -vpd <base catalog schema name>

      dbmsrmanvpc.sql -novpd <base catalog schema name>

      dbmsrmanvpc.sql -scan [<base catalog schema name>]

      dbmsrmanvpc.sql <base catalog schema name> [...]

      dbmsrmanvpc.sql -all

This script performs an upgrade of RMAN base catalog and corresponding VPC users schemas to a new VPD model.

-vpd command grants required privileges to support VPD protected catalog.

Connect to RMAN base catalog and perform UPGRADE CATALOG after the VPD privileges are granted.

After UPGRADE CATALOG is performed for the base catalog schemas a cleanup of VPC schemas has to take place for that the RMAN base catalog schema names have to be supplied as command line parameters.  

使用-vpd可以指定10个catalog schema, 使用-all可以自动发现并升级

Up to 10 schema names can be supplied per script execution. When -all is specified the script attempts to detect the RMAN base catalog schemas automatically and perform the upgrade.

-novpd command removes VPD support: cleans up the base catalog schema,

revokes grants and removes database objects to disable VPD facilities.

This is only possible when there are no existing VPC users registered in that catalog.

-scan command performs a scan of RMAN base catalog owner schemas and

reports on granted roles and VPC users status.

  1. Importing and Moving a Recovery Catalog

Oracle建议将所有已存在的catalog导入到一个最新版本的recovery catalog中

A target database, recovery catalog database, and recovery catalog schema can be at different database versions. The recommended practice is to import all existing recovery catalogs into a single recovery catalog at the latest version of the recovery catalog schema.

如果import失败会回滚,默认在成功import后会执行unregister,即从source catalog中注销相应数据库,在destination catalog中进行register

If the operation fails in the middle of the import, then the import is rolled back. Thus, a partial import is not permitted. The unregister operation is separate from the import. By default, the imported database IDs are unregistered from the source recovery catalog schema after a successful import.

可以使用NO UNREGISTER选项不在source catalog中进行注销

You can also specify the NO UNREGISTER option to specify that the databases is not unregistered from the source catalog.

在导入时global script可能重名,这时会自动重命名

It is possible for global scripts, but not local scripts, to have name conflicts during import because the destination schema already contains the script name. In this case, RMAN renames the global script name to COPY OF script_name. For example, RMAN renames bp_cmd to COPY OF bp_cmd.

If the renamed global script is still not unique, then RMAN renames it to COPY(2) OF script_name. If this script name also exists, then RMAN renames the script to COPY(3) OF script_name. RMAN continues the COPY(n) OF pattern until the script is uniquely named.

Prerequisites

  1. RMAN must be connected to the destination recovery catalog, which is the catalog into which you want to import catalog data. This recovery catalog must not be a virtual private catalog.
  2. No target database connection is needed to merge catalog schemas. Execute this command at the RMAN prompt.
  3. The version of the source recovery catalog schema must be equal to the current version of the destination recovery catalog schema. If they are not equal, then upgrade the schemas to the same version.
  4. Ensure that the same database is not registered in both the source recovery catalog schema and destination catalog schema. If a database is registered in both schemas, then UNREGISTER this database from source recovery catalog and execute the IMPORT command again.

Importing a Recovery Catalog

In this example, database srcdb contains a 10.2 recovery catalog schema owned by user 102cat, while database destdb contains an 11.1 recovery catalog schema owned by user 111cat.

To import a recovery catalog:

  1. Start RMAN and connect as CATALOG to the destination recovery catalog schema.

$ rman

RMAN> CONNECT CATALOG 111cat@destdb;

  1. Import the source recovery catalog schema, specifying the connection string for the source catalog.

IMPORT CATALOG 102cat@srcdb;

可以指定导入部分target database:

You can specify the databases by DBID or database name, as shown in the following examples:

IMPORT CATALOG 102cat@srcdb DBID=1423241, 1423242;

IMPORT CATALOG 102cat@srcdb DB_NAME=prod3, prod4;

  1. Optionally, connect to a target database to check that the metadata was successfully imported.

CONNECT TARGET "sbu@prod1 AS SYSBACKUP";

LIST BACKUP;

Protecting the Recovery Catalog

Catalog数据库的备份频率一般与target库相同频率

Protect the recovery catalog like any other part of your database, by backing it up.

Back up the recovery catalog with the same frequency that you back up a target database. For example, if you make a weekly whole database backup of a target database, then back up the recovery catalog after the backup of the target database.

一般通过RMAN with nocatalog来定时备份,另外可以用逻辑导入导出作为补充

When backing up the recovery catalog database, you can use RMAN to make the backups. Logical backups of the RMAN recovery catalog created with the Data Pump Export utility can be a useful supplement for physical backups.


Follow these guidelines when developing an RMAN backup strategy for catalog database:

  1. Run the recovery catalog database in ARCHIVELOG mode so that you can do point-in-time recovery if needed.
  2. Set the retention policy to a REDUNDANCY value greater than 1.
  3. Back up the database to two separate media (for example, disk and tape).
  4. Run BACKUP DATABASE PLUS ARCHIVELOG at regular intervals, to a media manager if available, or just to disk.
  5. Do not use another recovery catalog as the repository for the backups.
  6. Configure the control file autobackup feature to ON.

)Managing Stored Scripts

Local script只能对于的target database使用,global script可以被所有注册数据库使用

Stored scripts can be local or global. A local script is associated with the target database to which RMAN is connected when the script is created, and can only be executed when you are connected to that target database. A global stored script can be run against any database registered in the recovery catalog, if the RMAN client is connected to the recovery catalog and a target database.

CREATE SCRIPT里的内容与RUN块里命令是一样的,它们均不能使用RUN,@,@@

The commands allowable within the brackets of the CREATE SCRIPT command are the same commands supported within a RUN block. Any command that is legal within a RUN command is permitted in the stored script.

The following commands are not legal within stored scripts: RUN, @, and @@.

Local script可与global script重名

  1. Creating/Deleting Stored Scripts

Start RMAN and connect to a target database and recovery catalog (if used).

LOCAL SCRIPT:

CREATE SCRIPT full_backup

{ BACKUP DATABASE PLUS ARCHIVELOG;

 DELETE OBSOLETE;}

GLOBAL SCRIPT:

CREATE GLOBAL SCRIPT global_full_backup

{ BACKUP DATABASE PLUS ARCHIVELOG;

 DELETE OBSOLETE;}

COMMENT:

CREATE GLOBAL SCRIPT global_full_backup

COMMENT 'use only with ARCHIVELOG mode databases'

{ BACKUP DATABASE PLUS ARCHIVELOG;

 DELETE OBSOLETE;}

You can also create a script by reading its contents from a text file.The file must begin with a left brace ({) character, contain a series of commands valid within a RUN block, and end with a right brace (}) character. 

CREATE SCRIPT full_backup FROM FILE '/tmp/my_script_file.txt';

REPLACE SCRIPT:

REPLACE SCRIPT full_backup

{ BACKUP DATABASE PLUS ARCHIVELOG;}

REPLACE GLOBAL SCRIPT

REPLACE GLOBAL SCRIPT global_full_backup

COMMENT 'A script for full backup to be used with any database'

{ BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;}

As with CREATE SCRIPT, you can update a local or global stored script from a text file with the following form of the command:

REPLACE GLOBAL SCRIPT global_full_backup FROM FILE '/tmp/my_script_file.txt';

Use the DELETE GLOBAL SCRIPT command to delete a stored script from the recovery catalog.

DELETE SCRIPT 'global_full_backup';

DELETE GLOBAL SCRIPT 'global_full_backup';

  1. Executing Stored Scripts

Use the EXECUTE SCRIPT command to run a stored script.

If GLOBAL is not specified, then RMAN searches for a local stored script defined for the current target database. If no local script with this name is found, then RMAN searches for a global script by the same name and executes it if one is found.

Run EXECUTE SCRIPT . This command requires a RUN block, as shown in the following example:

RUN { EXECUTE GLOBAL SCRIPT global_full_backup;}

RUN { EXECUTE SCRIPT global_full_backup; }

To create and use a dynamic stored script:

CREATE SCRIPT quarterly {

  ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS 'ENV=(OB_MEDIA_FAMILY=&1)';

  BACKUP TAG &2 FORMAT '/disk2/&1%U.bck' KEEP FOREVER RESTORE POINT &3 DATABASE;}

两种使用方法

$ rman TARGET / CATALOG rco@catdb USING arc_backup bck0906 FY06Q3

RMAN> RUN

{ EXECUTE SCRIPT quarterly}

RMAN> RUN

{ EXECUTE SCRIPT quarterly USING arc_backup bck1206 FY06Q4; }

To run the RMAN client and start a stored script in the recovery catalog on startup, use the SCRIPT argument when starting the RMAN client.

$ rman TARGET / CATALOG rco@catdb SCRIPT '/tmp/fbkp.cmd';

  1. Other Operations
  1. The PRINT SCRIPT command displays a stored script or writes it out to a file.

PRINT SCRIPT full_backup;

PRINT SCRIPT full_backup TO FILE '/tmp/my_script_file.txt';

For global scripts, the analogous syntax is as follows:

PRINT GLOBAL SCRIPT global_full_backup;

PRINT GLOBAL SCRIPT global_full_backup TO FILE '/tmp/my_script_file.txt';

  1. Use the LIST ... SCRIPT NAMES command to display the names of scripts defined in the recovery catalog.

LIST GLOBAL SCRIPT NAMES and LIST ALL SCRIPT NAMES are the only commands that work when RMAN is connected to a recovery catalog without connecting to a target instance;

LIST SCRIPT NAMES;

LIST GLOBAL SCRIPT NAMES;

LIST ALL SCRIPT NAMES;

)Querying Recovery Catalog Views

The LIST, REPORT, and SHOW commands provide the easiest means of accessing the data in the control file and the recovery catalog. Nevertheless, you can sometimes also obtain useful information from the recovery catalog views, which reside in the recovery catalog schema and use the RC_ prefix.

通常RC视图与target库中的v$视图对应,RC视图显示信息没有RMAN report命令直观,一般你要过滤目标库及相应incarnation(DB_KEY与DBINC_KEY),另外查询也需要并联多表

Most of the catalog views have a corresponding V$ view in the database. For example, RC_BACKUP_PIECE corresponds to V$BACKUP_PIECE. In general, the recovery catalog views are not as user-friendly as the RMAN reporting commands. For example, when you start RMAN and connect to a target database, you obtain the information for this target database only when you issue LIST, REPORT, and SHOW commands.

If you have 10 different target databases registered in the same recovery catalog, then any query of the catalog views shows the metadata for all incarnations of all 10 databases. You often must perform complex selects and joins among the views to extract usable information about a database incarnation.

DB_KEY一般通过DBID查询:

SELECT DB_KEY FROM RC_DATABASE WHERE DBID = dbid_of_target;

RC查询示例:

SELECT BS_KEY, BACKUP_TYPE, COMPLETION_TIME

FROM   RC_DATABASE_INCARNATION i, RC_BACKUP_SET b

WHERE  i.DB_KEY = 1

AND    i.DB_KEY = b.DB_KEY

AND    i.CURRENT_INCARNATION = 'YES';

你也可以在执行时指定当前DBID:

Specify the DBID of a database registered in the recovery catalog, as shown in the following example:

SQL> CALL DBMS_RCVMAN.SETDATABASE(null,null,null,2283997583);

The fourth parameter must be the DBID of a database registered in the recovery catalog. The other parameters must all be NULL.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值