一、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>