一、Recovery Catalog
利用RMAN备份时,默认使用控制文件保存RMAN资料库,资料库包含备份集、镜像备份、归档日志的备份信息。默认控制文件保存这些信息是7天,可以通过参数control_file_record_keep_time查看。
SYS@orcl>show parameter control_file_record_keep_time;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
该参数最大可以设置为365,也就是说备份的信息最长可以保存365天,但是实际上我们并不会设置到这么大,因为该值设大后,控制文件保存的备份信息会很多,控制文件也会大很多,这样不利于控制文件的维护,如果真的需要备份信息保存很长时间,我们可以使用Recovery Catalog。
一般利用RMAN恢复数据库需要数据库在mount或者open状态, 使用Recovery Catalog后数据库只要启动到mount状态,RMAN就可以得到备份信息。同时保存的备份信息不受control_file_record_keep_time参数的限制。Recovery Catalog还可以保存RMAN脚本,查看任何时间点的表空间和数据库文件结构
二、创建和使用Recovery Catalog
Recovery Catalog可以创建在目标数据库中,但是实际中为了保证catalog信息的安全性,应该把catalog放在不同服务器的另一个数据库上。以下例子使用名为'catadb'的数据库,TNS也为'catadb'。
创建Recovery Catalog有以下5个步骤:
1.在catalog数据库创建表空间
[oracle@ora ~]$ sqlplus sys/oracle@catadb as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Dec 29 15:44:15 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@catadb>create tablespace cata_ts datafile '/u01/app/oracle/oradata/catadb/cata_ts01.dbf' size 100m autoextend on next 10m;
Tablespace created.
2.创建数据库用户
SYS@catadb>create user catauser identified by oracle temporary tablespace temp default tablespace cata_ts quota unlimited on cata_ts;
User created.
3.将recovery_catalog_owner角色授予用户
SYS@catadb>grant recovery_catalog_owner to catauser;
Grant succeeded.
4.以新创建的用户通过rman连接到catalog数据库创建必须的对象
[oracle@ora ~]$ rman catalog catauser/oracle@catadb
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Dec 29 15:56:46 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to recovery catalog database
RMAN> create catalog;
recovery catalog created
5.将目标数据库的信息注册到catalog
[oracle@ora ~]$ rman target sys/oracle@orcl catalog catauser/oracle@catadb
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Dec 29 15:59:51 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1330943900)
connected to recovery catalog database
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
从此以后使用ramn连接目标数据库时使用catalog子句同时连接Recovery Catalog才可以保证控制文件和catalog之间的信息同步。我们也可以在catalog数据库中执行手动同步。
[oracle@ora ~]$ rman target sys/oracle@orcl catalog catauser/oracle@catadb
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Dec 29 16:08:19 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1330943900)
connected to recovery catalog database
RMAN> resync catalog;
starting full resync of recovery catalog
full resync complete
再使用rman备份数据库时可以连接catalog数据库,这样所有的备份信息会保存在catalog数据库中。
[oracle@ora ~]$ rman target sys/oracle@orcl catalog catauser/oracle@catadb
……输出省略……
RMAN> backup datafile 1;
……输出省略……
三、Recovery Catalog的其他功能
使用控制文件保存rman备份信息时,无法在数据库nomount状态查看备份信息,使用Recovery Catalog后可以在nomount状态查看备份信息。
[oracle@ora ~]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Dec 29 16:14:59 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (not mounted) ---目标数据库没有mount
RMAN> list backup; ---查询不到控制文件中保存的备份信息
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 12/29/2012 16:15:03
ORA-01507: database not mounted
[oracle@ora ~]$ rman target / catalog catauser/oracle@catadb
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Dec 29 16:18:06 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (not mounted) ---'not mounted'表示目标数据库没有mount,但是连接到catalog数据库
connected to recovery catalog database
RMAN> list backup summary; ---连接到catalog数据库可以查询备份信息
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
160 B F A DISK 29-DEC-12 1 1 NO TAG20121229T161103
161 B F A DISK 29-DEC-12 1 1 NO TAG20121229T161103
使用'report schema at'命令可以查看数据库数据文件的历史结构。
RMAN> report schema; ---查看当前的数据库数据文件结构
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 720 SYSTEM YES /u01/app/oracle/oradata/orcl/system01.dbf
2 580 SYSAUX NO /u01/app/oracle/oradata/orcl/sysaux01.dbf
3 105 UNDOTBS1 YES /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 108 USERS NO /u01/app/oracle/oradata/orcl/users01.dbf
5 345 EXAMPLE NO /u01/app/oracle/oradata/orcl/example01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 29 TEMP 32767 /u01/app/oracle/oradata/orcl/temp01.dbf
RMAN> report schema at time "sysdate-interval '2' day"; ---查询两天前数据库数据文件结构
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 720 SYSTEM YES /u01/app/oracle/oradata/orcl/system01.dbf
2 580 SYSAUX YES /u01/app/oracle/oradata/orcl/sysaux01.dbf
3 105 UNDOTBS1 YES /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 108 USERS YES /u01/app/oracle/oradata/orcl/users01.dbf
Recovery Catalog可以保存rman脚本。有两种方式创建rman脚本
1.执行create script或者create global scritp命令
RMAN> create script systemts_bak{
2> allocate channel c1 device type disk;
3> backup tablespace system;
4> }
created script systemts_bak
2.从现有的文本文件中载入
RMAN> create global script sysauxts_bak from file '/home/oracle/sysauxts_bak.rman';
script commands will be loaded from file /home/oracle/sysauxts_bak.rman
created script sysauxts_bak
'create script'和'create global script'命令不同在于'create script‘创建的脚本只能在当前目标数据库上执行,另外一个可以在所有已经注册的数据库上执行。
可以执行'list script names'或'list global script names'查看脚本的名字,执行'print script '或'print global script'查看脚本内容。执行'run {execute script 脚本名字 }'或'run {execute global 脚本名字}'调用脚本内容
四、删除注册数据库信息
要删除数据库的注册信息需要知道数据库的db_id和db_key,然后用catalog的管理用户登录catalog数据库执行过程dbms_rcvcat.unregisterdatabase(db_key,db_id)删除注册信息。
[oracle@ora ~]$ rman target / catalog catauser/oracle@catadb
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Dec 29 17:26:25 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (not mounted)
connected to recovery catalog database
RMAN> list incarnation; ---查询db_key和db_id
List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 16 ORCL 1330943900 PARENT 1 17-SEP-11
1 2 ORCL 1330943900 CURRENT 995548 27-DEC-12
[oracle@ora ~]$ sqlplus catauser/oracle@catadb;
SQL*Plus: Release 11.2.0.3.0 Production on Sat Dec 29 17:27:26 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
CATAUSER@catadb>exec dbms_rcvcat.unregisterdatabase(1,1330943900); ---删除注册信息
PL/SQL procedure successfully completed.
[oracle@ora ~]$ rman target / catalog catauser/oracle@catadb
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Dec 29 17:32:08 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1330943900)
connected to recovery catalog database
RMAN> list incarnation;
RMAN>