1. 恢复目录概念
恢复目录(Recovery Catalog)是Oracle
RMAN的重要组成部分,用于存储RMAN备份和恢复相关的元数据信息。与控制文件相比,恢复目录提供了更强大的功能和更长期的备份历史记录。更多学习教程www.fgedu.net.cn
2. 恢复目录创建
创建恢复目录需要先创建一个专门的数据库,然后在其中创建恢复目录模式。
# sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 – Production on Thu Mar 31 10:00:00 2026
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to an idle instance.
SQL> STARTUP NOMOUNT;ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 8897512 bytes
Variable Size 587202568 bytes
Database Buffers 469762048 bytes
Redo Buffers 7876608 bytes
SQL> CREATE DATABASE rman_catalog
2 USER SYS IDENTIFIED BY password
3 USER SYSTEM IDENTIFIED BY password
4 LOGFILE GROUP 1 (‘/oracle/oradata/rman_catalog/redo01.log’) SIZE 50M,
5 GROUP 2 (‘/oracle/oradata/rman_catalog/redo02.log’) SIZE 50M
6 MAXLOGHISTORY 1
7 MAXLOGFILES 16
8 MAXLOGMEMBERS 3
9 MAXDATAFILES 100
10 CHARACTER SET AL32UTF8
11 NATIONAL CHARACTER SET AL16UTF16
12 EXTENT MANAGEMENT LOCAL
13 DATAFILE ‘/oracle/oradata/rman_catalog/system01.dbf’ SIZE 700M REUSE
14 SYSAUX DATAFILE ‘/oracle/oradata/rman_catalog/sysaux01.dbf’ SIZE 550M REUSE
15 DEFAULT TABLESPACE users
16 DATAFILE ‘/oracle/oradata/rman_catalog/users01.dbf’ SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
17 DEFAULT TEMPORARY TABLESPACE temp
18 TEMPFILE ‘/oracle/oradata/rman_catalog/temp01.dbf’ SIZE 200M REUSE
19 UNDO TABLESPACE undotbs1
20 DATAFILE ‘/oracle/oradata/rman_catalog/undotbs01.dbf’ SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;Database created.
SQL> @?/rdbms/admin/catalog.sql
SQL> @?/rdbms/admin/catproc.sql
SQL> @?/rdbms/admin/utlrp.sql
SQL> CREATE USER rman IDENTIFIED BY rman_password
2 DEFAULT TABLESPACE users
3 TEMPORARY TABLESPACE temp
4 QUOTA UNLIMITED ON users;User created.
SQL> GRANT RECOVERY_CATALOG_OWNER TO rman;Grant succeeded.
# rman catalog rman/rman_password
Recovery Manager: Release 19.0.0.0.0 – Production on Thu Mar 31 10:30:00 2026
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to recovery catalog database
RMAN> CREATE CATALOG;recovery catalog created
RMAN> EXIT;
3. 数据库注册
将目标数据库注册到恢复目录中,使RMAN可以在恢复目录中存储备份元数据。
# rman target / catalog rman/rman_password@rman_catalog
Recovery Manager: Release 19.0.0.0.0 – Production on Thu Mar 31 11:00:00 2026
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: FGEDUDB (DBID=1234567890)
connected to recovery catalog database
RMAN> REGISTER DATABASE;database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
RMAN> EXIT;
# rman target / catalog rman/rman_password@rman_catalog
RMAN> LIST DB_UNIQUE_NAME ALL;List of Databases
=================
DB Key DB Name DB ID Database Role Db_unique_name
——- ——- —————– ————— ——————
1 FGEDUDB 1234567890 PRIMARY fgedudb
4. 恢复目录备份
恢复目录本身也需要定期备份,以防止恢复目录丢失导致备份元数据丢失。
# rman target / catalog rman/rman_password@rman_catalog
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;Starting backup at 31-MAR-26
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=123 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=1 STAMP=1000000000
input archived log thread=1 sequence=2 RECID=2 STAMP=1000000001
channel ORA_DISK_1: starting piece 1 at 31-MAR-26
channel ORA_DISK_1: finished piece 1 at 31-MAR-26
piece handle=/backup/rman_catalog/arch_1_1_1000000000.bkp tag=TAG20260331T113000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/oradata/rman_catalog/system01.dbf
input datafile file number=00003 name=/oracle/oradata/rman_catalog/sysaux01.dbf
input datafile file number=00004 name=/oracle/oradata/rman_catalog/undotbs01.dbf
input datafile file number=00005 name=/oracle/oradata/rman_catalog/users01.dbf
channel ORA_DISK_1: starting piece 1 at 31-MAR-26
channel ORA_DISK_1: finished piece 1 at 31-MAR-26
piece handle=/backup/rman_catalog/db_full_1_1_1000000000.bkp tag=TAG20260331T113000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:05:23
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=3 STAMP=1000000002
channel ORA_DISK_1: starting piece 1 at 31-MAR-26
channel ORA_DISK_1: finished piece 1 at 31-MAR-26
piece handle=/backup/rman_catalog/arch_2_1_1000000002.bkp tag=TAG20260331T113000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-MAR-26
5. 恢复目录维护
定期维护恢复目录,包括同步、清理和优化操作。
# rman target / catalog rman/rman_password@rman_catalog
RMAN> RESYNC CATALOG;starting full resync of recovery catalog
full resync complete
RMAN> DELETE OBSOLETE;RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
——————– —— —————— ——————–
Backup Set 1 30-MAR-26 /backup/fgedudb/full_1_1_999999999.bkp
Backup Piece 1 30-MAR-26 /backup/fgedudb/full_1_1_999999999.bkp
Do you really want to delete the above objects (enter YES or NO)? YES
deleted backup piece
backup piece handle=/backup/fgedudb/full_1_1_999999999.bkp RECID=1 STAMP=999999999
Deleted 1 objects
# sqlplus rman/rman_password@rman_catalog
SQL> EXEC DBMS_RCVCAT.PURGE_RECYCLEBIN;PL/SQL procedure successfully completed.
SQL> EXEC DBMS_RCVCAT.SYNCHRONIZE;PL/SQL procedure successfully completed.
6. 恢复目录使用
使用恢复目录进行备份和恢复操作。
# rman target / catalog rman/rman_password@rman_catalog
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;Starting backup at 31-MAR-26
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=123 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=10 RECID=10 STAMP=1000000010
input archived log thread=1 sequence=11 RECID=11 STAMP=1000000011
channel ORA_DISK_1: starting piece 1 at 31-MAR-26
channel ORA_DISK_1: finished piece 1 at 31-MAR-26
piece handle=/backup/fgedudb/arch_1_1_1000000010.bkp tag=TAG20260331T120000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/oradata/fgedudb/system01.dbf
input datafile file number=00003 name=/oracle/oradata/fgedudb/sysaux01.dbf
input datafile file number=00004 name=/oracle/oradata/fgedudb/undotbs01.dbf
input datafile file number=00005 name=/oracle/oradata/fgedudb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 31-MAR-26
channel ORA_DISK_1: finished piece 1 at 31-MAR-26
piece handle=/backup/fgedudb/full_1_1_1000000010.bkp tag=TAG20260331T120000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:10:45
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12 RECID=12 STAMP=1000000012
channel ORA_DISK_1: starting piece 1 at 31-MAR-26
channel ORA_DISK_1: finished piece 1 at 31-MAR-26
piece handle=/backup/fgedudb/arch_2_1_1000000012.bkp tag=TAG20260331T120000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-MAR-26
7. 恢复目录安全
保护恢复目录的安全,确保备份元数据不被未授权访问。
# sqlplus / as sysdba@rman_catalog
SQL> REVOKE CREATE ANY TABLE FROM rman;Revoke succeeded.
SQL> REVOKE DROP ANY TABLE FROM rman;Revoke succeeded.
SQL> GRANT SELECT ON v$database TO rman;Grant succeeded.
SQL> AUDIT SELECT, INSERT, UPDATE, DELETE ON rman.rc_backup_set BY ACCESS;Audit succeeded.
8. 最佳实践
1. 使用独立的数据库存储恢复目录,避免与目标数据库在同一服务器上
2. 定期备份恢复目录,建议每天备份一次
3. 设置适当的保留策略,避免恢复目录过度增长
4. 定期同步恢复目录,确保元数据与控制文件一致
5. 对恢复目录进行定期维护,包括清理和优化
6. 限制恢复目录用户的权限,加强安全控制
7. 考虑使用Enterprise Manager来管理恢复目录
更多视频教程www.fgedu.net.cn
学习交流加群风哥微信: itpux-com
学习交流加群风哥QQ113257174
更多学习教程公众号风哥教程itpux_com
from oracle:www.itpux.com
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
