RMAN-使用catalog恢复目录进行备份与恢复

RMAN Architecture
The RMAN architecture, shown in Figure 7-3, includes a target database, repository, and Media Management Layer, as well as Server Processes, Channels, Backup Sets, and Backup Pieces. The target database is the database that is either being backed up or restored. RMAN connects to the target database using server sessions. The repository is a separate database or schema that contains the metadata about your target database, as well as all of the backup and recovery information connected with that database for maintenance purposes. It can keep track of all of the information about every backup that you perform, including all of the file information, the time of the backup, and the database incarnation (the database version) at the time of the backup. This information can all be used to restore files and recover the database by issuing very simple restore and recovery commands. All of the information needed to complete these operations is stored in the repository. This repository can be implemented in one of two ways:
■ By using control files
■ As a recovery catalog database
Control files are the default option for implementing a repository since backup information is written to control files making the recovery catalog optional. Using a control file, however, limits the functionality of RMAN, while a recovery catalog provides you with the use of all RMAN features (this option is strongly recommended). Some of the advantages that a recovery catalog gives include the following:
■ The catalog will store the physical structure of the target database, as well as backups of data files, control files, and archive logs.
■ You can store scripts of common tasks.
■ Multiple databases can be managed from one location.
■ Complete reporting capabilities
■ Access to a longer history of backups and metadata
■ Ability to perform recovery when control files are lostA complete set of options when you try to restore from previous backup sets
■ More recovery flexibility and options
One disadvantage of using an RMAN recovery is that it needs to be managed itself. However, this is a small database or schema, so maintenance is minimal. Also, one RMAN catalog can manage multiple databases. Backups can be performed easily through a hot backup or database export. You also need to keep the recovery catalog in sync with the control files, which is performed with the RMAN-provided resync command.

1、Set Up a Recovery Catalog and Target Database
Setting up a recovery catalog is a very simple process. This can be done through the Enterprise Manager GUI or through some simple commands in SQL*Plus and the RMAN command-line interface. In SQL*Plus, all you need to do is to create a tablespace to store the catalog data in, create an RMAN user, and then grant the  recovery_catalog_owner role to the RMAN user. In RMAN, run the  create     catalogstatement:  (使用恢复目录对数据库进行备份,以sys连接到rman实例,创建数据表空间,创建rcat用户并授权)以下测试时单独新建了一个实例rman,也可以不用新建,跟目标数据库使用同一个实例。                                    

SQL> conn sys/rman@rman as sysdba;--最好单独创建一个新的实例rman,并使用sys用户连接到rman
已连接。
SQL> create tablespace rcatts datafile 'D:\rman\rman_data\rcatts.dbf' size 1024M;

表空间已创建。

SQL> create user rcat identified by rcat temporary tablespace temp
  2     default tablespace rcatts quota unlimited on rcatts;

用户已创建。

SQL> grant connect, resource, recovery_catalog_owner to rcat;

授权成功。

SQL> exit
从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开

C:\Users\Administrator>

2、In the RMAN command-line interface, log in and create the catalog:

(使用上一步创建的rcat用户登录并创建恢复目录)

C:\Users\Administrator>rman catalog=rcat/rcat@rman;

恢复管理器: Release 11.2.0.1.0 - Production on 星期二 10月 7 23:52:05 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

连接到恢复目录数据库

RMAN> create catalog;

恢复目录已创建

RMAN>

3、把目标数据库注册到恢复目录catalog中

Now you need to register the target database in the catalog. To do this, connect to the target and the catalog database and then register the target database in the catalog. This can be done from either location. The target connection must have a user ID with sysdba privileges, so an Oracle password file must be created using the orapwd utility. As described in Chapter 3, you also need to create the Oracle networking configuration using tnsnames or an equivalent for both the target and recovery catalog instances:

RMAN> connect catalog rcat/rcat@rman;--连接到恢复目录数据库

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06167: 已经连接

RMAN> connect target rusky/rusky@orcl;--连接目标数据库orcl,用户为rusky,密码为rusky

连接到目标数据库: ORCL (DBID=1385990360)

RMAN> register database;

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

RMAN>

4、It’s now time to back up your entire database

连接恢复目录,连接目标数据库

C:\Users\Administrator>rman target rusky/rusky@orcl catalog rcat/rcat@rman;

恢复管理器: Release 11.2.0.1.0 - Production on 星期日 10月 12 21:45:51 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

连接到目标数据库: ORCL 
连接到恢复目录数据库

RMAN>

备份数据库。

RMAN> configure default device type to disk;--可不用指定,使用默认。可使用show all 查看configure参数
RMAN> configure controlfile autobackup on;--默认值off,一般设置为on,即备份目标数据库的同时备份控件文件
RMAN> backup database plus archivelog;--备份数据库库的同时备份归档文件。如果想单独备份归档文件,可使用命令:backup archivelog all;
RMAN> exit;

5、上一步数据库已完全备份成功,可设置一个恢复的环境,如可关闭数据库并且删除所有的数据文件、归档日志、控制文件、参数文件等。

To do this, shut down the database and delete all of the data files, archive logs, control files, and the spfile SPFILEORA11G.ora for the target database.
6、恢复数据库
重新连接到恢复目录和目标数据库,并将数据库置于nomount状态。

RMAN> connect catalog rcat/rcat@rman;
RMAN> connect target rusky/rusky@orcl;
RMAN> startup nomount;
RMAN> restore archivelog all;
RMAN> restore controlfile; --resotrer控制文件、参数文件、归档日志文件只能在nomount状态。
RMAN> alter database mount;
RMAN> restore database;--restore数据文件要先mount
RMAN> recover database;
RMAN> alter database open resetlogs;

7、其它相关操作

(1) 在rman提示符下来验证成功注册的数据库。
RMAN>Report Schema;
(2) 删除恢复目录
如同可以创建恢复目录模式,你也可以删除恢复目录模式。使用drop catalog命令可以删除恢复目录模式。当删除恢复目录模式,包含在模式中的所有信息都会丢失,因此在删除模式之前应该考虑备份恢复目录模式数据库。两次drop catalog
RMAN> drop catalog;

恢复目录所有者是RMAN
再输入一次 DROP CATALOG 命令来确认目录删除

RMAN> drop catalog;

恢复目录已删除

RMAN>
(3) 恢复目录中取消数据库注册
可在RMAN中使用unregister database命令来取消数据库注册。如果希望取消已存在的数据库注册,只要连接到数据库和恢复目录,并执行unregister database命令即可:
RMAN>unregister database;

如果数据库已删除,并且希望从恢复目录中删除该数据库,则大多数情况下只需要知道希望取消注册的数据库的名称。如希望取消注册orcl数据库实例。则可连接到恢复目录执行以下命令:
RMAN>Unregister database orcl;

8、恢复目录的备份

恢复目录本身也需要做备份,恢复目录的备份只能使用exp/imp导出导入方式进行备份。

RMAN不能用于备份初始化参数文件和口令文件。

9、更新恢复目录
为了支持更新的RMAN客户端,例如RMAN恢复目录版本是10g,而新的RMAN客户端是11G,使用upgrade catalog命令更新本地包和模式,与drop catalog一样,需要连接到恢复目录,但是无需连接到目标数据库:
RMAN> upgrade catalog;

恢复目录所有者是RCAT
再输入一次 UPGRADE CATALOG 命令来确认目录升级

RMAN> upgrade catalog;

恢复目录已升级到版本11.02.00.01
DBMS_RCVMAN 程序包升级为 11.02.00.01 版
DBMS_RCVCAT 程序包升级为 11.02.00.01 版

RMAN>

==============RMAN-catalog和nocatalog的区别====================================

注意,当使用rman nocatalog恢复时,数据库必须是处于“mount”状态的。而Oracle startup mount的前提条件是control必须存在。因此,你必须在恢复datafile之前先恢复controlfile。 使用rman catalog方式时,可以startup nomount然后restore controlfile;但使用rman nocatalog时,必须先用文件方式恢复controlfile。

下面对比一下rman nocatalog和rman catalog的恢复时的步骤,以便建立正确的备份策略(以下的恢复都是在online状态下的备份):
rman nocatalog恢复:
1) 建立oracle运行环境(包括init或sp文件)
2) 文件方式恢复controlfile到init文件指定的位置
3) startup mount
4) rman,恢复datafile
5) alter database open resetlogs

rman catalog恢复:
1) 建立oracle运行环境(包括init或sp文件)
2) rman ,restore controfile
3) alter database mount
4) rman, restore datafile
5) alter database open resetlogs

可以看出,rman nocatalog备份时,必须用文件方式备份controlfile。

==================

Report schema              Report shema是指在数据库中查找schema

List backup                   从control读取信息

Crosscheck backup       看一下backup的文件,检查controlfile中的目录或文件是否真正在磁盘上

Delete backupset 24      24代表backupset 的编号, 既delete目录,也delete你的文件

===================== 

The purpose of the RMAN recovery catalog:
A recovery catalog is a database schema used by RMAN to store metadata about one or more Oracle databases. Typically, you store the catalog in a dedicated database. A recovery catalog provides the following benefits:
A recovery catalog creates redundancy for the RMAN repository stored in the control file of each target database. The recovery catalog serves as a secondary metadata repository. If the target control file and all backups are lost, then the RMAN metadata still exists in the recovery catalog.
A recovery catalog centralizes metadata for all your target databases. Storing the metadata in a single place makes reporting and administration tasks easier to perform.
A recovery catalog can store metadata history much longer than the control file. This capability is useful if you must do a recovery that goes further back in time
than the history in the control file. The added complexity of managing a recovery catalog database can be offset by the convenience of having the extended backup
history available.
Some RMAN features function only when you use a recovery catalog. For example, you can store RMAN scripts in a recovery catalog. The chief advantage of a stored script is that it is available to any RMAN client that can connect to the target database and recovery catalog. Command files are only available if the RMAN client has access to the file system on which they are stored.
A recovery catalog is required when you use RMAN in a Data Guard environment. By storing backup metadata for all primary and standby databases, the catalog enables you to offload backup tasks to one standby database while enabling you to restore backups on other databases in the environment.

======FROM=======

http://blog.csdn.net/tianlesoftware/article/details/5641763

[oracle数据库11G初学者指南].Oracle.Database.11g,.A.Beginner's.Guide

posted on 2014-10-08 00:31  遠離塵世の方舟  阅读(2503)  评论(0编辑  收藏  举报

导航