一、创建恢复目录
创建恢复目录一般分为三大步骤
创建存放恢复目录的数据库(或使用已存在的数据库)
创建恢复目录的的所有者
创建恢复目录
创建数据库可以参考:Oralce 10g 使用DBCA创建数据库
在存储恢复目录的数据库创建表空间用于存储恢复目录schema及恢复目录数据(本文使用已经创建好的数据库catadb来存储恢复目录)
SQL> create tablespace tbs_rman datafile '/u01/app/Oracle/oradata/catadb/tbs_rman01.dbf'--创建rman恢复目录表空间
2 size 200m autoextend on;
SQL> create user rman identified by rman --创建rman schema
2 temporary tablespace temp
3 default tablespace tbs_rman
4 quota unlimited on tbs_rman;
SQL> grant recovery_catalog_owner to rman; --角色授予
SQL> conn rman/rman
SQL> select * from session_privs;
PRIVILEGE
----------------------------------------
CREATE SESSION
ALTER SESSION
CREATE TABLE
CREATE CLUSTER
CREATE SYNONYM
CREATE VIEW
CREATE SEQUENCE
CREATE DATABASE LINK
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
SQL> select * from session_roles;
ROLE
------------------------------
RECOVERY_CATALOG_OWNER
RMAN> connect catalog rman/rman@catadb --连接到恢复目录
connected to recovery catalog database
RMAN> create catalog tablespace tbs_rman; --创建恢复目录
recovery catalog created
[oracle@oradb ~]$ rman target sys/redhat@orcl catalog rman/rman@catadb --连接到目标数据库及恢复目录
connected to target database: ORCL (DBID=1260850162)
connected to recovery catalog database
RMAN> register database; --将目标数据库注册到恢复目录
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
二、基于恢复目录的备份
1.查看相关信息
RMAN> list incarnation;
List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 8 ORCL 1260850162 PARENT 1 30-JUN-05
1 2 ORCL 1260850162 CURRENT 446075 22-OCT-10
----------------------------------------------------------------------------------------------------
RMAN> crosscheck copy; --校验copy
RMAN> delete expired copy; --删除过期的copy
2.全备
RMAN> run{
2> allocate channel ch1 device type disk;
3> backup as compressed backupset
4> database plus archivelog delete input
5> format='/u01/app/oracle/bk/rmbk/Whole_%d_%U'
6> tag='Whole_bak';
7> release channel ch1;}
3.增量备份(0级)
RMAN> run{
2> allocate channel ch1 device type disk;
3> allocate channel ch2 device type disk;
4> backup as compressed backupset
5> incremental level 0
6> database plus archivelog delete input
7> format='/u01/app/oracle/bk/rmbk/Inc_0_%d_%U'
8> tag='Inc_0';
9> release channel ch1;
10> release channel ch2;}
RMAN> list backup summary;
4.增量备份(1级)
RMAN> run{
2> allocate channel ch1 device type disk;
3> allocate channel ch2 device type disk;
4> backup as compressed backupset
5> incremental level 1 database
6> format='/u01/app/oracle/bk/rmbk/Inc_1_%d_%U'
7> tag='Inc_1';
8> release channel ch1;
9> release channel ch2;}
RMAN> list backup by file;
5.累计增量备份(1级)
RMAN> run{
2> allocate channel ch1 device type disk;
3> backup as compressed backupset
4> incremental level 1 cumulative database
5> format '/u01/app/oracle/bk/rmbk/Cum_1_%d_%U'
6> tag='Cum_1';
7> release channel ch1;}
6.备份表空间
RMAN> run{
2> allocate channel ch1 device type disk;
3> backup as compressed backupset
4> tablespace users,example
5> format='/u01/app/oracle/bk/rmbk/tbs_%d_%U'
6> tag='tbs';
RMAN> list backupset tag=tbs;
7.备份数据文件
RMAN> run{
2> allocate channel ch1 device type disk;
3> backup as compressed backupset
4> datafile 3
5> format='/u01/app/oracle/bk/rmbk/df_%d_%U'
6> tag='df';
7> release channel ch1;}
8.备份归档日志
备份归档日志前,建议先使用crosscheck校验一下
crosscheck通常用于检查备份是否被删除,如果删除将会打上删除标签
RMAN> crosscheck archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 devtype=DISK
validation succeeded for archived log
archive log filename=/u01/app/oracle/oradata/orcl/arch/log_1_117_733069427.arc recid=111 stamp=733171369
Crosschecked 1 objects
RMAN> sql 'alter system switch logfile';
sql statement: alter system switch logfile
RMAN> sql 'alter system switch logfile';
sql statement: alter system switch logfile
RMAN> list archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
465 1 117 A 22-OCT-10 /u01/app/oracle/oradata/orcl/arch/log_1_117_733069427.arc
553 1 118 A 23-OCT-10 /u01/app/oracle/oradata/orcl/arch/log_1_118_733069427.arc
569 1 119 A 23-OCT-10 /u01/app/oracle/oradata/orcl/arch/log_1_119_733069427.arc
9.基于SCN来备份归档日志
RMAN> run{
2> allocate channel ch1 device type disk;
3> backup as compressed backupset
4> archivelog from scn 848043
5> format='/u01/app/oracle/bk/rmbk/arc_%d_%U'
6> tag='arc';
7> release channel ch1;
8> }
10.镜像备份
RMAN> run{
2> allocate channel ch1 device type disk;
3> backup as copy datafile 1,4
4> format '/u01/app/oracle/bk/rmbk/df_%d_%U'
5> tag 'copybak';
6> release channel ch1;}
11.其它
RMAN> crosscheck backupset;
RMAN> change backupset 1
RMAN> validate backupset
RMAN> validate backupset 635;
12.基于catalog的数据库恢复请参考:基于catalog 的RMAN 备份与恢复
三、更多参考
有关基于用户管理的备份和备份恢复的概念请参考:
Oracle 基于用户管理恢复的处理(详细描述了介质恢复及其处理)
有关RMAN的恢复与管理请参考:
RMAN 还原与恢复
有关Oracle体系结构请参考:
Oracle 实例和Oracle数据库(Oracle体系结构)
Oracle 联机重做日志文件(ONLINE LOG FILE)