Oracle Database Backup and Recovery

Stone大约 202 分钟

Oracle Database Backup and Recovery

Overview

故障类型

数据库的故障分为:

  • 语句失败,包括:

    • 向表插入无效的数据,需要验证并纠正数据。

    • 用户权限不够,需要授予用户合理的系统和对象权限。

    • 分配空间失败,需要增加用户配额或者增大表空间。

    • 应用的逻辑错误,需要开发人员调整应用逻辑。

  • 用户进程失败,异常的连接,会话或者程序错误都会导致用户进程失败,PMON进程定期查看服务器进程确保所属会话都连接正常,如果PMON发现服务器进程中的用户连接异常,则PMON回滚该会话未提交的事务并释放锁。一般不需要DBA进行解决,如果有大量的用户进程失败才需要去关注。

  • 网络故障,包括:

    • 监听失效,可以冗余监听。
    • 网卡,网络设备,可以冗余网卡和网络设备。
    • 线路故障,可以冗余网络线路。
  • 用户错误,包括:

    • 意外删除或者修改数据,如果没有提交,回滚。如果提交了,可以使用闪回表。
    • 意外删除表,如何还在回收站,使用闪回删除,如果使用了purge删除或者清空了回收站,还可以使用基于时间点的恢复。
  • 实例失败,由于断电,硬件故障,软件BUG,或者使用了SHUTDOWN ABORT和STARTUP FORCE命令,那么数据库在关闭前都无法进行数据文件同步,则下次启动就需要进行实例恢复(Instance Recovery)。如果安装了ORACLE RESTART,在实例失败的时候,就会自动去重启实例并进行恢复。

  • 介质失败,如果丢失数据库操作所需要的文件(文件被删除或者磁盘故障),就需要进行文件还原(Restore)和介质恢复(Media Recovery)。

实例恢复

当实例去打开数据文件的时候,数据文件头部中的SCN与控制文件中的SCN不匹配的时候(参考CKPT,就需要进行实例恢复(Instance Recovery)。使用联机日志文件的REDO数据重做事务,所有数据文件同步后,就可以打开数据库并登录到实例失败的时刻,但这个时刻包括没有提交的事务,则数据库会使用UNDO数据自动进行回滚,之后数据文件就只包括提交的数据了。

Description of Figure 13-6 follows

由于CKPT进程每3秒就会将联机重做日志文件中的检查点位置写入到控制文件,因此,就不需要使用检查点之前的重做日志文件进行数据库恢复,只需要使用检查点之后的重做日志文件进行恢复。

Description of Figure 13-5 follows

将数据文件最后一个检查点恢复到控制文件记录的最新的SCN位置的时间就是实例恢复所需要的时间,可以通过设置FAST_START_MTTR_TARGET参数控制这个时间。如果设置为0表示禁用,最大可以设置为3600秒。较小的FAST_START_MTTR_TARGET会增加I/O,影响性能,较大的FAST_START_MTTR_TARGET会增加恢复时间。

基本概念

备份策略:

  • Whole database backup:整个数据库备份,包括数据文件和至少一个控制文件

  • Partial database backup:部分数据库备份,可以包含一个或者多个表空间以及一个或者多个数据文件,可以包含也可以不包含控制文件

备份类型:

  • Full backup:备份文件中包含数据的所有块

  • Incremental backup:只备份上次备份后修改过的块。支持两种级别的增量备份(0级和1级),1级增量备份有2种:

    • cumulative:备份自0级以来所有的改变

    • differential:备份自上次增量备份后的所有的改变(可以是0级也可以是1级)

备份模式:

  • Offline backup:离线备份也称为冷备份或者一致备份,在数据库没有打开时进行的备份,在备份的时候,数据文件头部的SCN等于控制文件的SCN

  • Online backup:在线备份也成为热备份或者不一致备份,在数据库打开的时候进行的备份,不保证数据文件和控制文件同步

备份可以存储为:

  • Image copies:镜像拷贝,就是数据文件或者归档日志文件的拷贝,只能备份到磁盘,会备份文件中的所有块,不管有没有数据,且会检查是否存在坏块,优势是恢复快,可以直接指定镜像拷贝的位置
  • Backup sets:备份集,一个或者多个二进制文件的集合,包括一个或者多个数据文件,控制文件,服务器参数文件或者归档日志文件。使用备份集不会备份没有数据的数据块,占用更少的磁盘或者磁带空间,而且还可以进行压缩

RMAN

RMAN是Oracle提供的一个备份和恢复工具,可以用于备份数据文件,控制文件,重做日志归档文件,服务器参数文件,可以进行一致备份,不一致备份,增量备份,全备,整个数据库备份或者部分数据库备份,可以备份到磁盘或者磁带。可以备份成备份集或者镜像拷贝。

启动rman可以使用以下选项:

  • target:指定连接到目标数据库,"/"表示连接到本地数据库,使用操作系统认证
  • catalog:指定连接到恢复目录
  • nocatalog:不使用恢复目录,默认选项
  • cmdfile:指定命令文件
  • log:指定日志文件

例子:rman连接到本地数据库,使用操作系统认证,指定命令文件和日志文件

$ rman target / cmdfile=~/fullbu.rman log=~/fullbu.log

RMAN命令有2种基本类型:

  • stand-alone:在rman提示符后面输入,例如CHANGE,CONNECT,CREATE CATALOG, RESYNC CATALOG,CREATE SCRIPT, DELETE SCRIPT, REPLACE SCRIPT
  • job commands:run命令块中的一组命令,其中有一条命令执行失败,则rman停止处理,前面执行成功的命令不撤销,例如allocate channel命令只能在run块中运行,为当前执行的job分配通道。

有一些命令既可以是stand-alone,也可以是job command,比如backup database。

job commands必须都位于run块中,使用大括号括起来,run块中的配置只影响当前块的执行,覆盖之前的配置。必须位于run块中的命令有:

  • allocate channel
  • switch

归档模式

数据库数据被修改时重做数据会被写入到联机重做日志文件,当写满后,归档进程复制联机重做日志文件到归档位置进行保存。因为联机重做日志文件是循环写入,在归档模式下,只能向已经归档的联机重做日志文件进行写入,确保每个联机重做日志文件都会被归档。

例子:配置数据库为归档模式

SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     173
Current log sequence           175

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area  889389056 bytes
Fixed Size                  2258360 bytes
Variable Size             662702664 bytes
Database Buffers          218103808 bytes
Redo Buffers                6324224 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     173
Next log sequence to archive   175
Current log sequence           175
  • 当数据库处于NOARCHIVELOG模式(默认),只能恢复到最后一次备份的时刻,之后的事务都将丢失。
  • 当数据库处于ARCHIVELOG模式,可以使用归档日志恢复到最后一次提交的时刻,大多数生产数据库都运行在归档模式。

注意:切换到归档模式后需要对数据库进行一次备份。

Oracle建议指定多个归档位置,因为如果只有1个且空间不足的话,数据库会hang住。

Oracle建议通过设置LOG_ARCHIVE_DEST_N初始化参数指定本地和远程归档位置,可以指定31个,n从1到31。

  • 如果指定本地位置,使用"location=",后面跟本地目录,例如log_archive_dest_1='location=/disk3/arch'
  • 如果指定备库远程位置,使用"service=",后面跟备库实例的网络服务名,例如log_archive_dest_2='service=standy1'

如果是Oracle标准版,则只能设置log_archive_dest和log_archive_duplex_dest这两个初始化参数,指定2个本地磁盘目录作为归档位置。

如果指定了不止一个归档位置,则需要设置log_archive_min_succeed_dest初始化参数指定必须归档成功的最小数量。如果归档成功的数量不满足设置,则联机重做日志文件不能重用。

如果使用了log_archive_dest_n参数设置归档位置,根据n的大小,则log_archive_min_succeed_dest可以从1到31,如果使用了log_archive_dest,则log_archive_min_succeed_dest只能为1或者2。

可以使用mandatory或者optional,指定归档位置是必须归档还是可选归档(默认),例如:

log_archive_dest_1='location=/disk3/arch mandatory'

如果必须归档位置归档失败,则联机重做日志文件不能重用,忽略log_archive_min_succeed_dest的设置。

SQL> show parameter log_archive_min_succeed_dest

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------
log_archive_min_succeed_dest         integer     1

快速恢复区

快速恢复区(Fast Recovery Area)用于存放归档日志文件,备份,闪回日志,备用控制文件,备用重做日志文件。Oracle建议使用快速恢复区简化备份存储管理,并与数据文件、主联机重做日志文件和主控制文件分开存放在不同的位置。

  • 根据数据库业务情况和保留策略配置快速恢复区大小。
  • 通过参数DB_RECOVERY_FILE_DEST指定快速恢复区位置。
  • 通过参数DB_RECOVERY_FILE_DEST_SIZE指定快速恢复区大小。
  • 可以通过备份保留策略和归档日志删除策略来管理快速恢复区空间。

例子:查看快速恢复区位置和大小

SQL> show parameter db_recovery_file_dest

NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------------------------
db_recovery_file_dest                string      /u01/app/oracle/fast_recovery_area
db_recovery_file_dest_size           big integer 200G

快速恢复区包括2种类型的文件:永久类型和临时类型。

永久类型有:

  • 控制文件:根据初始化参数设置,在创建数据库的时候会在快速恢复区创建一个控制文件副本
  • 联机重做日志文件副本:在创建数据库的时候,通过logfile语句指定联机重做日志文件位置,如果没有使用logfile语句,则通过以下参数指定:
    • db_create_online_log_dest_n:如果指定了一个或者多个,则仅使用该位置
    • db_create_file_dest:创建文件的首选位置
    • db_recovery_file_dest:快速恢复区位置

临时类型:

  • 归档日志文件:如果配置了快速恢复区,则log_archive_dest_1自动设置为快速恢复区。
  • 闪回日志:启动闪回数据库产生的闪回日志
  • 控制文件自动备份:rman自动备份控制文件时,默认位置为快速恢复区
  • 数据文件拷贝:使用backup as copy命令创建数据文件镜像拷贝到快速恢复区
  • rman文件:使用rman进行备份的默认位置

当写入到快速恢复区的文件请求空间时,会删除在过期列表中的文件,并将信息写入的告警日志。当快速恢复区使用到85%,则会发出告警,使用到97%,则会发出严重告警,这是系统内部设置,不能更改。告警示例如下:

WARNING: db_recovery_file_dest_size of 52428800 bytes is 100.00% used, and has 0 remaining bytes available.

可以通过dba_outstanding_alerts数据字典查询告警信息以及建议:

SQL> select object_type,message_type,message_level,reason,suggested_action
  2  from dba_outstanding_alerts;

OBJECT_TYPE     MESSAGE_TYPE MESSAGE_LEVEL REASON                                      SUGGESTED_ACTION
--------------- ------------ ------------- ------------------------------------------- ---------------------------
TABLESPACE      Warning                  5 Tablespace [INVENTORY] is [90 percent] full Add space to the tablespace
TABLESPACE      Warning                  1 Tablespace [TBS_03] is [100 percent] full   Add space to the tablespace

如果快速恢复区满了,可以选择增加磁盘空间,备份文件到另外的地方,使用rman删除快速恢复区的文件或者修改rman的保留策略。

为避免快速恢复区空间不足,可以使用如下建议:

  • 使用rman删除不必要的文件
  • 使用rman备份快速恢复区
  • 修改rman保留策略到最小值
  • 修改rman归档日志删除策略
  • 增加磁盘空间,增大db_recovery_file_dest_size

不要把不受rman管理的文件放到快速恢复区。如果不是使用rman删除快速恢复区的文件(例如使用操作系统的rm命令),则需要再使用rman删除对应的记录(crosscheck和delete)回收空间。例如备份了归档日志文件后,要删除这些已经成功备份了的归档日志文件,可以使用以下rman命令:

BACKUP ARCHIVELOG ALL DELETE ALL INPUT;

配置归档日志删除策略

使用CONFIGURE ARCHIVELOG DELETE POLICY命令对所有归档位置配置删除策略。

归档日志可以被数据库自动删除也可以通过发出rman命令进行删除:

  • 只有在快速恢复区的归档日志才可以被数据库自动删除
  • 使用BACKUP ... DELETE INPUT或者DELETE ARCHIVELOG手动删除任何位置的归档日志
  • 默认是CONFIGURE ARCHIVELOG DELETION POLICY TO NONE

例子:通过V$FLASH_RECOVERY_AREA_USAGE视图查看快速恢复区使用情况

SQL> SELECT * FROM V$FLASH_RECOVERY_AREA_USAGE;

FILE_TYPE            PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
-------------------- ------------------ ------------------------- ---------------
CONTROL FILE                        .25                         0               1
REDO LOG                           3.79                         0               3
ARCHIVED LOG                      10.84                      5.67              12
BACKUP PIECE                      34.13                     23.69              10
IMAGE COPY                            0                         0               0
FLASHBACK LOG                         0                         0               0
FOREIGN ARCHIVED LOG                  0                         0               0

7 rows selected.

介质恢复

介质恢复(media recovery)分为数据文件介质恢复和块介质恢复。数据文件介质恢复是对还原的数据文件应用重做日志或增量备份,以将其更新到当前时间或其他指定时间。

Recovery Catalog

RMAN备份信息默认存储在数据库的控制文件中,也可以存储到一个称之为恢复目录的单独数据库中。

恢复目录在一个单独的数据库中保存备份信息,相比控制文件,可以保存更长的时间,可以存储多个数据库的备份信息,RMAN脚本等。

如果只是几个数据库简单的备份管理,Oracle建议使用控制文件进行管理,如果有很多数据库且需要保存备份较长时间,就可以使用恢复目录。

使用恢复目录的理由:

  • 如果使用控制文件作为唯一的rman备份信息仓库,受控制文件大小限制,存储的备份信息有限,则备份的保留的时间也就有限制,如果使用恢复目录,则可以存储更多的备份信息,备份的保留时间也更长。
  • 如果要使用rman存储的脚本,则必须使用恢复目录。
  • 由于恢复目录集中管理了所有数据库的备份信息,可以通过连接到恢复目录查询各种RC_视图创建定制化的备份报表信息。
  • 在指定的保留策略外,可以使用BACKUP ... KEEP命令创建备份并指定备份保留多久。如果使用了恢复目录,还可以使用KEEP FOREVER语句指定备份或者拷贝永远不过期。
  • 使用REPORT SCHEMA命令列出目标数据库的表空间和数据文件,如果使用了恢复目录,还可以加上AT [time/scn/logseq]选项查看过去某个时间的信息。

创建恢复目录的三步:

  1. 配置存储恢复目录的数据库

  2. 创建恢复目录所有者

  3. 创建恢复目录

配置恢复目录数据库

在安装恢复目录模式的数据库上为恢复目录模式分配空间,考虑如下需求:

  • 支持的数据库数量
  • 归档日志和备份的记录数量
  • 是否存储rman脚本

为恢复目录创建默认表空间:

SQL> create tablespace rcat_ts datafile size 15M;

Tablespace created.

创建恢复目录所有者

创建用户,指定默认表空间,不限制使用表空间,赋予RECOVERY_CATALOG_OWNER角色。

SQL> create user rcowner identified by rcowner
  2  temporary tablespace temp
  3  default tablespace rcat_ts
  4  quota unlimited on rcat_ts;

User created.

SQL> grant recovery_catalog_owner to rcowner;

Grant succeeded.

创建恢复目录

使用rman的CREATE CATALOG命令创建恢复目录。

[oracle@test ~]$ rman catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 7 08:37:08 2016

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

connected to recovery catalog database

RMAN> create catalog;

recovery catalog created

注册数据库

创建恢复目录后,需要在恢复目录中注册数据库,注册数据库会执行如下操作:

  • 在恢复目录表中为目标数据库创建记录
  • 复制目标数据库控制文件数据到恢复目录表
  • 使用控制文件同步恢复目录

在恢复目录中注册数据库步骤如下:

  1. 使用rman同时连接到目标数据库和恢复目录
% rman TARGET / CATALOG rman/rman@reccatdb
  1. 确保目标数据库是mount或者open状态

  2. 在rman中使用REGISTER DATABASE命令

[oracle@test ~]$ rman target sys/123456@192.168.230.139:1521/stone catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 7 08:49:01 2016

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

connected to target database: STONE (DBID=3003597140)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

取消注册数据库

从恢复目录中取消注册数据库,则该数据库的所有rman记录都会被删掉。一般情况下,只有在被备份的数据库不再使用了或者不存在了才会去取消注册。

[oracle@test ~]$ rman target / catalog rcowner/rcowner@192.168.230.138:1521/stone

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 7 20:01:23 2016

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

connected to target database: STONE (DBID=3003597140)
connected to recovery catalog database

RMAN> unregister database;

database name is "STONE" and DBID is 3003597140

Do you really want to unregister the database (enter YES or NO)? yes
database unregistered from the recovery catalog

增加额外的备份文件

不管有没有使用恢复目录,都可以使用CATALOG命令将额外的控制文件拷贝、数据文件拷贝、备份集以及归档日志文件信息加入到恢复目录或者控制文件,即使这些备份已经过期,也可以加入进来用于还原操作。

增加备份文件、数据文件、归档文件及备份片的例子如下:

RMAN> CATALOG CONTROLFILECOPY '/disk1/controlfile_bkup/2009_01_01/control01.ctl';
RMAN> CATALOG DATAFILECOPY '/disk1/datafile_bkup/2009_01_01/users01.dbf';
RMAN> CATALOG ARCHIVELOG '/disk1/arch_logs/archive1_731.log',
'/disk1/arch_logs/archive1_732.log';
RMAN> CATALOG BACKUPPIECE '/disk1/backups/backup_820.bkp';

还可以catalog当前快速恢复区的所有文件:

RMAN> CATALOG RECOVERY AREA NOPROMPT;

可以使用start with选项指定搜索的目录或者目录前缀,但是不能使用通配符。

指定搜索目录的例子:

RMAN> CATALOG START WITH '/tmp/arch_logs/';

指定搜索目录前缀的例子:

RMAN> CATALOG START WITH '/tmp/bset';

恢复目录重同步

当rman执行重同步的时候,将目标数据库的控制文件与恢复目录进行比较,将控制文件中增加或者更新的信息同步到恢复目录。

重同步分2种:

  • 部分(Partial):将控制文件中的备份、归档日志及数据文件拷贝等数据与恢复目录进行比较并同步
  • 全部(Full):先创建一个控制文件快照,使用快照进行比较和同步,同时还包括数据库结构的改变,例如模式的改变或者新的表空间

如果由参数CONTROL_FILE_RECORD_KEEP_TIME管理控制文件改变的记录,则进行部分同步,否则进行全部同步,如果使用RESYNC CATALOG命令,也会执行全部同步。

在以下情况需要手工同步恢复目录:

  • 当使用rman命令导致自动重同步时恢复目录不可用的情况
  • 由于恢复目录不会在联机重做日志文件切换或者归档时自动更新,所以如果数据库备份不频繁的话,需要手工同步恢复目录
  • 在对目标数据库物理结构进行修改后

同步的记录包括:

  • 日志历史记录,联机重做日志切换产生的记录
  • 归档日志记录
  • 备份记录,包括备份集、备份片,镜像拷贝等
  • 模式记录,对应数据文件和表空间,如果目标数据库是open状态,还包括回滚段
[oracle@test ~]$ rman target / catalog rcowner/rcowner@192.168.230.138:1521/stone

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 7 22:27:51 2016

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

connected to target database: STONE (DBID=3003597140)
connected to recovery catalog database

RMAN> resync catalog;

starting full resync of recovery catalog
full resync complete

使用RMAN存储脚本

可以使用rman存储脚本,有2种类型:

  • Local:只能由创建该脚本的目标数据库执行
  • Global:任何注册到恢复目录的数据库都可以执行
[oracle@test ~]$ rman target / catalog rcowner/[rcowner@192.168.230.138](mailto:rcowner@192.168.230.138):1521/stone

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 7 22:47:01 2016

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

connected to target database: STONE (DBID=3003597140)

connected to recovery catalog database

RMAN> create script backuptbs_03

2> {backup datafile 15;}

created script backuptbs_03

执行RMAN存储的脚本

连接到目标数据库和恢复目录,在run块内使用EXECUTE SCRIPT命令执行脚本。

[oracle@test ~]$ rman target / catalog rcowner/rcowner@192.168.230.138:1521/stone

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 7 22:57:09 2016

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

connected to target database: STONE (DBID=3003597140)
connected to recovery catalog database

RMAN> run{execute script backuptbs_03;}

executing script: backuptbs_03

Starting backup at 07-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=60 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=+DATA/stone/datafile/tbs_03.277.900065973
channel ORA_DISK_1: starting piece 1 at 07-JAN-16
channel ORA_DISK_1: finished piece 1 at 07-JAN-16
piece handle=+FRA/stone/backupset/2016_01_07/nnndf0_tag20160107t225746_0.347.900543467 tag=TAG20160107T225746 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-JAN-16

Starting Control File and SPFILE Autobackup at 07-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_07/s_900543469.334.900543471 comment=NONE
Finished Control File and SPFILE Autobackup at 07-JAN-16

维护RMAN存储的脚本

打印脚本内容:
RMAN> print script backuptbs_03;

printing stored script: backuptbs_03
{backup datafile 15;}

将脚本内容保存到文件
RMAN> print script backuptbs_03 to file 'backuptbs_03';

script backuptbs_03 written to file backuptbs_03

查看当前目标数据库可以执行的脚本
RMAN> list script names;

List of Stored Scripts in Recovery Catalog


    Scripts of Target Database STONE

       Script Name
       Description
       -----------------------------------------------------------------------
       backuptbs_03

修改脚本
RMAN> replace script backuptbs_03
2> {backup datafile 14;}

replaced script backuptbs_03

RMAN> print script backuptbs_03;

printing stored script: backuptbs_03
{backup datafile 14;}

删除脚本
RMAN> delete script backuptbs_03;

deleted script: backuptbs_03

RMAN> list script names;

List of Stored Scripts in Recovery Catalog

        No scripts in recovery catalog

备份恢复目录

Oracle建议使用rman对恢复目录进行备份,备份信息存放在恢复目录所在数据库的控制文件中。不要在目标数据库上面创建恢复目录。

建议配置恢复目录所在数据库的控制文件自动备份,在对目标数据库进行备份之后,立即对恢复目录进行备份。

为恢复目录配置备份和恢复环境包括:

  • 使恢复目录所在数据库运行在归档模式

  • 设置redundancy保留策略大于1

  • 备份恢复目录到磁盘或者磁带

  • 使用BACKUP DATABASE PLUS ARCHIVELOG进行备份

  • 使用控制文件而不是其他恢复目录作为备份信息存储库

  • 打开控制文件自动备份

重建不可恢复的恢复目录

如果恢复目录数据库丢失或者损坏,无法进行恢复,则需要重建。

使用以下命令部分重建恢复目录:

  • RESYNC CATALOG:使用目标数据库控制文件的rman信息更新恢复目录

  • CATALOG START WITH ...重新注册可用的备份

导出和导入恢复目录

可以使用导出导入工具移动恢复目录到其他数据库,也可以创建一个逻辑备份。

导出导入步骤如下:

  • 使用导出工具导出恢复目录
  • 在要导入的数据库创建恢复目录用户并赋予权限
  • 使用对应的导入工具导入恢复目录到刚刚创建的模式中

在导入之前或者之后都不需要执行CREATE CATALOG命令,由导入操作创建目录。

例子:导出导入恢复目录

[oracle@rcdb ~]$ exp rcowner/rcowner file=/home/oracle/rc.dmp owner=rcowner

Export: Release 11.2.0.4.0 - Production on Fri Jun 17 14:56:39 2016

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


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and AL16UTF16 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user RCOWNER 
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user RCOWNER 
About to export RCOWNER's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export RCOWNER's tables via Conventional Path ...
. . exporting table                             AL         85 rows exported
. . exporting table                            BCB          0 rows exported
. . exporting table                            BCF          0 rows exported
. . exporting table                            BCR          0 rows exported
. . exporting table                            BDF          0 rows exported
. . exporting table                             BP          0 rows exported
. . exporting table                            BRL          0 rows exported
. . exporting table                             BS          0 rows exported
. . exporting table                            BSF          0 rows exported
. . exporting table                            CCB          0 rows exported
. . exporting table                            CCF          0 rows exported
. . exporting table                            CDF          0 rows exported
. . exporting table                            CFS        157 rows exported
. . exporting table                            CKP          2 rows exported
. . exporting table                           CONF          0 rows exported
. . exporting table                         CONFIG          1 rows exported
. . exporting table                             DB          1 rows exported
. . exporting table                          DBINC          2 rows exported
. . exporting table                             DF          6 rows exported
. . exporting table                             FB          0 rows exported
. . exporting table                           GRSP          0 rows exported
. . exporting table                           NODE          1 rows exported
. . exporting table                           NRSP          0 rows exported
. . exporting table                           OFFR          5 rows exported
. . exporting table                            ORL          8 rows exported
. . exporting table                          RCVER          1 rows exported
. . exporting table                            RLH         85 rows exported
. . exporting table                           ROUT         21 rows exported
. . exporting table                             RR          0 rows exported
. . exporting table                            RSR          8 rows exported
. . exporting table                             RT          2 rows exported
. . exporting table                            SCR          0 rows exported
. . exporting table                           SCRL          0 rows exported
. . exporting table                     SITE_DFATT          6 rows exported
. . exporting table                     SITE_TFATT          1 rows exported
. . exporting table                        TEMPRES          0 rows exported
. . exporting table                             TF          1 rows exported
. . exporting table                             TS          7 rows exported
. . exporting table                          TSATT          7 rows exported
. . exporting table                  VPC_DATABASES          0 rows exported
. . exporting table                      VPC_USERS          0 rows exported
. . exporting table                            XAL          0 rows exported
. . exporting table                            XCF          0 rows exported
. . exporting table                            XDF          0 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.

[oracle@rcdb ~]$ scp rc.dmp oracle@192.168.254.131:/home/oracle
The authenticity of host '192.168.254.131 (192.168.254.131)' can't be established.
RSA key fingerprint is 63:31:3c:7c:e2:39:d9:4e:75:f8:8d:cc:d0:ae:a9:a2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.254.131' (RSA) to the list of known hosts.
oracle@192.168.254.131's password: 
rc.dmp                                                                                                                                   100% 2096KB   2.1MB/s   00:00 

[oracle@test ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Jun 17 14:58:59 2016

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> create tablespace rcat_ts datafile size 15M;

Tablespace created.

SQL> create user rcowner identified by rcowner
  2  temporary tablespace temp
  3  default tablespace rcat_ts
  4  quota unlimited on rcat_ts;

User created.

SQL> grant recovery_catalog_owner to rcowner;

Grant succeeded.

[oracle@test ~]$ imp rcowner/rcowner file=/home/oracle/rc.dmp fromuser=rcowner touser=rcowner

升级和删除恢复目录

如果使用的恢复目录版本小于rman需要的版本,则必须通过执行UPGRADE CATALOG命令进行升级。包括:

  • 安装新的恢复目录模式,恢复目录用户需要有CREATE TYPE权限
  • 需要连接到恢复目录且恢复目录数据库必须open,不需要连接到目标数据库
  • 需要输入2次UPGRADE CATALOG命令进行确认
  • 会显示所有错误消息
[oracle@test ~]$ rman catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 8 08:37:50 2016

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

connected to recovery catalog database

RMAN> upgrade catalog;

recovery catalog owner is RCOWNER
enter UPGRADE CATALOG command again to confirm catalog upgrade

RMAN> upgrade catalog;

recovery catalog upgraded to version 11.02.00.04
DBMS_RCVMAN package upgraded to version 11.02.00.04
DBMS_RCVCAT package upgraded to version 11.02.00.04

使用DROP CATALOG命令删除恢复目录模式,会删除注册到恢复目录的数据库的备份记录。

  • 只能在rman执行
  • 需要连接到恢复目录且恢复目录数据库必须open,不需要连接到目标数据库
  • 需要输入2次DROP CATALOG命令进行确认
[oracle@test ~]$ rman catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jun 17 15:18:49 2016

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

connected to recovery catalog database

RMAN> drop catalog;

recovery catalog owner is RCOWNER
enter DROP CATALOG command again to confirm catalog removal

RMAN> drop catalog;

recovery catalog dropped

IMPORT CATALOG命令

使用IMPORT CATALOG命令从一个恢复目录模式导入元数据到另一个恢复目录模式,用于使用单个恢复目录模式统一管理多个目标数据库不同版本的恢复目录模式。语法如下:

IMPORT CATALOG <connectStringSpec>
[DBID = <dbid> [, <dbid>,]]
[DB_NAME=<dbname>[, <dbname,]]
[ NO UNREGISTER ];

其中:

<connectStringSpec>:源恢复目录连接字符串,源恢复目录模式版本必须等于rman的版本,如果不满足则需要进行upgrade。

DBID:指定需要从源目录模式导入的数据库ID,如果不指定,则导入所有数据库ID,如果已经存在则报错。

DB_NAME:指定需要从源目录模式导入的数据库名字。

NO UNREGISTER:默认情况下,成功导入到目的目录模式后,被导入的数据库ID从源恢复目录模式中取消注册,可以使用NO UNREGISTER选项使源目录模式保留这些数据库ID。

注意事项:

  • 确保目标数据库不会同时注册到源目录模式和目的目录模式,如果在源目录模式和目的目录模式都注册了目标数据库,则需要从源目录模式取消注册并重新import。
  • improt操作要么都导入,要么失败回滚,不存在部分导入。
  • 当源目录模式和目的目录模式有系统名字的脚本,rman会对源目录模式的脚本进行重命名。
[oracle@test ~]$ sqlpus / as sysdba

SQL> drop user rcowner cascade;

User dropped.

SQL> create user rcowner1 identified by rcowner1
  2  temporary tablespace temp
  3  default tablespace rcat_ts
  4  quota unlimited on rcat_ts;

User created.

SQL> grant recovery_catalog_owner to rcowner1;

Grant succeeded.

SQL> quit

[oracle@test ~]$ rman catalog rcowner1/rcowner1

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jun 17 15:34:07 2016

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

connected to recovery catalog database

RMAN> create catalog;

recovery catalog created

RMAN> quit

Recovery Manager complete.

[oracle@test ~]$ rman target / catalog rcowner/rcowner@192.168.254.141:1521/rcdb

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jun 17 15:38:52 2016

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

connected to target database: STONE (DBID=3020335403)
connected to recovery catalog database

RMAN> unregister database;

database name is "STONE" and DBID is 3020335403

Do you really want to unregister the database (enter YES or NO)? yes
database unregistered from the recovery catalog

[oracle@test ~]$ rman target / catalog rcowner1/rcowner1

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jun 17 15:34:59 2016

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

connected to target database: STONE (DBID=3020335403)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

[oracle@rcdb ~]$ rman catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jun 17 15:39:18 2016

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

connected to recovery catalog database

RMAN> import catalog rcowner1/rcowner1@192.168.254.131:1521/stone;

Starting import catalog at 17-JUN-16
connected to source recovery catalog database
import validation complete
database unregistered from the source recovery catalog
Finished import catalog at 17-JUN-16

创建和使用虚拟私有目录

虚拟私有目录用于访问人员的职责分离,可以限制人员只能看到某些目标数据库的备份记录以及进行指定的操作,提高安全性。

可以访问所有注册数据库信息的目录所有者,在SQL*Plus使用如下语句列出注册的数据库:

SQL> select distinct db_name from dbinc;

DB_NAME
--------
STONE

如果是虚拟私有目录的所有者,使用上面的语句只能看到被授权的数据库信息。

创建虚拟私有目录步骤:

1)使用SQL*Plus和RMAN创建基本恢复目录
SQL> create user rcowner1 identified by rcowner1 default tablespace rcat_ts quota unlimited on rcat_ts;

User created.

SQL> grant recovery_catalog_owner to rcowner1;

Grant succeeded.

RMAN> connect catalog rcowner1/rcowner1;

connected to recovery catalog database

RMAN> create catalog;

recovery catalog created

(2)在SQL*Plus中,基本恢复目录数据库DBA创建虚拟私有目录用户并授权
SQL> conn / as sysdba
Connected.

SQL> create user vpcowner identified by vpcowner;

User created.

SQL> grant recovery_catalog_owner to vpcowner;

Grant succeeded.3)在RMAN中,基本恢复目录所有者给虚拟私有目录用户授予注册数据库的访问权限或者REGISTER权限
RMAN> connect catalog rcowner1/rcowner1;

connected to recovery catalog database

RMAN> grant register database to vpcowner;

Grant succeeded.4a)连接到虚拟私有目录用户,为11g创建虚拟目录
RMAN> connect catalog vpcowner/vpcowner

connected to recovery catalog database

RMAN> create virtual catalog;

found ineligible base catalog owned by RCOWNER
found eligible base catalog owned by RCOWNER1
created virtual catalog against base catalog owned by RCOWNER1

(4b)如果是11g之前的数据库,则需要在SQL*Plus执行以下命令创建虚拟目录
SQL> CONNECT vpcowner/oracle@catdb
SQL> exec catowner.dbms_rcvcat.create_virtual_catalog;5)在rman中使用虚拟私有目录用户注册数据库
[oracle@test ~]$ rman target / catalog vpcowner/vpcowner@192.168.230.138:1521/stone

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 8 12:02:32 2016

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

connected to target database: STONE (DBID=3003597140)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

(6)使用虚拟私有目录
[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 8 12:05:02 2016

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

connected to target database: STONE (DBID=3003597140)

RMAN> connect catalog vpcowner/vpcowner@192.168.230.138:1521/stone

connected to recovery catalog database

RMAN> backup datafile 15;

Starting backup at 08-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=53 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=+DATA/stone/datafile/tbs_03.277.900065973
channel ORA_DISK_1: starting piece 1 at 08-JAN-16
channel ORA_DISK_1: finished piece 1 at 08-JAN-16
piece handle=+FRA/stone/backupset/2016_01_08/nnndf0_tag20160108t120542_0.335.900590743 tag=TAG20160108T120542 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-JAN-16

Starting Control File and SPFILE Autobackup at 08-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_08/s_900590744.348.900590745 comment=NONE
Finished Control File and SPFILE Autobackup at 08-JAN-16

注意:在创建与使用虚拟私有恢复目录时,基本恢复目录中不能注册目标数据库,否则会出现RMAN-06004, ORA-00942错误信息。

Backup Settings

可以在RMAN中使用CONFIGURE命令对数据库的备份配置进行设置,包括:

  • 通道
  • 备份保留策略
  • 创建备份拷贝的数量
  • 默认备份类型,是备份集还是镜像拷贝
  • 备份片大小
  • 不需要备份的表空间
  • 启用和禁用备份优化
  • 定义归档删除策略
  • 为设备指定并行度
  • 指定加密和压缩参数

可以在会话中使用SET命令对以上选项进行修改,仅在当前会话有效。

查看配置的2种方法:

RMAN> show all;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; ## default
CONFIGURE BACKUP OPTIMIZATION OFF; ## default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; ## default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; ## default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; ## default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; ## default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; ## default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; ## default
CONFIGURE MAXSETSIZE TO UNLIMITED; ## default
CONFIGURE ENCRYPTION FOR DATABASE OFF; ## default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; ## default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; ## default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; ## default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_stone.f'; ## default

SQL> select * from v$rman_configuration;

     CONF## NAME                           VALUE
---------- ------------------------------ ------------------------------
         1 CONTROLFILE AUTOBACKUP         ON
         2 DEFAULT DEVICE TYPE TO         DISK
         3 BACKUP OPTIMIZATION            ON

配置控制文件自动备份

Oracle推荐启用控制文件自动备份。默认是禁用的,使用RMAN进行启用,启用后会在以下情况自动备份控制文件和启动数据库的服务器参数文件:

  • 运行脚本结束时
  • 成功的备份被记录到RMAN存储库
  • 数据库结构改变(例如修改控制文件内容的DDL操作)

对于所有的设备类型,控制文件备份的名称使用默认的%F格式,可以直接指定控制文件位置进行恢复。%F格式显示为c-IIIIIIIIII-YYYYMMDD-QQ,其中:

  • IIIIIIIIII表示DBID
  • YYYYMMDD表示生成备份的时间戳
  • QQ表示以 00 开头且最大为 FF 的十六进制序列

可以使用CONFIGURE CONTROLFILE AUTOBACK FORMAT FOR DEVICE TYPE type TO 'string'修改默认格式。其中string必须包含%F,且不能包含其他格式变量。例如:

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT
FOR DEVICE TYPE DISK TO '/u01/oradata/cf_ORCL_auto_%F';

如果不指定位置,控制文件自动备份到快速恢复区。

由于控制文件备份使用了固定格式的名称,即使当前控制文件,恢复目录以及服务器参数文件不可访问,RMAN也可以从自动备份中搜索和还原服务器参数文件和控制文件。

例子:配置控制文件自动备份

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

配置并行度

可以配置设备的并行度,并行度是读取或者写入设备的数据流的数量。例如有2个磁带驱动器,就可以配置并行度为2,这样2个磁带驱动器就可以同时进行备份。语法:

CONFIGURE DEVICE TYPE <device> PARALLELISM  <n>

例子:配置到磁带的并行度为2

RMAN> configure device type sbt parallelism 2;

new RMAN configuration parameters:
CONFIGURE DEVICE TYPE 'SBT_TAPE' PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored

使用show命令查看配置,show all查看所有配置。
RMAN> show controlfile autobackup format;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; ## default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; ## defaul


RMAN> show device type;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE DEVICE TYPE 'SBT_TAPE' PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; ## default

RMAN> show exclude;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name STONE are:
RMAN configuration has no stored or default parameters

使用clear选项将配置还原到默认值。
RMAN> configure default device type clear;

RMAN configuration parameters are successfully reset to default value


RMAN> show default device type;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE DEFAULT DEVICE TYPE TO DISK; ## default

配置备份位置

数据可以备份到磁盘目录或者FRA。指定一个磁盘目录或FRA表示备份到硬盘媒体。通常情况下,备份通过介质管理接口定期移动到磁带上以保持磁盘空间的可用性。可以指定任何已经存在的磁盘目录作为备份的目的地。

如果设置了快速恢复区域,可以简化备份和恢复任务。数据库自动命名文件,在空间压力不足时删除已过时的文件。

备份到磁盘,使用命令CONFIGURE DEFAULT DEVICE TYPE TO DISK。如果使用FORMAT关键字(指定备份的磁盘目录位置),则将该备份写入指定目录。如果配置了FRA,则写入到FRA;否则,将被写入到特定平台的默认位置。

RMAN> configure default device type to disk;

old RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO 'TAPE';
new RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
new RMAN configuration parameters are successfully stored

配置和分配通道

配置通道的方法有:

  • 使用CONFIGURE命令配置自动通道,在RMAN提示符或者RUN块中使用BACKUP命令
  • 在RUN块中使用ALLOCATE CHANNEL命令手动分配通道并执行BACKUP命令
RMAN> configure channel device type disk format '/home/oracle/backup_%U';

new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/home/oracle/backup_%U';
new RMAN configuration parameters are successfully stored

RMAN> configure channel 1 device type disk format '/home/oracle/backup_%U';

new RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT   '/home/oracle/backup_%U';
new RMAN configuration parameters are successfully stored

RMAN> configure channel 2 device type disk format '/home/oracle/backup_%U';

new RMAN configuration parameters:
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT   '/home/oracle/backup_%U';
new RMAN configuration parameters are successfully stored

RMAN> show channel for device type disk;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/home/oracle/backup_%U';
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT   '/home/oracle/backup_%U';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT   '/home/oracle/backup_%U';

RMAN> configure channel device type disk clear;

old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/home/oracle/backup_%U';
old RMAN configuration parameters are successfully deleted

RMAN> run{
2> allocate channel ch1 device type disk;
3> backup datafile 15;}

allocated channel: ch1
channel ch1: SID=23 device type=DISK

Starting backup at 10-JAN-16
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00015 name=+DATA/stone/datafile/tbs_03.277.900065973
channel ch1: starting piece 1 at 10-JAN-16
channel ch1: finished piece 1 at 10-JAN-16
piece handle=+FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t104758_0.354.900758879 tag=TAG20160110T104758 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_10/s_900758879.346.900758881 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16
released channel: ch1

配置冗余备份集

rman可以同时生成最多4份备份集,冗余备份集通常用于磁带备份,不能对FRA进行冗余备份集,也不能用于镜像拷贝。

冗余备份最简单的方式是使用BACKUP ... COPIES或者CONFIGURE ... BACKUP COPIES。对于DISK通道,通过FORMAT指定不同的备份位置,对于SBT通道,如果使用支持第二版的SBT API介质管理器,则自动备份到不同的介质去。

RMAN> backup copies 4 datafile 4 format '/home/oracle/backup_%U';

Starting backup at 10-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-16
channel ORA_DISK_1: finished piece 1 at 10-JAN-16 with 4 copies and tag TAG20160110T110452
piece handle=/home/oracle/backup_0bqr10ak_1_1 comment=NONE
piece handle=/home/oracle/backup_0bqr10ak_1_2 comment=NONE
piece handle=/home/oracle/backup_0bqr10ak_1_3 comment=NONE
piece handle=/home/oracle/backup_0bqr10ak_1_4 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:17
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_10/o1_mf_s_900759911_c93lm887_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16

RMAN> run{
2> set backup copies 2;
3> backup datafile 4 format '/home/oracle/backup1/%U','/home/oracle/backup2/%U';}

executing command: SET BACKUP COPIES

Starting backup at 10-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-16
channel ORA_DISK_1: finished piece 1 at 10-JAN-16 with 2 copies and tag TAG20160110T112004
piece handle=/home/oracle/backup1/0fqr1174_1_1 comment=NONE
piece handle=/home/oracle/backup2/0fqr1174_1_2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_10/o1_mf_s_900760805_c93mh625_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16

使用CONFIGURE ... BACKUP COPIES命令设置特定设备类型的备份集数量,对控制文件自动备份以及使用BACKUP BACKUPSET命令无效。同时需要配置自动通道。

RMAN> configure datafile backup copies for device type disk to 2;

new RMAN configuration parameters:
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
new RMAN configuration parameters are successfully stored

RMAN> backup datafile 4 format '/home/oracle/backup_%U';

Starting backup at 10-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=45 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-16
channel ORA_DISK_1: finished piece 1 at 10-JAN-16 with 2 copies and tag TAG20160110T111536
piece handle=/home/oracle/backup_0dqr10uo_1_1 comment=NONE
piece handle=/home/oracle/backup_0dqr10uo_1_2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_10/o1_mf_s_900760537_c93m6sdb_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16

使用BACKUP ... AS COPY命令不受COPIES配置的影响,只会创建一个拷贝。
RMAN> backup as copy datafile 4;

Starting backup at 10-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c93n45kn_.dbf tag=TAG20160110T113117 RECID=2 STAMP=900761477
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_10/o1_mf_s_900761478_c93n46py_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16

配置备份优化

如果配置了备份优化,则使用BACKUP DATABASE命令、BACKUP ARCHIVELOG命令带有ALL或LIKE选项以及BACKUP BACKUPSET ALL命令,且只分配了一种通道类型,则会跳过已经备份了的文件。一般用于跳过只读表空间或者Offline表空间以及已经备份过的归档文件。

同时会根据保留策略和冗余策略进行评估。备份优化默认是禁用的,通过CONFIGURE BACKUP OPTIMIZATION ON命令启用。对于BACKUP RECOVERY AREA|DB_RECOVERY_FILE_DEST以及BACKUP RECOVERY FILES命令自动启用备份优化。

通过在BACKUP命令中指定FORCE选项覆盖备份优化设置,备份所有文件。命令如下:

BACKUP DEVICE TYPE DISK BACKUPSET ALL FORCE;

注意FORCE选项不适用于恢复区中的文件 。

可以通过以下命令禁用备份优化:

CONFIGURE BACKUP OPTIMIZATION OFF;
RMAN> show backup optimization;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE BACKUP OPTIMIZATION OFF; ## default

RMAN> configure backup optimization on;

new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored

RMAN> show backup optimization;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE BACKUP OPTIMIZATION ON;

RMAN> configure backup optimization off;

old RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION OFF;
new RMAN configuration parameters are successfully stored

RMAN> show backup optimization;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE BACKUP OPTIMIZATION OFF;

配置压缩备份

压缩备份可以减少写入到备份中的块,节约空间,有4种压缩算法:HIGH,MEDIUM,LOW和BASIC。可以通过CONFIGURE COMPRESSION ALGORITHM进行配置也可以在RUN块中使用SET COMPRESSION ALGORITHM进行配置。

对压缩的备份进行还原不需要手工进行额外的操作,系统会自动进行解压。压缩和解压缩会消耗CPU资源。

Compression Ratio or LevelConsiderationsRequires Advanced Compression Option
LOWFastest. Best suited to address backup: CPU resources
MEDIUMFast. Good balance of CPU usage and compression ratio
HIGHBest compression ratio at the expense of high CPU consumption. Best suited to address backup constraint: network.
BASICFair. Compression ratio similar to MEDIUM at expense of additional CPU usage. Compression ratio between MEDIUM and HIGH

根据数据类型,网络环境,系统资源等,使用不同的压缩算法进行测试,选择最适合当前系统环境的压缩算法。

配置加密备份

有三种备份加密的方式:

  • 透明加密(Transparent encryption):默认方式,使用钱夹(wallet),适用于本地恢复
  • 密码加密(Password encryption):通过密码进行加密,不需要配置钱夹(wallet)
  • 双重加密(Dual mode encryption):使用透明加密和密码加密,本地恢复使用透明模式,异机恢复使用密码模式。

例子:密码加密

RMAN> set encryption on identified by 'oracle' only;

executing command: SET encryption

RMAN> backup datafile 15;

Starting backup at 10-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=+DATA/stone/datafile/tbs_03.277.900065973
channel ORA_DISK_1: starting piece 1 at 10-JAN-16
channel ORA_DISK_1: finished piece 1 at 10-JAN-16
piece handle=+FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t210116_0.350.900795677 tag=TAG20160110T210116 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_10/s_900795678.333.900795679 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

ASMCMD> rm +DATA/stone/datafile/tbs_03.277.900065973


RMAN> restore datafile 15;

Starting restore at 10-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=22 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00015 to +DATA/stone/datafile/tbs_03.277.900065973
channel ORA_DISK_1: reading from backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t210116_0.350.900795677
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/10/2016 21:05:21
ORA-19870: error while restoring backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t210116_0.350.900795677
ORA-19913: unable to decrypt backup
ORA-28365: wallet is not open

RMAN> set decryption identified by 'oracle';

executing command: SET decryption

RMAN> restore datafile 15;

Starting restore at 10-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00015 to +DATA/stone/datafile/tbs_03.277.900065973
channel ORA_DISK_1: reading from backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t210116_0.350.900795677
channel ORA_DISK_1: piece handle=+FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t210116_0.350.900795677 tag=TAG20160110T210116
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 10-JAN-16

RMAN> recover datafile 15;

Starting recover at 10-JAN-16
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 10-JAN-16

RMAN> alter database open;

database opened

例子:透明加密

需要先配置Wallet:
在sqlnet.ora中指定Wallet的地址
[oracle@test ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
[oracle@test admin]$ vim sqlnet.ora
ENCRYPTION_WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=/u01/app/oracle/admin/stone/wallet/)))
[oracle@test admin]$ mkdir /u01/app/oracle/admin/stone/wallet/

SQL> alter system set encryption key identified by oracle;

System altered.

SQL> !ls /u01/app/oracle/admin/stone/wallet/
ewallet.p12

SQL> alter system set encryption wallet close identified by oracle;

System altered.

SQL> alter system set encryption wallet open identified by oracle;

System altered.


RMAN> configure encryption for database on;

new RMAN configuration parameters:
CONFIGURE ENCRYPTION FOR DATABASE ON;
new RMAN configuration parameters are successfully stored

RMAN> set encryption on;

executing command: SET encryption

RMAN> backup datafile 15;

Starting backup at 10-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=+DATA/stone/datafile/tbs_03.277.900795951
channel ORA_DISK_1: starting piece 1 at 10-JAN-16
channel ORA_DISK_1: finished piece 1 at 10-JAN-16
piece handle=+FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t213839_0.359.900797921 tag=TAG20160110T213839 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_10/s_900797922.337.900797923 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16

关闭钱夹进行还原报错。
SQL> alter system set encryption wallet close identified by oracle;

System altered.

RMAN> restore datafile 15;

Starting restore at 10-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00015 to +DATA/stone/datafile/tbs_03.277.900795951
channel ORA_DISK_1: reading from backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t213839_0.359.900797921
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/10/2016 21:39:24
ORA-19870: error while restoring backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t213839_0.359.900797921
ORA-19913: unable to decrypt backup
ORA-28365: wallet is not open

打开钱夹进行还原正常。
SQL> alter system set encryption wallet open identified by oracle;

System altered.

RMAN> restore datafile 15;

Starting restore at 10-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00015 to +DATA/stone/datafile/tbs_03.277.900795951
channel ORA_DISK_1: reading from backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t213839_0.359.900797921
channel ORA_DISK_1: piece handle=+FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t213839_0.359.900797921 tag=TAG20160110T213839
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 10-JAN-16

例子:双重加密

在进行备份时,即启用口令加密,又启动透明加密。在本地模式下,启用透明模式,在异地恢复时启用口令加密。

在设置加密密码时去掉后面的only即可。

RMAN> set encryption on identified by oracle;

executing command: SET encryption

SQL> alter system set encryption wallet open identified by oracle;

System altered.

RMAN> backup datafile 15;

Starting backup at 10-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=+DATA/stone/datafile/tbs_03.277.900795951
channel ORA_DISK_1: starting piece 1 at 10-JAN-16
channel ORA_DISK_1: finished piece 1 at 10-JAN-16
piece handle=+FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t215448_0.331.900798889 tag=TAG20160110T215448 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-16

Starting Control File and SPFILE Autobackup at 10-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_10/s_900798890.330.900798893 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-16


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

ASMCMD> rm DATA/STONE/datafile/TBS_03.277.900795951

SQL> startup
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.

Total System Global Area  889389056 bytes
Fixed Size                  2258360 bytes
Variable Size             662702664 bytes
Database Buffers          218103808 bytes
Redo Buffers                6324224 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 15 - see DBWR trace file
ORA-01110: data file 15: '+DATA/stone/datafile/tbs_03.277.900795951'

直接进行还原报错。
RMAN> restore datafile 15;

Starting restore at 10-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00015 to +DATA/stone/datafile/tbs_03.277.900795951
channel ORA_DISK_1: reading from backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t215448_0.331.900798889
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/10/2016 22:00:51
ORA-19870: error while restoring backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t215448_0.331.900798889
ORA-19913: unable to decrypt backup
ORA-28365: wallet is not open

打开钱夹或通过口令都可以进行还原。
SQL> alter system set encryption wallet open identified by oracle;

System altered.

或者

RMAN> set decryption identified by oracle;

executing command: SET decryption

RMAN> restore datafile 15;

Starting restore at 10-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00015 to +DATA/stone/datafile/tbs_03.277.900795951
channel ORA_DISK_1: reading from backup piece +FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t215448_0.331.900798889
channel ORA_DISK_1: piece handle=+FRA/stone/backupset/2016_01_10/nnndf0_tag20160110t215448_0.331.900798889 tag=TAG20160110T215448
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 10-JAN-16

RMAN> recover datafile 15;

Starting recover at 10-JAN-16
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 10-JAN-16

RMAN> alter database open;

database opened

Creating Backups

创建备份集

RMAN可以使用备份集(Backup Sets)的方式存储备份,备份集是备份片的集合,一个备份片可能包括一个或者多个数据文件。FORMAT参数指定备份片文件名的格式,也可以通过ALLOCATE CHANNEL或者CONFIGURE命令指定。

例子:创建备份集

SQL> select tablespace_name,file_name from dba_data_files where tablespace_name='TBS_03';

TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
TBS_03               +DATA/stone/datafile/tbs_03.277.900799397
TBS_03               +DATA/stone/datafile/tbs_03.280.900834713

RMAN> backup as backupset
2> format '/home/oracle/df_%d_%s_%p.bus'
3> tablespace tbs_03;

Starting backup at 11-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=+DATA/stone/datafile/tbs_03.277.900799397
input datafile file number=00016 name=+DATA/stone/datafile/tbs_03.280.900834713
channel ORA_DISK_1: starting piece 1 at 11-JAN-16
channel ORA_DISK_1: finished piece 1 at 11-JAN-16
piece handle=/home/oracle/df_STONE_155_1.bus tag=TAG20160111T075429 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-JAN-16

Starting Control File and SPFILE Autobackup at 11-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_11/s_900834871.329.900834873 comment=NONE
Finished Control File and SPFILE Autobackup at 11-JAN-16

创建镜像拷贝

镜像拷贝(Image Copies)是对单个数据文件,归档日志文件或者控制文件的复制,使用BACKUP AS COPY命令或者操作系统命令创建。使用BACKUP AS COPY命令创建会去验证是否有坏块并将备份信息写入到控制文件。

镜像拷贝有如下特性:

  • 只能写入到磁盘,如果文件很多,需较长时间,但是还原时间会缩短。
  • 通过SWITCH命令可以立即使用磁盘上面的镜像拷贝,等同于SQL语句ALTER DATABASE RENAME FILE。
  • 镜像拷贝会复制文件中的所有块,不管这些块有没有数据。同时默认会对这些块进行检查,使用NOCHECKSUM选项设置不检查以提高拷贝的速度。
  • 镜像拷贝可以是全部或者0级备份的一部分。

例子:创建镜像拷贝

RMAN> backup as copy datafile 16;

Starting backup at 11-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00016 name=+DATA/stone/datafile/tbs_03.280.900834713
output file name=+FRA/stone/datafile/tbs_03.326.900875863 tag=TAG20160111T191742 RECID=6 STAMP=900875863
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 11-JAN-16

Starting Control File and SPFILE Autobackup at 11-JAN-16
piece handle=+FRA/stone/autobackup/2016_01_11/s_900875863.325.900875865 comment=NONE
Finished Control File and SPFILE Autobackup at 11-JAN-16

创建整库备份

整库备份(Whole Database Backup)是所有数据文件和控制文件的备份集或者镜像拷贝。可以选择包括服务器参数文件和归档日志文件。使用RMAN创建所有数据文件的镜像拷贝只需要加载或者打开数据库,启动RMAN并输入BACKUP DATABASE PLUS ARCHIVELOG命令。可以使用DELETE INPUT选择在备份完成之后删除已经备份的归档日志文件,例如:

RMAN> BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;

使用CONFIGURE进行如下配置:

CONFIGURE DEFAULT DEVICE TYPE TO disk;
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY;
CONFIGURE CONTROLFILE AUTOBACKUP ON;

也可以使用如下命令创建先前所有数据文件和控制文件的镜像拷贝的备份:

RMAN> BACKUP COPY OF DATABASE;

RMAN默认是顺序执行每个BACKUP命令,可以通过如下设置并行拷贝操作:

  • 使用CONFIGURE DEVICE TYPE DISK PARALLELISM n命令,n为并行度
  • 分配多个通道
  • 指定一个BACKUP AS COPY命令并列出多个文件

例子:创建整库备份

RMAN> configure controlfile autobackup on;

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

RMAN> configure device type disk backup type to copy;

new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1

RMAN> configure default device type to disk;

old RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
new RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
new RMAN configuration parameters are successfully stored

RMAN> list backup;

specification does not match any backup in the repository

RMAN> list copy;

specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
specification does not match any archived log in the repository

RMAN> backup database plus archivelog delete input;


Starting backup at 11-JAN-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=118 RECID=118 STAMP=900888563
output file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_11/o1_mf_1_118_c97j7n2l_.arc RECID=119 STAMP=900888564
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_11/o1_mf_1_118_c97j7msn_.arc RECID=118 STAMP=900888563
Finished backup at 11-JAN-16

Starting backup at 11-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c97j7odz_.dbf tag=TAG20160111T224925 RECID=15 STAMP=900888622
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c97j9prw_.dbf tag=TAG20160111T224925 RECID=16 STAMP=900888677
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c97jcg2j_.dbf tag=TAG20160111T224925 RECID=17 STAMP=900888702
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c97jd7j8_.dbf tag=TAG20160111T224925 RECID=18 STAMP=900888718
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c97jdgw2_.dbf tag=TAG20160111T224925 RECID=19 STAMP=900888719
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c97jdj0z_.dbf tag=TAG20160111T224925 RECID=20 STAMP=900888720
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 11-JAN-16

Starting backup at 11-JAN-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=119 RECID=120 STAMP=900888721
output file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_11/o1_mf_1_119_c97jdkow_.arc RECID=121 STAMP=900888721
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_11/o1_mf_1_119_c97jdkbn_.arc RECID=120 STAMP=900888721
Finished backup at 11-JAN-16

Starting Control File and SPFILE Autobackup at 11-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_11/o1_mf_s_900888722_c97jdm55_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 11-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
26      Full    9.45M      DISK        00:00:01     11-JAN-16      
        BP Key: 32   Status: AVAILABLE  Compressed: NO  Tag: TAG20160111T225202
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_11/o1_mf_s_900888722_c97jdm55_.bkp
  SPFILE Included: Modification time: 11-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3598756      Ckp time: 11-JAN-16

RMAN> list copy;

specification does not match any control file copy in the repository
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
16      1    A 11-JAN-16       3598672    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c97j9prw_.dbf
        Tag: TAG20160111T224925

15      2    A 11-JAN-16       3598619    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c97j7odz_.dbf
        Tag: TAG20160111T224925

18      3    A 11-JAN-16       3598736    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c97jd7j8_.dbf
        Tag: TAG20160111T224925

20      4    A 11-JAN-16       3598742    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c97jdj0z_.dbf
        Tag: TAG20160111T224925

17      5    A 11-JAN-16       3598706    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c97jcg2j_.dbf
        Tag: TAG20160111T224925

19      7    A 11-JAN-16       3598740    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c97jdgw2_.dbf
        Tag: TAG20160111T224925

List of Archived Log Copies for database with db_unique_name STONE
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
119     1    118     A 11-JAN-16
        Name: /u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_11/o1_mf_1_118_c97j7n2l_.arc

121     1    119     A 11-JAN-16
        Name: /u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_11/o1_mf_1_119_c97jdkow_.arc


RMAN> backup copy of database;

Starting backup at 11-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input is copy of datafile 00002: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c97j7odz_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c97jkx8v_.dbf tag=TAG20160111T224925 RECID=21 STAMP=900888940
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input is copy of datafile 00001: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c97j9prw_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c97jmno3_.dbf tag=TAG20160111T224925 RECID=22 STAMP=900888992
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:46
channel ORA_DISK_1: starting datafile copy
input is copy of datafile 00005: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c97jcg2j_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c97jo2h8_.dbf tag=TAG20160111T224925 RECID=23 STAMP=900889019
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input is copy of datafile 00003: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c97jd7j8_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c97jow0v_.dbf tag=TAG20160111T224925 RECID=24 STAMP=900889026
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:08
channel ORA_DISK_1: starting datafile copy
input is copy of datafile 00007: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c97jdgw2_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c97jp3nt_.dbf tag=TAG20160111T224925 RECID=25 STAMP=900889028
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input is copy of datafile 00004: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c97jdj0z_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c97jp4rz_.dbf tag=TAG20160111T224925 RECID=26 STAMP=900889029
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 11-JAN-16

Starting Control File and SPFILE Autobackup at 11-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_11/o1_mf_s_900889030_c97jp698_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 11-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
26      Full    9.45M      DISK        00:00:01     11-JAN-16      
        BP Key: 32   Status: AVAILABLE  Compressed: NO  Tag: TAG20160111T225202
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_11/o1_mf_s_900888722_c97jdm55_.bkp
  SPFILE Included: Modification time: 11-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3598756      Ckp time: 11-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
27      Full    9.45M      DISK        00:00:00     11-JAN-16      
        BP Key: 33   Status: AVAILABLE  Compressed: NO  Tag: TAG20160111T225709
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_11/o1_mf_s_900889030_c97jp698_.bkp
  SPFILE Included: Modification time: 11-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3599063      Ckp time: 11-JAN-16

RMAN> list copy;

specification does not match any control file copy in the repository
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
22      1    A 11-JAN-16       3598672    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c97jmno3_.dbf
        Tag: TAG20160111T224925

21      2    A 11-JAN-16       3598619    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c97jkx8v_.dbf
        Tag: TAG20160111T224925

24      3    A 11-JAN-16       3598736    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c97jow0v_.dbf
        Tag: TAG20160111T224925

18      3    A 11-JAN-16       3598736    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c97jd7j8_.dbf
        Tag: TAG20160111T224925

26      4    A 11-JAN-16       3598742    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c97jp4rz_.dbf
        Tag: TAG20160111T224925

20      4    A 11-JAN-16       3598742    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c97jdj0z_.dbf
        Tag: TAG20160111T224925

23      5    A 11-JAN-16       3598706    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c97jo2h8_.dbf
        Tag: TAG20160111T224925

17      5    A 11-JAN-16       3598706    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c97jcg2j_.dbf
        Tag: TAG20160111T224925

25      7    A 11-JAN-16       3598740    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c97jp3nt_.dbf
        Tag: TAG20160111T224925

19      7    A 11-JAN-16       3598740    11-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c97jdgw2_.dbf
        Tag: TAG20160111T224925

List of Archived Log Copies for database with db_unique_name STONE
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
121     1    119     A 11-JAN-16
        Name: /u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_11/o1_mf_1_119_c97jdkow_.arc

创建增量备份

RMAN备份类型:

  • 全备(Full Backups):不同于整备(Whole Backup),全备包括所有使用过的数据文件块,跳过从来没有用过的数据文件块,复制到备份集或者镜像拷贝。
  • 增量备份(Incremental Backups):包括0级增量备份和1级增量备份,0级增量备份等同于全备,包括所有使用过的数据文件块,但可以作为1级增量备份的基础,1级增量备份包括自上次备份后改变过的块。在BACKUP命令使用INCREMENTAL LEVEL [0|1]指定增量备份。

1级增量备份有2种:

  • 差异(Differential):默认类型,对最近一次0级或者1级备份后改变的块进行备份
  • 累积(Cumulative):对最近一次0级备份后改变的块进行备份

执行0级增量备份:

RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;

执行差异增量备份:

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;

执行累积增量备份:

RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;

如果没有指定FULL或者INCREMENTAL,则默认执行全备,不能作为增量备份的基础,然而完整镜像拷贝可以通过使用RECOVER命令应用增量备份进行增量更新。

如果数据库没有打开,可以在NOARCHIVELOG模式进行任何类型的备份(全备或者增备)。

例子:创建增量备份

RMAN> list backup;

specification does not match any backup in the repository

RMAN> list copy;

specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
specification does not match any archived log in the repository

RMAN> backup incremental level 0 database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c98l9nf4_.dbf tag=TAG20160112T083044 RECID=27 STAMP=900923499
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c98lccrp_.dbf tag=TAG20160112T083044 RECID=28 STAMP=900923540
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c98lds0k_.dbf tag=TAG20160112T083044 RECID=29 STAMP=900923556
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c98lf894_.dbf tag=TAG20160112T083044 RECID=30 STAMP=900923566
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c98lfhfh_.dbf tag=TAG20160112T083044 RECID=31 STAMP=900923567
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c98lfjlc_.dbf tag=TAG20160112T083044 RECID=32 STAMP=900923568
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900923569_c98lfl2z_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
28      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 34   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T083249
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900923569_c98lfl2z_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3603414      Ckp time: 12-JAN-16

RMAN> list copy;

specification does not match any control file copy in the repository
specification does not match any archived log in the repository
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
28      1    A 12-JAN-16       3603354    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c98lccrp_.dbf
        Tag: TAG20160112T083044

27      2    A 12-JAN-16       3603256    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c98l9nf4_.dbf
        Tag: TAG20160112T083044

30      3    A 12-JAN-16       3603403    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c98lf894_.dbf
        Tag: TAG20160112T083044

32      4    A 12-JAN-16       3603408    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c98lfjlc_.dbf
        Tag: TAG20160112T083044

29      5    A 12-JAN-16       3603396    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c98lds0k_.dbf
        Tag: TAG20160112T083044

31      7    A 12-JAN-16       3603407    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c98lfhfh_.dbf
        Tag: TAG20160112T083044


RMAN> backup incremental level 1 database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T083629_c98lng5q_.bkp tag=TAG20160112T083629 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900923905_c98lr2r9_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
28      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 34   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T083249
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900923569_c98lfl2z_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3603414      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
29      Incr 1  1.93M      DISK        00:01:54     12-JAN-16      
        BP Key: 35   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T083629
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T083629_c98lng5q_.bkp
  List of Datafiles in backup set 29
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
30      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 36   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T083825
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900923905_c98lr2r9_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3603722      Ckp time: 12-JAN-16

RMAN> list copy;

specification does not match any control file copy in the repository
specification does not match any archived log in the repository
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
28      1    A 12-JAN-16       3603354    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c98lccrp_.dbf
        Tag: TAG20160112T083044

27      2    A 12-JAN-16       3603256    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c98l9nf4_.dbf
        Tag: TAG20160112T083044

30      3    A 12-JAN-16       3603403    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c98lf894_.dbf
        Tag: TAG20160112T083044

32      4    A 12-JAN-16       3603408    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c98lfjlc_.dbf
        Tag: TAG20160112T083044

29      5    A 12-JAN-16       3603396    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c98lds0k_.dbf
        Tag: TAG20160112T083044

31      7    A 12-JAN-16       3603407    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c98lfhfh_.dbf
        Tag: TAG20160112T083044


RMAN> backup incremental level 1 cumulative database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T084519_c98m507j_.bkp tag=TAG20160112T084519 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900924435_c98m8n10_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
28      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 34   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T083249
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900923569_c98lfl2z_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3603414      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
29      Incr 1  1.93M      DISK        00:01:54     12-JAN-16      
        BP Key: 35   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T083629
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T083629_c98lng5q_.bkp
  List of Datafiles in backup set 29
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    1  Incr 3603636    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
30      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 36   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T083825
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900923905_c98lr2r9_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3603722      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
31      Incr 1  2.38M      DISK        00:01:46     12-JAN-16      
        BP Key: 37   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T084519
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T084519_c98m507j_.bkp
  List of Datafiles in backup set 31
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    1  Incr 3604558    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    1  Incr 3604558    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    1  Incr 3604558    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    1  Incr 3604558    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    1  Incr 3604558    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    1  Incr 3604558    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
32      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 38   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T084715
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900924435_c98m8n10_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3604651      Ckp time: 12-JAN-16

RMAN> show device type;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;

RMAN> configure device type disk backup type to backupset;

old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET PARALLELISM 1;
new RMAN configuration parameters are successfully stored

RMAN> delete backup;

RMAN> delete copy;

RMAN> list backup;

specification does not match any backup in the repository

RMAN> list copy;

specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
specification does not match any archived log in the repository

RMAN> backup incremental level 0 database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd0_TAG20160112T091936_c98o58oo_.bkp tag=TAG20160112T091936 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:15
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900926511_c98o9j1j_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
33      Incr 0  1.42G      DISK        00:02:09     12-JAN-16      
        BP Key: 39   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T091936
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd0_TAG20160112T091936_c98o58oo_.bkp
  List of Datafiles in backup set 33
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
34      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 40   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T092151
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900926511_c98o9j1j_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3606793      Ckp time: 12-JAN-16

RMAN> list copy;

specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
specification does not match any archived log in the repository


RMAN> backup incremental level 1 database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T092515_c98ohw5c_.bkp tag=TAG20160112T092515 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900926830_c98omgss_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
33      Incr 0  1.42G      DISK        00:02:09     12-JAN-16      
        BP Key: 39   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T091936
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd0_TAG20160112T091936_c98o58oo_.bkp
  List of Datafiles in backup set 33
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
34      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 40   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T092151
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900926511_c98o9j1j_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3606793      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
35      Incr 1  1.22M      DISK        00:01:46     12-JAN-16      
        BP Key: 41   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T092515
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T092515_c98ohw5c_.bkp
  List of Datafiles in backup set 35
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
36      Full    9.45M      DISK        00:00:00     12-JAN-16      
        BP Key: 42   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T092710
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900926830_c98omgss_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3607104      Ckp time: 12-JAN-16


RMAN> backup incremental level 1 cumulative database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T093506_c98p2cbo_.bkp tag=TAG20160112T093506 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900927412_c98p5no8_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
33      Incr 0  1.42G      DISK        00:02:09     12-JAN-16      
        BP Key: 39   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T091936
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd0_TAG20160112T091936_c98o58oo_.bkp
  List of Datafiles in backup set 33
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    0  Incr 3606653    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
34      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 40   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T092151
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900926511_c98o9j1j_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3606793      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
35      Incr 1  1.22M      DISK        00:01:46     12-JAN-16      
        BP Key: 41   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T092515
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T092515_c98ohw5c_.bkp
  List of Datafiles in backup set 35
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    1  Incr 3607008    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
36      Full    9.45M      DISK        00:00:00     12-JAN-16      
        BP Key: 42   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T092710
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900926830_c98omgss_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3607104      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
37      Incr 1  2.45M      DISK        00:01:39     12-JAN-16      
        BP Key: 43   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T093506
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T093506_c98p2cbo_.bkp
  List of Datafiles in backup set 37
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    1  Incr 3607540    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    1  Incr 3607540    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    1  Incr 3607540    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    1  Incr 3607540    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    1  Incr 3607540    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    1  Incr 3607540    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
38      Full    9.45M      DISK        00:00:00     12-JAN-16      
        BP Key: 44   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T093652
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900927412_c98p5no8_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3607774      Ckp time: 12-JAN-16

创建快速增量备份

通过使用块改变跟踪文件进行快速增量备份(Fast Incremental Backup),块改变跟踪文件记录变化块的物理地址,进行备份的时候就不需要扫描每一个块了,直接根据块改变跟踪文件定位变化的块,加快增量备份。

Oracle自动维护块改变跟踪文件,块改变跟踪文件最小为10M,增量为10M,数据库默认不记录块改变信息。

可以通过ALTER DATABASE语句启用和停用块改变跟踪,启用会自动在DB_CREATE_FILE_DEST指定的位置创建目录和块改变跟踪文件,停用会自动删除文件。可以通过ALTER DATABASE RENAME命令在MOUNT状态重命名块改变跟踪文件。可以使用ALTER DATABASE RENAME FILE '...' TO '...' 改变文件位置。

RMAN不支持备份和恢复块改变跟踪文件,故不要将其放入快速恢复区。

例子:启用和停用块改变跟踪

SQL> show parameter db_create_file_dest;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string      /u01/app/oracle/oradata

SQL> alter database enable block change tracking;

Database altered.

SQL> !ls /u01/app/oracle/oradata/STONE/changetracking/
o1_mf_c98obb33_.chg

SQL> alter database disable block change tracking;

Database altered.

SQL> !ls /u01/app/oracle/oradata/STONE/changetracking/

SQL> 

视图V$BLOCK_CHANGE_TRACKING显示块改变跟踪文件的位置,状态,大小等。

视图V$BACKUP_DATAFILE可以计算块改变跟踪在最小化增量备份I/O上起的作用。比较大的值表示在增量备份的时候读取了数据文件的很多块。

例子:使用块改变跟踪文件创建增量备份

SQL> alter database enable block change tracking;

Database altered.

SQL> select filename,status,bytes from v$block_change_tracking;

FILENAME                                                               STATUS          BYTES
---------------------------------------------------------------------- ---------- ----------
/u01/app/oracle/oradata/STONE/changetracking/o1_mf_c98v5ocs_.chg       ENABLED      11599872

RMAN> delete backup;

RMAN> list backup;

specification does not match any backup in the repository

RMAN> backup incremental level 0 database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd0_TAG20160112T110829_c98vkfbr_.bkp tag=TAG20160112T110829 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:15
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900933044_c98vonwh_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> backup incremental level 1 database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnnd1_TAG20160112T111141_c98vqgq8_.bkp tag=TAG20160112T111141 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900933109_c98vqpcc_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

SQL> select file#,avg(datafile_blocks),avg(blocks_read),avg(blocks_read/datafile_blocks)*100 as pct_read_for_backup,avg(blocks)
  2  from v$backup_datafile
  3  where used_change_tracking='YES' and incremental_level>0
  4  group by file#;

     FILE## AVG(DATAFILE_BLOCKS) AVG(BLOCKS_READ) PCT_READ_FOR_BACKUP AVG(BLOCKS)
---------- -------------------- ---------------- ------------------- -----------
         1                98560               81          .082183442          27
         2               110080              561           .50962936          91
         5                44320                1          .002256318           1
         4                  960                1          .104166667           1
         3                14720              181          1.22961957          36
         7                 1920                1          .052083333           1

6 rows selected.

创建冗余备份集

使用COPIES选项的BACKUP命令创建冗余备份集(Duplexed Backup Sets ),不能创建在快速恢复区。

使用BACKUP COPIES创建冗余备份,执行以下步骤:

  • 使用COPIES选择指定备份数量
  • 使用LIST BACKUP命令查看

例子:创建冗余备份集

RMAN> delete backup;

RMAN> list backup;

specification does not match any backup in the repository

RMAN> backup as backupset copies 2 incremental level 0 database format '/home/oracle/backup/%U';

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16 with 2 copies and tag TAG20160112T113017
piece handle=/home/oracle/backup/2qqr6ai9_1_1 comment=NONE
piece handle=/home/oracle/backup/2qqr6ai9_1_2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:35
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900934372_c98wz4q4_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16


RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size
------- ---- -- ----------
43      Incr 0  1.42G
  List of Datafiles in backup set 43
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    0  Incr 3614834    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2    0  Incr 3614834    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3    0  Incr 3614834    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4    0  Incr 3614834    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5    0  Incr 3614834    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7    0  Incr 3614834    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

  Backup Set Copy #1 of backup set 43
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:02:32     12-JAN-16       NO         TAG20160112T113017

    List of Backup Pieces for backup set 43 Copy #1
    BP Key  Pc## Status      Piece Name
    ------- --- ----------- ----------
    49      1   AVAILABLE   /home/oracle/backup/2qqr6ai9_1_1

  Backup Set Copy #2 of backup set 43
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:02:32     12-JAN-16       NO         TAG20160112T113017

    List of Backup Pieces for backup set 43 Copy #2
    BP Key  Pc## Status      Piece Name
    ------- --- ----------- ----------
    50      1   AVAILABLE   /home/oracle/backup/2qqr6ai9_1_2

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
44      Full    9.45M      DISK        00:00:00     12-JAN-16      
        BP Key: 51   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T113252
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900934372_c98wz4q4_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3615011      Ckp time: 12-JAN-16

创建备份集的备份

使用BACKUP BACKUPSET创建备份集的备份(Backups of Backup Sets),只能对创建在设备类型为DISK的备份集进行备份,可以备份到任何可用设备类型。

例子:创建备份集的备份

RMAN> delete backup;

RMAN> list backup;

specification does not match any backup in the repository

RMAN> backup as backupset device type disk database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T114054_c98xg7d2_.bkp tag=TAG20160112T114054 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:05
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900934980_c98xl4ov_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> backup device type disk backupset all;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: input backup set: count=92, stamp=900934855, piece=1
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T114054_c98xg7d2_.bkp
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T114054_c98xn3j0_.bkp comment=NONE
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
channel ORA_DISK_1: backup piece complete, elapsed time: 00:01:05
channel ORA_DISK_1: input backup set: count=93, stamp=900934980, piece=1
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
skipping backup piece handle /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900934980_c98xl4ov_.bkp; already exists
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
channel ORA_DISK_1: backup piece complete, elapsed time: 00:00:00
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900935108_c98xp528_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size
------- ---- -- ----------
45      Full    1.42G
  List of Datafiles in backup set 45
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3615552    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2       Full 3615552    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3       Full 3615552    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4       Full 3615552    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5       Full 3615552    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7       Full 3615552    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

  Backup Set Copy #1 of backup set 45
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:02:04     12-JAN-16       NO         TAG20160112T114054

    List of Backup Pieces for backup set 45 Copy #1
    BP Key  Pc## Status      Piece Name
    ------- --- ----------- ----------
    52      1   AVAILABLE   /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T114054_c98xg7d2_.bkp

  Backup Set Copy #2 of backup set 45
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:02:04     12-JAN-16       NO         TAG20160112T114054

    List of Backup Pieces for backup set 45 Copy #2
    BP Key  Pc## Status      Piece Name
    ------- --- ----------- ----------
    54      1   AVAILABLE   /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T114054_c98xn3j0_.bkp

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
46      Full    9.45M      DISK        00:00:00     12-JAN-16      
        BP Key: 53   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T114300
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900934980_c98xl4ov_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3615643      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
47      Full    9.45M      DISK        00:00:01     12-JAN-16      
        BP Key: 55   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T114508
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900935108_c98xp528_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3615751      Ckp time: 12-JAN-16

创建只读表空间备份

  • 备份优化会导致 RMAN 仅在不存在满足保留策略的备份时才备份只读表空间。
  • 如果修改了表空间的读写状态,则建议立即进行备份。
  • 可以使用BACKUP命令的SKIP READONLY选项跳过只读表空间或者数据库文件。

例子:满足保留策略情况下跳过只读表空间

RMAN> delete backup;

RMAN> list backup;

specification does not match any backup in the repository

RMAN> show backup optimization;

RMAN configuration parameters for database with db_unique_name STONE are:
CONFIGURE BACKUP OPTIMIZATION OFF;

RMAN> configure backup optimization on;

old RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION OFF;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored

SQL> alter tablespace example read only;

Tablespace altered.

RMAN> backup database;

Starting backup at 12-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=48 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T183047_c99ogr3v_.bkp tag=TAG20160112T183047 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:47
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900959615_c99on091_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> backup database;

Starting backup at 12-JAN-16
using channel ORA_DISK_1
skipping datafile 5; already backed up 2 time(s)
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T183414_c99oo6hl_.bkp tag=TAG20160112T183414 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:16
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900959790_c99osgdj_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
62      Full    1.42G      DISK        00:02:10     12-JAN-16      
        BP Key: 70   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T130252
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T130252_c99280bo_.bkp
  List of Datafiles in backup set 62
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3620850    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2       Full 3620850    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3       Full 3620850    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4       Full 3620850    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5       Full 3618687    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7       Full 3620850    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
63      Full    9.52M      DISK        00:00:05     12-JAN-16      
        BP Key: 71   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T130508
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900939908_c992d910_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3620994      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
64      Full    1.42G      DISK        00:02:44     12-JAN-16      
        BP Key: 72   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T183047
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T183047_c99ogr3v_.bkp
  List of Datafiles in backup set 64
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3641178    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2       Full 3641178    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3       Full 3641178    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4       Full 3641178    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5       Full 3618687    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7       Full 3641178    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
65      Full    9.52M      DISK        00:00:01     12-JAN-16      
        BP Key: 73   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T183335
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900959615_c99on091_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3641367      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
66      Full    1.36G      DISK        00:02:14     12-JAN-16      
        BP Key: 74   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T183414
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T183414_c99oo6hl_.bkp
  List of Datafiles in backup set 66
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3641407    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2       Full 3641407    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3       Full 3641407    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4       Full 3641407    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  7       Full 3641407    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
67      Full    9.52M      DISK        00:00:00     12-JAN-16      
        BP Key: 75   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T183630
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900959790_c99osgdj_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3641508      Ckp time: 12-JAN-16

例子:使用SKIP跳过只读表空间

RMAN> delete backup;

RMAN> list backup;

specification does not match any backup in the repository

RMAN> backup database skip readonly;

Starting backup at 12-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=53 device type=DISK
skipping read-only file 5
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T185525_c99pwy64_.bkp tag=TAG20160112T185525 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:36
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900961081_c99q1tlv_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

创建分片备份

Oracle数据文件最大可以到128TB,可以将大文件分片,创建分片备份(Multisection Backups ),分片备份只能用于备份集,不能用于镜像拷贝。通过并行的方式进行分片备份可以提高性能。一般除了最后一个备份片,备份片的大小一致,一个文件最多256个备份片。

BACKUP和VALIDATE DATAFILE命令可以使用以下选项:

SECTION SIZE <integer> [K | M | G]

来指定每个备份片的大小,也可以为不同文件指定不同备份片的大小。

查看分片备份:

  • 通过V$BACKUP_SET和RC_BACKUP_SET视图的MULTI_SECTION字段查看是否是分片备份
  • 通过V$BACKUP_DATAFILE和RC_BACKUP_DATAFILE视图的SETTION_SIZE字段查看分片备份中每片的块数量,0表示整个文件备份。

例子:创建分片备份

SQL> select recid,multi_section from v$backup_set;

     RECID MUL
---------- ---
        68 NO
        69 NO

SQL> select file#,section_size from v$backup_datafile order by 1;

     FILE## SECTION_SIZE
---------- ------------
         0            0
         1            0
         2            0
         3            0
         4            0
         7            0

6 rows selected.

RMAN> backup datafile 5 section size=100M tag 'section100mb';

Starting backup at 12-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
backing up blocks 1 through 12800
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhby7_.bkp tag=SECTION100MB 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=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
backing up blocks 12801 through 25600
channel ORA_DISK_1: starting piece 2 at 12-JAN-16
channel ORA_DISK_1: finished piece 2 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhfyy_.bkp tag=SECTION100MB 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=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
backing up blocks 25601 through 38400
channel ORA_DISK_1: starting piece 3 at 12-JAN-16
channel ORA_DISK_1: finished piece 3 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhk4l_.bkp tag=SECTION100MB 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=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
backing up blocks 38401 through 44320
channel ORA_DISK_1: starting piece 4 at 12-JAN-16
channel ORA_DISK_1: finished piece 4 at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhn9f_.bkp tag=SECTION100MB comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JAN-16

Starting Control File and SPFILE Autobackup at 12-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900962549_c99rholg_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 12-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
70      Full    68.95M     DISK        00:00:10     12-JAN-16      
  List of Datafiles in backup set 70
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  5       Full 3618687    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf

  Backup Set Copy #1 of backup set 70
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:00:10     12-JAN-16       NO         SECTION100MB

    List of Backup Pieces for backup set 70 Copy #1
    BP Key  Pc## Status      Piece Name
    ------- --- ----------- ----------
    78      1   AVAILABLE   /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhby7_.bkp
    79      2   AVAILABLE   /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhfyy_.bkp
    80      3   AVAILABLE   /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhk4l_.bkp
    81      4   AVAILABLE   /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_SECTION100MB_c99rhn9f_.bkp

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
71      Full    9.52M      DISK        00:00:00     12-JAN-16      
        BP Key: 82   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T192229
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900962549_c99rholg_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3644072      Ckp time: 12-JAN-16

SQL> select recid,multi_section from v$backup_set;

     RECID MUL
---------- ---
        70 YES
        71 NO

SQL> select file#,section_size from v$backup_datafile order by 1;

     FILE## SECTION_SIZE
---------- ------------
         0            0
         5        12800

创建存档备份

如果需要恢复到从备份到当前这段时间的任何时间点(point-in-time recovery),那么就需要这段时间所有的归档日志文件。

还有一种需求,就是将备份保留足够长的时间,只是需要恢复到备份的时候,而不需要恢复到某个时间点,可以通过存档备份(Archival Backups)来解决。如果标记一个备份为存档,则会覆盖其他保留策略,保留备份到指定的时间或者永久。

使用KEEP语句创建存档备份,可以看作数据库在某个时间点上的快照。所需要的仅是恢复备份到一致状态的重做日志,在备份完成后使用RESTORE POINT语句指定需要保留的重做日志数量(足够恢复备份到RESTORE POINT)。

存档备份还保证了恢复备份所需的所有文件,包括数据文件,SPFILE,归档日志文件(仅恢复联机备份所需的日志文件)以及相关的自动备份文件,所有这些文件必须位于同一种介质(或者一组磁带)。

可以指定创建还原点,与存档备份有相同的SCN,相当于为这个备份时间点指定一个有意义的名字。

存档备份不受保留窗口以及DELETE OBSOLETE命令的影响,是数据库在某个时间点的快照,可以还原到另外的数据库用于测试。

存档备份不能写入快速恢复区,需要使用FORMAT语句指定位置。

RMAN使用下面的语法创建存档备份:

BACKUP ... KEEP {FOREVER|UNTIL TIME 'SYSDATE + <n>'} RESTORE POINT <restore_point_name>

可以使用UNTIL TIME指定保留时间,也可以使用FOREVER指定备份永不过期。可以使用RESTORE POINT指定还原点名称,实际上就是数据文件备份完成后捕获的SCN的名称,存档备份可以还原和恢复到这个时间点并使数据库打开。

例子:创建存档备份

RMAN> delete backup;

RMAN> list backup;

specification does not match any backup in the repository


RMAN> list restore point all;

SCN              RSP Time  Type       Time      Name
---------------- --------- ---------- --------- ----

RMAN> backup database keep until time 'sysdate+365' restore point '%RESTORE_POINT' format '/home/oracle/backup/%U';

Starting backup at 12-JAN-16
current log archived

using channel ORA_DISK_1
backup will be obsolete on date 11-JAN-17
archived logs required to recover from this backup will be backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/home/oracle/backup/3uqr7fkk_1_1 tag=TAG20160112T220256 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:46

using channel ORA_DISK_1
backup will be obsolete on date 11-JAN-17
archived logs required to recover from this backup will be backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/home/oracle/backup/3vqr7frm_1_1 tag=TAG20160112T220256 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01


current log archived
using channel ORA_DISK_1
backup will be obsolete on date 11-JAN-17
archived logs required to recover from this backup will be backed up
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=124 RECID=126 STAMP=900972409
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/home/oracle/backup/40qr7frp_1_1 tag=TAG20160112T220256 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

using channel ORA_DISK_1
backup will be obsolete on date 11-JAN-17
archived logs required to recover from this backup will be backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 12-JAN-16
channel ORA_DISK_1: finished piece 1 at 12-JAN-16
piece handle=/home/oracle/backup/41qr7frr_1_1 tag=TAG20160112T220256 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JAN-16

RMAN> list restore point all;

SCN              RSP Time  Type       Time      Name
---------------- --------- ---------- --------- ----
3656190                               12-JAN-16 %RESTORE_POINT

例子:调整备份的保留策略

[oracle@test ~]$ rman target / catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Jan 12 22:16:17 2016

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

connected to target database: STONE (DBID=3001485737)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN> resync catalog;

starting full resync of recovery catalog
full resync complete

将备份修改为永久保存
RMAN> change backup tag 'TAG20160112T220256' keep forever;

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=70 device type=DISK
keep attributes for the backup are changed
backup will never be obsolete
backup set key=1816 RECID=72 STAMP=900972401
keep attributes for the backup are changed
backup will never be obsolete
backup set key=1817 RECID=73 STAMP=900972406
keep attributes for the backup are changed
backup will never be obsolete
backup set key=1818 RECID=74 STAMP=900972410
keep attributes for the backup are changed
backup will never be obsolete
backup set key=1819 RECID=75 STAMP=900972412

将备份修改为适用于保留策略
RMAN> change backup nokeep;

using channel ORA_DISK_1
keep attributes for the backup are deleted
backup set key=1816 RECID=72 STAMP=900972401
keep attributes for the backup are deleted
backup set key=1817 RECID=73 STAMP=900972406
keep attributes for the backup are deleted
backup set key=1818 RECID=74 STAMP=900972410
keep attributes for the backup are deleted
backup set key=1819 RECID=75 STAMP=900972412

管理备份

使用下面的命令获取备份信息:

  • LIST:列出备份集和镜像拷贝信息
  • REPORT:对备份信息进行分析报告
  • REPORT NEED BACKUP:列出所有需要备份的数据文件
  • REPORT OBSOLETE:列出不再满足当前备份保留策略的文件,可以使用REDUNDANCY或者RECOVERY WINDOW选项指定不同的保留策略来产生报告

例子:查看备份信息

RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
76      Full    5.78M      DISK        00:00:01     12-JAN-16      
        BP Key: 87   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T223031
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp
  List of Datafiles in backup set 76
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 3659048    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
77      Full    9.52M      DISK        00:00:01     12-JAN-16      
        BP Key: 88   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T223033
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900973833_c9b3j9vn_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3659113      Ckp time: 12-JAN-16

RMAN> report need backup;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of files with less than 1 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
1    0     /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
2    0     /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
3    0     /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
5    0     /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
7    0     /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

RMAN> backup database;

Starting backup at 13-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=74 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 13-JAN-16
channel ORA_DISK_1: finished piece 1 at 13-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T083100_c9c6p4hq_.bkp tag=TAG20160113T083100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:35
Finished backup at 13-JAN-16

Starting Control File and SPFILE Autobackup at 13-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901010015_c9c6tzoy_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 13-JAN-16

RMAN> report need backup;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of files with less than 1 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------


RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           76     12-JAN-16         
  Backup Piece       87     12-JAN-16          /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp
Backup Set           77     12-JAN-16         
  Backup Piece       88     12-JAN-16          /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900973833_c9b3j9vn_.bkp

可以在目标数据库中查询以下动态性能视图获取备份信息,也可以在恢复目录数据库的恢复目录模式中使用对应的RC_替换V$的这些视图进行查询。

  • V$BACKUP_SET:创建的备份集
  • V$BACKUP_PIECE:存在的备份片
  • V$DATAFILE_COPY:磁盘上面的镜像拷贝
  • V$BACKUP_FILES:所有备份文件的信息

例子:查看备份信息

SQL> select backup_type,file_type,status,fname from v$backup_files;

BACKUP_TYP FILE_TYPE    STATUS     FNAME
---------- ------------ ---------- --------------------------------------------------------------------------------------------------------------
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp
BACKUP SET SPFILE
BACKUP SET CONTROLFILE
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900973833_c9b3j9vn_.bkp
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf

BACKUP_TYP FILE_TYPE    STATUS     FNAME
---------- ------------ ---------- --------------------------------------------------------------------------------------------------------------
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T083100_c9c6p4hq_.bkp
BACKUP SET SPFILE
BACKUP SET CONTROLFILE
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901010015_c9c6tzoy_.bkp

15 rows selected.


[oracle@test ~]$ rman target / catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jan 13 08:51:59 2016

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

connected to target database: STONE (DBID=3001485737)
connected to recovery catalog database

RMAN> resync catalog;

starting full resync of recovery catalog
full resync complete


SQL> conn rcowner/rcowner
Connected.

SQL> call dbms_rcvman.setdatabase(null,null,null,3001485737);

Call completed.

SQL> select backup_type,file_type,status,fname from rc_backup_files;

BACKUP_TYP FILE_TYPE    STATUS     FNAME
---------- ------------ ---------- --------------------------------------------------------------------------------------------------------------
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp
BACKUP SET SPFILE
BACKUP SET CONTROLFILE
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900973833_c9b3j9vn_.bkp
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
BACKUP SET DATAFILE                /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf

BACKUP_TYP FILE_TYPE    STATUS     FNAME
---------- ------------ ---------- --------------------------------------------------------------------------------------------------------------
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T083100_c9c6p4hq_.bkp
BACKUP SET SPFILE
BACKUP SET CONTROLFILE
BACKUP SET PIECE        AVAILABLE  /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901010015_c9c6tzoy_.bkp

15 rows selected.

使用下面的命令管理备份:

  • CROSSCHECK:将RMAN仓库中的备份信息与介质上的文件进行比较,如果对应的文件不存在了,就将该备份信息标记为EXPIRED
  • DELETE EXPIRED:删除标记为EXPIRED的备份信息
  • DELETE OBSOLETE:根据备份策略,删除不再需要的备份,可以使用REDUNDANCY和RECOVERY WINDOW选项

如果没有使用RMAN删除备份,可以使用UNCATALOG命令从恢复目录中删除备份信息,或者使用CROSSCHECK和DELETE EXPIRED命令。

例子:使用CROSSCHECK和DELETE EXPIRED命令

RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
76      Full    5.78M      DISK        00:00:01     12-JAN-16      
        BP Key: 87   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T223031
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp
  List of Datafiles in backup set 76
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 3659048    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
77      Full    9.52M      DISK        00:00:01     12-JAN-16      
        BP Key: 88   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T223033
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900973833_c9b3j9vn_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3659113      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
78      Full    1.45G      DISK        00:02:30     13-JAN-16      
        BP Key: 89   Status: AVAILABLE  Compressed: NO  Tag: TAG20160113T083100
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T083100_c9c6p4hq_.bkp
  List of Datafiles in backup set 78
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5       Full 3618687    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
79      Full    9.52M      DISK        00:00:00     13-JAN-16      
        BP Key: 90   Status: AVAILABLE  Compressed: NO  Tag: TAG20160113T083335
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901010015_c9c6tzoy_.bkp
  SPFILE Included: Modification time: 13-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3661883      Ckp time: 13-JAN-16

[oracle@test ~]$ rm /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp

RMAN> crosscheck backup;

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp RECID=87 STAMP=900973831
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900973833_c9b3j9vn_.bkp RECID=88 STAMP=900973833
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T083100_c9c6p4hq_.bkp RECID=89 STAMP=901009860
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901010015_c9c6tzoy_.bkp RECID=90 STAMP=901010015
Crosschecked 4 objects

RMAN> delete expired backup;

using channel ORA_DISK_1

List of Backup Pieces
BP Key  BS Key  Pc## Cp## Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
87      76      1   1   EXPIRED     DISK        /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_12/o1_mf_nnndf_TAG20160112T223031_c9b3j7z6_.bkp RECID=87 STAMP=900973831
Deleted 1 EXPIRED objects

例子:使用UNCATALOG
RMAN> backup datafile 4;

Starting backup at 13-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 13-JAN-16
channel ORA_DISK_1: finished piece 1 at 13-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T095836_c9cctdn4_.bkp tag=TAG20160113T095836 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 13-JAN-16

Starting Control File and SPFILE Autobackup at 13-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901015117_c9cctfrz_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 13-JAN-16

[oracle@test ~]$ rman target / catalog rcowner/rcowner

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jan 13 09:57:48 2016

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

connected to target database: STONE (DBID=3001485737)
connected to recovery catalog database

[oracle@test ~]$ rm /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T095836_c9cctdn4_.bkp

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2643    Full    9.52M      DISK        00:00:01     12-JAN-16      
        BP Key: 2645   Status: AVAILABLE  Compressed: NO  Tag: TAG20160112T223033
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_12/o1_mf_s_900973833_c9b3j9vn_.bkp
  SPFILE Included: Modification time: 12-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3659113      Ckp time: 12-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3022    Full    1.45G      DISK        00:02:30     13-JAN-16      
        BP Key: 3026   Status: AVAILABLE  Compressed: NO  Tag: TAG20160113T083100
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T083100_c9c6p4hq_.bkp
  List of Datafiles in backup set 3022
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
  2       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
  3       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
  4       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
  5       Full 3618687    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
  7       Full 3661683    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3023    Full    9.52M      DISK        00:00:00     13-JAN-16      
        BP Key: 3027   Status: AVAILABLE  Compressed: NO  Tag: TAG20160113T083335
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901010015_c9c6tzoy_.bkp
  SPFILE Included: Modification time: 13-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3661883      Ckp time: 13-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3100    Full    5.78M      DISK        00:00:00     13-JAN-16      
        BP Key: 3104   Status: AVAILABLE  Compressed: NO  Tag: TAG20160113T095836
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T095836_c9cctdn4_.bkp
  List of Datafiles in backup set 3100
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 3667290    13-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3101    Full    9.52M      DISK        00:00:00     13-JAN-16      
        BP Key: 3105   Status: AVAILABLE  Compressed: NO  Tag: TAG20160113T095837
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_13/o1_mf_s_901015117_c9cctfrz_.bkp
  SPFILE Included: Modification time: 13-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3667297      Ckp time: 13-JAN-16

RMAN> change backuppiece 3104 uncatalog;

uncataloged backup piece
backup piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_13/o1_mf_nnndf_TAG20160113T095836_c9cctdn4_.bkp RECID=91 STAMP=901015116
Uncataloged 1 objects

Restore and Recover

Oracle中的备份和恢复中的恢复包括2方面:

  • 还原(Restore):从备份获取数据文件。语法:
RESTORE {DATABASE | TABLESPACE name [,name]... | DATAFILE name [,name] }...
  • 恢复(Recover):应用增量备份和重做日志中的改变。语法:
RECOVER {DATABASE | TABLESPACE name [,name]... | DATAFILE name [,name] }...

恢复临时文件

临时表空间的临时文件丢失或者损坏,会导致需要使用临时表空间进行排序的SQL语句执行失败。

如果实例启动时候没有临时文件,那么数据库会自动创建,并在告警日志中增加如下信息:

Re-creating tempfile /u01/app/oracle/oradata/orcl/temp01.dbf

也可以使用如下命令手工重建临时文件:

SQL> ALTER TABLESPACE temp ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp02.dbf' SIZE 20M;
SQL> ALTER TABLESPACE temp DROP TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf';

例子:数据库重启自动创建临时文件

SQL> select tablespace_name,file_name,bytes/1024/1024 from dba_temp_files;

TABLESPACE_NAME      FILE_NAME                                                              BYTES/1024/1024
-------------------- ---------------------------------------------------------------------- ---------------
TEMP                 /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c06xhsm8_.tmp                     29

SQL> !rm /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c06xhsm8_.tmp

SQL> insert into emp select * from emp;

876544 rows created.

SQL> select * from emp order by 1,2,3,4,5,6,7,8,9;
select * from emp order by 1,2,3,4,5,6,7,8,9
              *
ERROR at line 1:
ORA-01116: error in opening database file 201
ORA-01110: data file 201: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c06xhsm8_.tmp'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
Database opened.

数据库重启后自动重建一个新的临时文件并删除无效的记录。
SQL> select tablespace_name,file_name,bytes/1024/1024 from dba_temp_files;

TABLESPACE_NAME FILE_NAME                                                       BYTES/1024/1024
--------------- --------------------------------------------------------------- ---------------
TEMP            /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c9dnkhxd_.tmp              20

例子:手工重建临时文件

SQL> select tablespace_name,file_name,bytes/1024/1024 from dba_temp_files;

TABLESPACE_NAME FILE_NAME                                                       BYTES/1024/1024
--------------- --------------------------------------------------------------- ---------------
TEMP            /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c9dnkhxd_.tmp              20

SQL> !rm /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c9dnkhxd_.tmp

SQL> alter tablespace temp add tempfile size 20M;

Tablespace altered.

SQL> select tablespace_name,file_name,bytes/1024/1024 from dba_temp_files;

TABLESPACE_NAME FILE_NAME                                                       BYTES/1024/1024
--------------- --------------------------------------------------------------- ---------------
TEMP            /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c9dnkhxd_.tmp              20
TEMP            /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c9dnt4fs_.tmp              20

SQL> alter tablespace temp drop tempfile '/u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c9dnkhxd_.tmp';

Tablespace altered.

SQL> select tablespace_name,file_name,bytes/1024/1024 from dba_temp_files;

TABLESPACE_NAME FILE_NAME                                                       BYTES/1024/1024
--------------- --------------------------------------------------------------- ---------------
TEMP            /u01/app/oracle/oradata/STONE/datafile/o1_mf_temp_c9dnt4fs_.tmp              20

恢复联机重做日志

日志组有以下三种循环状态:

  • CURRENT:LGWR进程正在写入的日志组
  • ACTIVE:不再写入,实例恢复open in new window需要该组日志,等待执行检查点
  • INACTIVE:不再写入,实例恢复也不需要该组日志,已经执行了检查点

丢失联机日志组的恢复:

  • 丢失的日志组是INACTIVE状态,如果介质修复了,那么就可以继续使用,如果介质不能修复,可以清除日志文件进行重建。
  • 丢失的日志组是ACTIVE状态,如果可以执行检查点,则表示不再需要它进行实例恢复,会到INACTIVE状态,后续操作与INACTIVE一样。
  • 丢失的日志组是CURRENT状态,如果实例崩溃,只能还原备份,执行cacel-based point-in-time恢复,使用RESETLOGS选项打开数据库。

image-20221115161623855

清除日志文件使用如下命令:

ALTER DATABASE CLEAR [UNARCHIVED] LOGFILE GROUP <n>
  [UNRECOVERABLE DATAFILE]

如果日志文件已经归档,则使用最简单的格式:

ALTER DATABASE CLEAR LOGFILE GROUP <n>

使用如下语句查询日志组是否归档:

SQL> SELECT GROUP#, STATUS, ARCHIVED FROM V$LOG;

如果日志文件没有归档,则必须使用UNARCHIVED关键字,确认放弃这一部分重做日志的恢复,然后需要对数据库进行备份,这样后续就不会需要这一部分重做日志了。

恢复一个当前Offline的数据文件是有可能需要重做日志的,使用UNRECOVERABLE DATAFILE进行恢复。

image-20221115162221874

例子:丢失INACTIVE日志组的恢复

SQL> select l.group#,l.status,archived,member from v$log l join v$logfile lf on l.group#=lf.group## order by 1;

    GROUP## STATUS           ARC MEMBER
---------- ---------------- --- --------------------------------------------------------------------------------
         1 INACTIVE         YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c06xh9t5_.log
         1 INACTIVE         YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c06xh9xt_.log
         2 INACTIVE         YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c06xhdlj_.log
         2 INACTIVE         YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c06xhdnc_.log
         3 CURRENT          NO  /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c06xhj1g_.log
         3 CURRENT          NO  /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c06xhj37_.log

6 rows selected.

SQL> !rm /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c06xh9t5_.log

SQL> !rm /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c06xh9xt_.log

SQL> alter database clear logfile group 1;

Database altered.

SQL> select l.group#,l.status,archived,member from v$log l join v$logfile lf on l.group#=lf.group## order by 1;

    GROUP## STATUS           ARC MEMBER
---------- ---------------- --- --------------------------------------------------------------------------------
         1 UNUSED           YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c9ds6g3g_.log
         1 UNUSED           YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c9ds6g7o_.log
         2 INACTIVE         YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c06xhdlj_.log
         2 INACTIVE         YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c06xhdnc_.log
         3 CURRENT          NO  /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c06xhj1g_.log
         3 CURRENT          NO  /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c06xhj37_.log

6 rows selected.

例子:丢失ACTIVE日志组的恢复

SQL> select l.group#,l.status,archived,member from v$log l join v$logfile lf on l.group#=lf.group## order by 1;

    GROUP## STATUS           ARC MEMBER
---------- ---------------- --- --------------------------------------------------------------------------------
         1 INACTIVE         YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c9ds6g3g_.log
         1 INACTIVE         YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c9ds6g7o_.log
         2 ACTIVE           YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c06xhdlj_.log
         2 ACTIVE           YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c06xhdnc_.log
         3 CURRENT          NO  /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c9dt1dc8_.log
         3 CURRENT          NO  /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9dt1dfx_.log

6 rows selected.

SQL> !rm /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c06xhdlj_.log

SQL> !rm /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c06xhdnc_.log

SQL> alter system checkpoint;

System altered.

SQL> alter database clear logfile group 2;

Database altered.

SQL> select l.group#,l.status,archived,member from v$log l join v$logfile lf on l.group#=lf.group## order by 1;

    GROUP## STATUS           ARC MEMBER
---------- ---------------- --- --------------------------------------------------------------------------------
         1 INACTIVE         YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c9ds6g3g_.log
         1 INACTIVE         YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c9ds6g7o_.log
         2 UNUSED           YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c9dtbvbt_.log
         2 UNUSED           YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9dtbvhf_.log
         3 CURRENT          NO  /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c9dt1dc8_.log
         3 CURRENT          NO  /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9dt1dfx_.log

6 rows selected.

例子:丢失CURRENT日志组的恢复

SQL> select l.group#,l.status,archived,member from v$log l join v$logfile lf on l.group#=lf.group## order by 1;

    GROUP## STATUS           ARC MEMBER
---------- ---------------- --- --------------------------------------------------------------------------------
         1 INACTIVE         YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c9ds6g3g_.log
         1 INACTIVE         YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c9ds6g7o_.log
         2 UNUSED           YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c9dtbvbt_.log
         2 UNUSED           YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9dtbvhf_.log
         3 CURRENT          NO  /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c9dt1dc8_.log
         3 CURRENT          NO  /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9dt1dfx_.log

6 rows selected.

SQL> !rm /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c9dt1dc8_.log

SQL> !rm /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9dt1dfx_.log

SQL> alter system switch logfile;

System altered.

SQL> alter system checkpoint;

System altered.

SQL> alter database clear logfile group 3;
alter database clear logfile group 3
*
ERROR at line 1:
ORA-00350: log 3 of instance stone (thread 1) needs to be archived
ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c9dt1dc8_.log'
ORA-00312: online log 3 thread 1: '/u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9dt1dfx_.log'


SQL> alter database clear unarchived logfile group 3;

Database altered.

SQL> select l.group#,l.status,archived,member from v$log l join v$logfile lf on l.group#=lf.group## order by 1;

    GROUP## STATUS           ARC MEMBER
---------- ---------------- --- --------------------------------------------------------------------------------
         1 INACTIVE         YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c9ds6g3g_.log
         1 INACTIVE         YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c9ds6g7o_.log
         2 CURRENT          NO  /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c9dtbvbt_.log
         2 CURRENT          NO  /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9dtbvhf_.log
         3 UNUSED           YES /u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c9dthbft_.log
         3 UNUSED           YES /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9dthblx_.log

6 rows selected.

恢复索引表空间

索引表空间的数据文件丢失,执行以下步骤恢复:

  1. Drop数据文件。
  2. Drop表空间。
  3. 重建索引表空间。
  4. 重建索引。

使用以下关键字创建索引,缩短创建时间:

  • PARALLEL:默认是不并行,使用并行可以让多个处理器同时创建索引,速度更快。
  • NOLOGGING:只会产生非常少量的重做日志记录,也可以通过ALTER INDEX NOLOGGING/LOGGING命令进行修改。

如果使用了Data Guard或者在数据库或表级使用FORCE LOGGING,则会覆盖NOLOGGING设置。

如果索引丢失了,相比恢复,创建索引有时会更快和更简单。可以使用Data Pump Export命令以及CONTENT=METADATA_ONLY参数创建包含重建索引的SQL语句的dump文件,再使用Data Pump Import命令及SQLFILE=<filename>参数导入dump文件。

例子:丢失索引表空间

SQL> create tablespace test_index datafile size 10M;

Tablespace created.

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------------------------------------
USERS                /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
UNDOTBS1             /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
SYSAUX               /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
SYSTEM               /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
TEST_INDEX           /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g2k2h2_.dbf
EXAMPLE              /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
RCAT_TS              /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

7 rows selected.

SQL> create user ind identified by ind default tablespace test_index;

User created.

SQL> grant dba to ind;

Grant succeeded.

SQL> conn ind/ind
Connected.

SQL> create table emp as select * from hr.employees where 1=0;

Table created.

SQL> create index index_1 on emp(last_name) tablespace test_index nologging;

Index created.
[oracle@test ~]$ expdp ind/ind directory=data_pump_dir dumpfile=test.dmp

Export: Release 11.2.0.4.0 - Production on Thu Jan 14 11:28:39 2016

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "IND"."SYS_EXPORT_SCHEMA_01":  ind/******** directory=data_pump_dir dumpfile=test.dmp 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "IND"."EMP"                                     0 KB       0 rows
^[[AMaster table "IND"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for IND.SYS_EXPORT_SCHEMA_01 is:
  /u01/app/oracle/admin/stone/dpdump/test.dmp
Job "IND"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Jan 14 11:29:04 2016 elapsed 0 00:00:25

[oracle@test ~]$ impdp ind/ind directory=data_pump_dir dumpfile=test.dmp sqlfile=createindex.sql

Import: Release 11.2.0.4.0 - Production on Thu Jan 14 11:29:12 2016

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "IND"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
Starting "IND"."SYS_SQL_FILE_FULL_01":  ind/******** directory=data_pump_dir dumpfile=test.dmp sqlfile=createindex.sql 
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Job "IND"."SYS_SQL_FILE_FULL_01" successfully completed at Thu Jan 14 11:29:15 2016 elapsed 0 00:00:02

[oracle@test ~]$ cat /u01/app/oracle/admin/stone/dpdump/createindex.sql 
-- CONNECT IND
ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
-- new object type path: SCHEMA_EXPORT/USER
-- CONNECT SYSTEM
 CREATE USER "IND" IDENTIFIED BY VALUES 'S:BDCE451E685962D89DC91F33FFFA101C70087BA591000F074BA73C684E64;83FE70BA53E35C65'
      DEFAULT TABLESPACE "TEST_INDEX"
      TEMPORARY TABLESPACE "TEMP";
-- new object type path: SCHEMA_EXPORT/SYSTEM_GRANT
GRANT UNLIMITED TABLESPACE TO "IND";
-- new object type path: SCHEMA_EXPORT/ROLE_GRANT
 GRANT "DBA" TO "IND";
-- new object type path: SCHEMA_EXPORT/DEFAULT_ROLE
 ALTER USER "IND" DEFAULT ROLE ALL;
-- new object type path: SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
-- CONNECT IND

BEGIN 
sys.dbms_logrep_imp.instantiate_schema(schema_name=>SYS_CONTEXT('USERENV','CURRENT_SCHEMA'), export_db_name=>'STONE', inst_scn=>'3758719');
COMMIT; 
END; 
/ 
-- new object type path: SCHEMA_EXPORT/TABLE/TABLE
CREATE TABLE "IND"."EMP" 
   (    "EMPLOYEE_ID" NUMBER(6,0), 
        "FIRST_NAME" VARCHAR2(20 BYTE), 
        "LAST_NAME" VARCHAR2(25 BYTE) NOT NULL ENABLE, 
        "EMAIL" VARCHAR2(25 BYTE) NOT NULL ENABLE, 
        "PHONE_NUMBER" VARCHAR2(20 BYTE), 
        "HIRE_DATE" DATE NOT NULL ENABLE, 
        "JOB_ID" VARCHAR2(10 BYTE) NOT NULL ENABLE, 
        "SALARY" NUMBER(8,2), 
        "COMMISSION_PCT" NUMBER(2,2), 
        "MANAGER_ID" NUMBER(6,0), 
        "DEPARTMENT_ID" NUMBER(4,0)
   ) SEGMENT CREATION DEFERRED 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
 NOCOMPRESS LOGGING
  TABLESPACE "TEST_INDEX" ;
-- new object type path: SCHEMA_EXPORT/TABLE/INDEX/INDEX
CREATE INDEX "IND"."INDEX_1" ON "IND"."EMP" ("LAST_NAME") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING 
  TABLESPACE "TEST_INDEX" PARALLEL 1 ;

  ALTER INDEX "IND"."INDEX_1" NOPARALLEL;
-- new object type path: SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
DECLARE I_N VARCHAR2(60); 
  I_O VARCHAR2(60); 
  NV VARCHAR2(1); 
  c DBMS_METADATA.T_VAR_COLL; 
  df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS'; 
 stmt varchar2(300) := ' INSERT INTO "SYS"."IMPDP_STATS" (type,version,flags,c1,c2,c3,c5,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,d1,cl1) VALUES (''I'',6,:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,NULL,:14,:15,NULL,:16,:17)';
BEGIN
  DELETE FROM "SYS"."IMPDP_STATS"; 
  i_n := 'INDEX_1'; 
  i_o := 'IND'; 
  EXECUTE IMMEDIATE stmt USING 2,I_N,NV,NV,I_O,0,0,0,0,0,0,0,0,NV,NV,TO_DATE('2016-01-14 11:28:28',df),NV;

  DBMS_STATS.IMPORT_INDEX_STATS('"' || i_o || '"','"' || i_n || '"',NULL,'"IMPDP_STATS"',NULL,'"SYS"'); 
  DELETE FROM "SYS"."IMPDP_STATS"; 
END; 
/
SQL> conn / as sysdba
Connected.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> !rm /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g2k2h2_.dbf

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g2k2h2_.dbf'


SQL> alter database datafile 6 offline drop;

Database altered.

SQL> alter database open;

Database altered.

SQL> drop tablespace test_index including contents;

Tablespace dropped.

SQL> create tablespace test_index datafile size 10M;

Tablespace created.

SQL>  create index index_1 on hr.employees(last_name) tablespace test_index nologging;

Index created.

重建密码文件

数据库管理员有可能是在数据库服务器上面本地管理数据库,也有可能是通过远程管理数据库,可以选择通过操作系统或者密码文件进行认证。

  • 如果数据库有一个密码文件,且已经授予用户SYSDBA和SYSOPER权限,则用户可以使用密码文件认证。
  • 如果数据库没有密码文件,或者没有授予用户SYSDBA和SYSOPER权限,则用户可以使用操作系统认证。用户在OSDBA组会被授予SYSDBA权限,用户在OSOPER组会被授予SYSOPEN权限。

系统会优先使用操作系统认证,如果用户属于OSDBA或者OSOPER组,使用AS SYSDBA或者SYSOPER连接,则不管指定了什么用户名和密码,都会以管理权限进行连接。

Oracle提供了一个名为orapwd的密码工具用于创建密码文件。当使用SYSDBA连接,则会连接到SYS模式,当使用SYSOPER连接,则会连接到PUBLIC模式。通过GRANT命令授权SYSDBA或者SYSOPER的用户才能使用密码文件访问数据库。

因为可以轻松重建密码文件,所以一般不会备份密码文件。

如果设置了参数REMOTE_LOGIN_PASSWORDFILEopen in new window=EXCLUSIVE或SHARED,则不要删除密码文件,否则无法通过密码文件远程连接到数据库。

密码大小写敏感,但是如果原有密码文件设置了IGNORECASE=Y选项,重建也必须使用该选项。

重建密码文件的步骤:

  1. 通过orapwd创建密码文件
orapwd file=filename password=password entries=max_users

其中:

  • filename:密码文件名称
  • password:SYS的密码
  • entries:允许使用SYSDBA或者SYSOPER连接的最大用户数量,如果要超过这个数量,必须创建一个新的密码文件。等号之间没有空格。
  1. 使用创建的密码文件连接到数据库,授予用户权限
SQL> CONNECT sys/admin AS SYSDBA

SQL> grant sysdba to admin2;

密码文件的位置:

  • UNIX: $ORACLE_HOME/dbs
  • Windows: %ORACLE_HOME%\database

例子:查询密码文件内容,删除密码文件并重建

SQL> select * from v$pwfile_users;

USERNAME                       SYSDB SYSOP SYSAS
------------------------------ ----- ----- -----
SYS                            TRUE  TRUE  FALSE


SQL> !rm /u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwstone


SQL> select * from v$pwfile_users;

no rows selected


SQL> !orapwd file=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwstone password=123456 entries=10

SQL> select * from v$pwfile_users;

USERNAME                       SYSDB SYSOP SYSAS
------------------------------ ----- ----- -----
SYS                            TRUE  TRUE  FALSE

基于时间点的恢复

有2种恢复类型:

  • 完全恢复:将数据库恢复到当前时间点,包括所有提交的数据。
  • 不完全恢复:将数据库恢复到过去的某一个时间点,也称之为“Database Point in Time Recovery”,会丢失这个时间点之后的所有事务。用于取消某个时间点后对数据所做的所有改变。

完全恢复过程:

  1. 从备份还原文件。
  2. 从增量备份,归档重做日志文件,联机重做日志文件应用改变到最近的事务。
  3. 还原的数据文件可能包括已经提交的修改和没有提交的修改。
  4. 使用UNDO回滚没有提交的修改。
  5. 恢复完成,文件一致。

不完全恢复或者基于时间点的恢复,就是使用备份产生一个非当前版本的数据库,不需要应用所有的重做记录。

执行Point-in-Time Recovery,需要:

  • 在恢复点之前的所有数据文件的有效备份,包括脱机备份和联机备份。
  • 从备份时间点到恢复时间点的所有归档日志。

恢复步骤如下:

  1. 从备份还原数据文件:可以使用操作系统的复制命令或者RMAN的RESTORE命令。
  2. 使用RECOVER命令:应用归档重做日志文件到还原点,包括了UNDO数据。
  3. 数据文件包括提交和未提交的数据。
  4. 使用ALTER DATABASE OPEN命令。
  5. 自动应用UNDO数据,撤销未提交的事务。
  6. 处理完成。

例子:基于时间点的不完全恢复

先做一个整备
RMAN> backup database plus archivelog delete input;


Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=142 RECID=144 STAMP=901202541
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T140221_c9k2vg5w_.bkp tag=TAG20160115T140221 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_142_c9k2vf0r_.arc RECID=144 STAMP=901202541
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
using channel ORA_DISK_1
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=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T140223_c9k2vmjm_.bkp tag=TAG20160115T140223 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:17
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=143 RECID=145 STAMP=901202680
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T140440_c9k2zs4b_.bkp tag=TAG20160115T140440 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_143_c9k2zrkw_.arc RECID=145 STAMP=901202680
Finished backup at 15-JAN-16

Starting Control File and SPFILE Autobackup at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901202682_c9k2ztgc_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 15-JAN-16

重启到mount
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.

执行不完全恢复
RMAN> restore database until time "to_date('2016-01-17 14:07:17','yyyy-mm-dd hh24:mi:ss')";

Starting restore at 15-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK

skipping datafile 5; already restored to file /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T140223_c9k2vmjm_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T140223_c9k2vmjm_.bkp tag=TAG20160115T140223
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:46
Finished restore at 15-JAN-16

RMAN> recover database until time "to_date('2016-01-17 14:07:17','yyyy-mm-dd hh24:mi:ss')";

Starting recover at 15-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 15-JAN-16

RMAN> alter database open resetlogs;

database opened

恢复只读表空间

因为只读表空间不能写入,故备份的时候不需要将表空间置于备份模式或者离线,简单拷贝就可以了。

当还原只读表空间时,将表空间离线,还原,再联机。

当只读表空间修改为可读写,执行以下操作:

  1. 备份只读表空间
  2. 将表空间置为读写
  3. 恢复表空间

即使备份之后表空间置为读写,甚至被写入了,只读时候做的备份仍然可用于恢复。

例子:恢复只读表空间

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
SYSAUX                         ONLINE
UNDOTBS1                       ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        READ ONLY
RCAT_TS                        ONLINE
TEST_INDEX                     ONLINE

8 rows selected.

RMAN> backup database plus archivelog delete input;

Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=154 STAMP=901205555
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T145235_c9k5smqc_.bkp tag=TAG20160115T145235 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_1_c9k5sm90_.arc RECID=154 STAMP=901205555
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
using channel ORA_DISK_1
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=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T145236_c9k5soy4_.bkp tag=TAG20160115T145236 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:15
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=2 RECID=155 STAMP=901205692
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T145452_c9k5xx10_.bkp tag=TAG20160115T145452 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9k5xwlc_.arc RECID=155 STAMP=901205692
Finished backup at 15-JAN-16

Starting Control File and SPFILE Autobackup at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901205694_c9k5xycp_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 15-JAN-16

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> !rm /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf

SQL> startup mount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.

[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 15 15:06:30 2016

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

connected to target database: STONE (DBID=3001485737, not open)

RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      15-JAN-16     One or more non-system datafiles are missing

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      15-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore and recover datafile 5  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3443618444.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3443618444.hm

contents of repair script:
   ## restore and recover datafile
   restore datafile 5;
   recover datafile 5;
   sql 'alter database datafile 5 online';

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 15-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c06xj0bk_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T145236_c9k5soy4_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T145236_c9k5soy4_.bkp tag=TAG20160115T145236
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 15-JAN-16

Starting recover at 15-JAN-16
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 15-JAN-16

sql statement: alter database datafile 5 online
repair failure complete

Do you want to open the database (enter YES or NO)? yes
database opened

恢复非归档数据库对象

创建表和索引的时候加上NOLOGGING属性,可以提高插入速度。

SQL> CREATE TABLE sales_copy NOLOGGING;
SQL> INSERT /*+ APPEND */ INTO sales_copy
  2  SELECT * FROM sales_history;

上面创建sales_copy表使用了NOLOGGING属性。当INSERT语句使用APPEND Hint,不会产生REDO,故不能恢复这个事务。

进行介质恢复的时候,如果有NOLOGGING对象,在恢复过程中,这些对象会被标记为逻辑损坏,需要删除NOLOGGING对象并重建。

使用REPORT UNRECOVERABLE命令列出包含执行过NOLOGGING操作对象的数据文件。

SQL> alter table emp nologging;

Table altered.

SQL> select table_name,logging from user_tables where table_name='EMP';

TABLE_NAME                     LOG
------------------------------ ---
EMP                            NO

SQL> insert /*+ APPEND */ into emp select * from emp;

107 rows created.

SQL> commit;

Commit complete.

RMAN> report unrecoverable;

Report of files that need backup due to unrecoverable operations
File Type of Backup Required Name
---- ----------------------- -----------------------------------
4    full or incremental     /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf

丢失所有控制文件的恢复

确保不要丢失所有的控制文件,如果丢失了所有的控制文件,但是还有备份,则恢复的方法取决于联机重置日志文件和数据文件的状态。

(1)联机重做日志文件可用

如果联机重做日志文件可用并包含恢复所需的重做记录,不论数据文件当前是否存在,则可以还原控制文件,执行完全恢复,使用RESETLOGS打开数据库。在恢复过程中需要指定联机重做日志文件名。

(2)联机重做日志文件不可用

如果联机重做日志文件不可用但数据文件存在,则需要重建控制文件,使用RESETLOGS打开数据库。如果数据文件不存在,则还原备份的控制文件,执行Point-in-Time恢复,使用RESETLOGS打开数据库。

例子:丢失所有控制文件,数据文件以及联机重做日志文件的恢复

RMAN> backup database plus archivelog delete input;


Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=167 STAMP=901210666
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T161746_c9kbsboc_.bkp tag=TAG20160115T161746 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_1_c9kbsb9p_.arc RECID=167 STAMP=901210666
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
using channel ORA_DISK_1
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=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9k6o4tp_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T161747_c9kbsg13_.bkp tag=TAG20160115T161747 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:15
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=2 RECID=168 STAMP=901210803
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T162003_c9kbxmkf_.bkp tag=TAG20160115T162003 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9kbxm8q_.arc RECID=168 STAMP=901210803
Finished backup at 15-JAN-16

Starting Control File and SPFILE Autobackup at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901210804_c9kbxnqb_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 15-JAN-16


SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf
/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9k6o4tp_.dbf
/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf

7 rows selected.

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/STONE/onlinelog/o1_mf_3_c9k5fb7q_.log
/u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9k5fc9t_.log
/u01/app/oracle/oradata/STONE/onlinelog/o1_mf_2_c9k5f7l7_.log
/u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9k5f8t5_.log
/u01/app/oracle/oradata/STONE/onlinelog/o1_mf_1_c9k5f63d_.log
/u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c9k5f6or_.log

6 rows selected.

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
/home/oracle/o1_mf_c06xh9fs_.ctl


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> !rm /u01/app/oracle/oradata/STONE/datafile/*

SQL> !rm /u01/app/oracle/oradata/STONE/onlinelog/*

SQL> !rm /u01/app/oracle/fast_recovery_area/STONE/onlinelog/*

SQL> !rm /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl

SQL> !rm /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl

SQL> !rm /home/oracle/o1_mf_c06xh9fs_.ctl

SQL> startup nomount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes

[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 15 16:27:45 2016

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

connected to target database: STONE (not mounted)

RMAN> restore controlfile from autobackup;

Starting restore at 15-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK

recovery area destination: /u01/app/oracle/fast_recovery_area
database name (or database unique name) used for search: STONE
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901210804_c9kbxnqb_.bkp found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901210804_c9kbxnqb_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
output file name=/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
output file name=/home/oracle/o1_mf_c06xh9fs_.ctl
Finished restore at 15-JAN-16

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1


RMAN> list failure;

no failures found that match specification

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 01/15/2016 16:29:41
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 01/15/2016 16:29:53
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf'

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
4107       CRITICAL OPEN      15-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf' is missing
4104       CRITICAL OPEN      15-JAN-16     Control file needs media recovery
3282       HIGH     OPEN      15-JAN-16     One or more non-system datafiles are missing

RMAN> advise failure;

Starting implicit crosscheck backup at 15-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 15-JAN-16

Starting implicit crosscheck copy at 15-JAN-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 15-JAN-16

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901208867_c9k913mg_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901210804_c9kbxnqb_.bkp

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
4107       CRITICAL OPEN      15-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf' is missing
4104       CRITICAL OPEN      15-JAN-16     Control file needs media recovery
3282       HIGH     OPEN      15-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If you have the correct version of the control file, then shutdown the database and replace the old control file
2. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf was unintentionally renamed or moved, restore it
3. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf was unintentionally renamed or moved, restore it
4. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf was unintentionally renamed or moved, restore it
5. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf was unintentionally renamed or moved, restore it
6. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9k6o4tp_.dbf was unintentionally renamed or moved, restore it
7. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf was unintentionally renamed or moved, restore it
8. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Perform incomplete database recovery  
  Strategy: The repair includes point-in-time recovery with some data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2303641599.hm


RMAN> repair failure;

Strategy: The repair includes point-in-time recovery with some data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2303641599.hm

contents of repair script:
   ## database point-in-time recovery until a missing log
   restore database until scn 3830448;
   recover database until scn 3830448;
   alter database open resetlogs;

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 15-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9k6o4tp_.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T161747_c9kbsg13_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T161747_c9kbsg13_.bkp tag=TAG20160115T161747
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 15-JAN-16

Starting recover at 15-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T162003_c9kbxmkf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T162003_c9kbxmkf_.bkp tag=TAG20160115T162003
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9kcnrx0_.arc thread=1 sequence=2
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9kcnrx0_.arc RECID=169 STAMP=901211544
media recovery complete, elapsed time: 00:00:01
Finished recover at 15-JAN-16

database opened
repair failure complete

如果需要恢复控制文件且默认位置可用,按照下面步骤进行恢复:

先关闭数据库,再还原控制文件到默认位置。使用如下命令拷贝备份控制文件到默认位置:

% cp /backup/control01.dbf /disk1/oradata/trgt/control01.dbf
% cp /backup/control02.dbf /disk2/oradata/trgt/control02.dbf

MOUNT数据库,指定使用备份的控制文件进行恢复:

SQL> RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL;

在恢复过程中,如果提示缺少重做日志,有可能是缺少联机重做日志文件,指定一个联机重做日志文件名字。恢复完成后,使用RESETLOGS选项打开数据库。

例子:丢失所有控制文件的恢复

RMAN> backup database plus archivelog delete input;


Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=156 STAMP=901208738
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T154538_c9k8x34j_.bkp tag=TAG20160115T154538 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_3_c9k8x2pk_.arc RECID=156 STAMP=901208738
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
using channel ORA_DISK_1
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=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9k6o4tp_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T154540_c9k8x4lx_.bkp tag=TAG20160115T154540 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:05
Finished backup at 15-JAN-16

Starting backup at 15-JAN-16
current log archived
using channel ORA_DISK_1
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=4 RECID=157 STAMP=901208865
channel ORA_DISK_1: starting piece 1 at 15-JAN-16
channel ORA_DISK_1: finished piece 1 at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T154746_c9k9126o_.bkp tag=TAG20160115T154746 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_4_c9k911wp_.arc RECID=157 STAMP=901208865
Finished backup at 15-JAN-16

Starting Control File and SPFILE Autobackup at 15-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901208867_c9k913mg_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 15-JAN-16

SQL> show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      /u01/app/oracle/oradata/STONE/
                                                 controlfile/o1_mf_c06xh9fs_.ct
                                                 l, /u01/app/oracle/fast_recove
                                                 ry_area/STONE/controlfile/o1_m
                                                 f_c06xh9jx_.ctl, /home/oracle/
                                                 o1_mf_c06xh9fs_.ctl

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> !rm /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl

SQL> !rm /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl

SQL> !rm /home/oracle/o1_mf_c06xh9fs_.ctl

SQL> startup nomount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes

RMAN> restore controlfile from autobackup;

Starting restore at 15-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

recovery area destination: /u01/app/oracle/fast_recovery_area
database name (or database unique name) used for search: STONE
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901208867_c9k913mg_.bkp found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901208867_c9k913mg_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
output file name=/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
output file name=/home/oracle/o1_mf_c06xh9fs_.ctl
Finished restore at 15-JAN-16


RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3910       CRITICAL OPEN      15-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf' needs media recovery
3907       CRITICAL OPEN      15-JAN-16     Control file needs media recovery
3913       HIGH     OPEN      15-JAN-16     One or more non-system datafiles need media recovery

RMAN> advise failure;

Starting implicit crosscheck backup at 15-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=22 device type=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 15-JAN-16

Starting implicit crosscheck copy at 15-JAN-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 15-JAN-16

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901208867_c9k913mg_.bkp

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3910       CRITICAL OPEN      15-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf' needs media recovery
3907       CRITICAL OPEN      15-JAN-16     Control file needs media recovery
3913       HIGH     OPEN      15-JAN-16     One or more non-system datafiles need media recovery

analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If you have the correct version of the control file, then shutdown the database and replace the old control file
2. If you restored the wrong version of data file /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c06xczt5_.dbf, then replace it with the correct one
3. If you restored the wrong version of data file /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c06xczw8_.dbf, then replace it with the correct one
4. If you restored the wrong version of data file /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c06xczwc_.dbf, then replace it with the correct one
5. If you restored the wrong version of data file /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c06xczx2_.dbf, then replace it with the correct one
6. If you restored the wrong version of data file /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9g4h22q_.dbf, then replace it with the correct one
7. If you restored the wrong version of data file /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c8vd4mmy_.dbf, then replace it with the correct one

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Recover datafile 1; Recover datafile 2; Recover datafile 3; ...
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_117371079.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_117371079.hm

contents of repair script:
   ## recover datafile
   recover database;
   alter database open resetlogs;

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting recover at 15-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only

starting media recovery

archived log for thread 1 with sequence 5 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9k5f8t5_.log
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9k5f8t5_.log thread=1 sequence=5
media recovery complete, elapsed time: 00:00:01
Finished recover at 15-JAN-16

database opened
repair failure complete

归档模式下丢失非关键数据文件的恢复

在归档模式下,丢失的数据文件如果不属于SYSTEM或者UNDO表空间,则只会影响丢失文件中的对象。归档模式下可以恢复都最后一次提交的时间,数据不会丢失,不需要重新录入数据。

例子:归档模式下丢失非关键数据文件的恢复

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> !rm /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kcl36t_.dbf

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4:
'/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kcl36t_.dbf'
[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 15 17:50:53 2016

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

connected to target database: STONE (DBID=3001485737, not open)

RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      15-JAN-16     One or more non-system datafiles are missing

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      15-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kcl36t_.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore and recover datafile 4  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2813147558.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2813147558.hm

contents of repair script:
   ## restore and recover datafile
   restore datafile 4;
   recover datafile 4;
   sql 'alter database datafile 4 online';

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 15-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kcl36t_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T161747_c9kbsg13_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T161747_c9kbsg13_.bkp tag=TAG20160115T161747
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 15-JAN-16

Starting recover at 15-JAN-16
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T162003_c9kbxmkf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T162003_c9kbxmkf_.bkp tag=TAG20160115T162003
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9kj97ol_.arc thread=1 sequence=2
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9kj97ol_.arc RECID=170 STAMP=901216295
media recovery complete, elapsed time: 00:00:01
Finished recover at 15-JAN-16

sql statement: alter database datafile 4 online
repair failure complete

Do you want to open the database (enter YES or NO)? yes
database opened

归档模式下丢失关键数据文件的恢复

SYSTEM和UNDO表空间的数据文件为关键文件,关键数据文件需要在MOUNT状态下进行恢复。

例子:归档模式下丢失关键数据文件的恢复

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> !rm /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kcl35t_.dbf

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1:
'/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kcl35t_.dbf'
[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jan 15 18:00:48 2016

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

connected to target database: STONE (DBID=3001485737, not open)

RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
4328       CRITICAL OPEN      15-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kcl35t_.dbf' is missing

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
4328       CRITICAL OPEN      15-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kcl35t_.dbf' is missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kcl35t_.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore and recover datafile 1  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3894925211.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3894925211.hm

contents of repair script:
   ## restore and recover datafile
   restore datafile 1;
   recover datafile 1;
   sql 'alter database datafile 1 online';

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 15-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kcl35t_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T161747_c9kbsg13_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_nnndf_TAG20160115T161747_c9kbsg13_.bkp tag=TAG20160115T161747
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 15-JAN-16

Starting recover at 15-JAN-16
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T162003_c9kbxmkf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_15/o1_mf_annnn_TAG20160115T162003_c9kbxmkf_.bkp tag=TAG20160115T162003
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9kjx4gm_.arc thread=1 sequence=2
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_15/o1_mf_1_2_c9kjx4gm_.arc RECID=171 STAMP=901216932
media recovery complete, elapsed time: 00:00:01
Finished recover at 15-JAN-16

sql statement: alter database datafile 1 online
repair failure complete

Do you want to open the database (enter YES or NO)? yes
database opened

恢复镜像拷贝

可以使用RMAN对数据文件镜像拷贝应用增量备份,将镜像拷贝前滚到指定的时间点或者增量备份的SCN,这样就不需要每天对数据库进行完整镜像拷贝。对数据文件镜像拷贝应用增量备份还有以下好处:

  • 减少介质恢复的时间,只需要应用上次增量备份以来的归档日志。
  • 增量恢复后无需执行完整镜像拷贝。
RMAN> recover copy of database with tag 'daily_inc';
RMAN> backup incremental level 1 for recover of copy
2> with tag 'daily_inc' database;
RECOVERBACKUP
Day 1NothingCreate image copies
Day 2NothingCreate incremental level 1
Day 3 and onwardRecover copies based on incrementalCreate incremental level 1

通过执行上面命令,可以获得所有数据文件连续更新的镜像拷贝。

每天运行的情况如下:

第一天:RECOVER命令什么也不做,没有镜像拷贝需要恢复,BACKUP命令创建镜像拷贝。

第二天:RECOVER命令什么也不做,这是因为此时还没有增量备份。BACKUP命令创建增量备份。

第三天:RECOVER命令从增量备份应用改变到镜像拷贝。BACKUP命令创建另外的增量备份,用于第四天RECOVER镜像拷贝。

在执行这种备份策略时使用tag是非常重要的,用于连接增量备份和镜像拷贝。如果不使用tag,有可能会将不正确的增量备份应用到镜像拷贝。

例子:恢复镜像拷贝

RMAN> recover copy of database with tag '20160118';

Starting recover at 18-JAN-16
using channel ORA_DISK_1
no copy of datafile 1 found to recover
no copy of datafile 2 found to recover
no copy of datafile 3 found to recover
no copy of datafile 4 found to recover
no copy of datafile 5 found to recover
no copy of datafile 6 found to recover
no copy of datafile 7 found to recover
Finished recover at 18-JAN-16

RMAN> backup incremental level 1 for recover of copy with tag '20160118' database;

Starting backup at 18-JAN-16
using channel ORA_DISK_1
no parent backup or copy of datafile 1 found
no parent backup or copy of datafile 2 found
no parent backup or copy of datafile 5 found
no parent backup or copy of datafile 3 found
no parent backup or copy of datafile 7 found
no parent backup or copy of datafile 6 found
no parent backup or copy of datafile 4 found
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c9snq72l_.dbf tag=20160118 RECID=47 STAMP=901483036
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:56
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c9snryc5_.dbf tag=20160118 RECID=48 STAMP=901483079
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c9sntcfx_.dbf tag=20160118 RECID=49 STAMP=901483095
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c9snttol_.dbf tag=20160118 RECID=50 STAMP=901483101
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c9sntxsh_.dbf tag=20160118 RECID=51 STAMP=901483102
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_test_ind_c9sntyx9_.dbf tag=20160118 RECID=52 STAMP=901483103
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kj96dg_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c9snv01x_.dbf tag=20160118 RECID=53 STAMP=901483104
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 18-JAN-16

Starting Control File and SPFILE Autobackup at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_18/o1_mf_s_901483105_c9snv1jt_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-JAN-16

RMAN> recover copy of database with tag '20160118';

Starting recover at 18-JAN-16
using channel ORA_DISK_1
no copy of datafile 1 found to recover
no copy of datafile 2 found to recover
no copy of datafile 3 found to recover
no copy of datafile 4 found to recover
no copy of datafile 5 found to recover
no copy of datafile 6 found to recover
no copy of datafile 7 found to recover
Finished recover at 18-JAN-16

RMAN> backup incremental level 1 for recover of copy with tag '20160118' database;

Starting backup at 18-JAN-16
using channel ORA_DISK_1
no parent backup or copy of datafile 5 found
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kj96dg_.dbf
channel ORA_DISK_1: starting piece 1 at 18-JAN-16
channel ORA_DISK_1: finished piece 1 at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnnd1_20160118_c9so3rom_.bkp tag=20160118 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c9so3vtm_.dbf tag=20160118 RECID=54 STAMP=901483399
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
Finished backup at 18-JAN-16

Starting Control File and SPFILE Autobackup at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_18/o1_mf_s_901483402_c9so4c76_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-JAN-16

RMAN> recover copy of database with tag '20160118';

Starting recover at 18-JAN-16
using channel ORA_DISK_1
no copy of datafile 5 found to recover
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile copies to recover
recovering datafile copy file number=00001 name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c9snq72l_.dbf
recovering datafile copy file number=00002 name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c9snryc5_.dbf
recovering datafile copy file number=00003 name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c9snttol_.dbf
recovering datafile copy file number=00004 name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c9snv01x_.dbf
recovering datafile copy file number=00006 name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_test_ind_c9sntyx9_.dbf
recovering datafile copy file number=00007 name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c9sntxsh_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnnd1_20160118_c9so3rom_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnnd1_20160118_c9so3rom_.bkp tag=20160118
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished recover at 18-JAN-16

Starting Control File and SPFILE Autobackup at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_18/o1_mf_s_901483426_c9so52by_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-JAN-16

RMAN> backup incremental level 1 for recover of copy with tag '20160118' database;

Starting backup at 18-JAN-16
using channel ORA_DISK_1
no parent backup or copy of datafile 5 found
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kj96dg_.dbf
channel ORA_DISK_1: starting piece 1 at 18-JAN-16
channel ORA_DISK_1: finished piece 1 at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnnd1_20160118_c9so6fmj_.bkp tag=20160118 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
output file name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c9so6gnj_.dbf tag=20160118 RECID=61 STAMP=901483485
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
Finished backup at 18-JAN-16

Starting Control File and SPFILE Autobackup at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_18/o1_mf_s_901483485_c9so6xxt_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-JAN-16

使用镜像拷贝进行数据文件的快速恢复

可以使用镜像拷贝进行数据文件的快速恢复,步骤如下:

  1. 将数据文件OFFLINE。
  2. 使用SWITCH TO ... COPY命令指向数据文件的镜像拷贝。
  3. RECOVER数据文件。
  4. 将数据文件ONLINE

如果还想将数据文件放回原来的位置,执行以下步骤:

  1. 使用BACKUP AS COPY命令在原来的位置创建该数据文件的镜像拷贝。

  2. 将数据文件OFFLINE。

  3. 使用SWITCH TO COPY命令切换到步骤5创建的镜像拷贝。

  4. RECOVER数据文件。

  5. 将数据文件ONLINE。

可以使用这个命令来恢复数据文件,表空间,临时文件或者整个数据库。

例子:使用镜像拷贝进行数据文件的快速恢复

RMAN> list copy;

specification does not match any control file copy in the repository
specification does not match any archived log in the repository
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
58      1    A 18-JAN-16       3901980    18-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_system_c9snq72l_.dbf
        Tag: 20160118

60      2    A 18-JAN-16       3901980    18-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_sysaux_c9snryc5_.dbf
        Tag: 20160118

59      3    A 18-JAN-16       3901980    18-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_undotbs1_c9snttol_.dbf
        Tag: 20160118

57      4    A 18-JAN-16       3901980    18-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c9snv01x_.dbf
        Tag: 20160118

61      5    A 18-JAN-16       3618687    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c9so6gnj_.dbf
        Tag: 20160118

54      5    A 18-JAN-16       3618687    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c9so3vtm_.dbf
        Tag: 20160118

49      5    A 18-JAN-16       3618687    12-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_example_c9sntcfx_.dbf
        Tag: 20160118

56      6    A 18-JAN-16       3901980    18-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_test_ind_c9sntyx9_.dbf
        Tag: 20160118

55      7    A 18-JAN-16       3901980    18-JAN-16      
        Name: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_rcat_ts_c9sntxsh_.dbf
        Tag: 20160118

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ ----------------------------------------------------------------------
USERS                          /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kj96dg_.dbf
UNDOTBS1                       /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
SYSAUX                         /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
SYSTEM                         /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
TEST_INDEX                     /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
EXAMPLE                        /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
RCAT_TS                        /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf

7 rows selected.

删除数据文件
SQL> !rm /u01/app/oracle/oradata/STONE/datafile/o1_mf_users_c9kj96dg_.dbf

离线数据文件
SQL> alter database datafile 4 offline;

Database altered.

RMAN> switch datafile 4 to copy;

datafile 4 switched to datafile copy "/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c9snv01x_.dbf"

RMAN> recover datafile 4;

Starting recover at 18-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c9snv01x_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnnd1_20160118_c9so6fmj_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnnd1_20160118_c9so6fmj_.bkp tag=20160118
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 18-JAN-16

SQL> alter database datafile 4 online;

Database altered.

RMAN> backup as copy datafile 4 format '/u01/app/oracle/oradata/STONE/datafile/%U.dbf';

Starting backup at 18-JAN-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/fast_recovery_area/STONE/datafile/o1_mf_users_c9snv01x_.dbf
output file name=/u01/app/oracle/oradata/STONE/datafile/data_D-STONE_I-3001485737_TS-USERS_FNO-4_6hqrnagg.dbf tag=TAG20160118T221336 RECID=63 STAMP=901491216
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 18-JAN-16

Starting Control File and SPFILE Autobackup at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_18/o1_mf_s_901491217_c9swrkdw_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-JAN-16

RMAN> sql 'alter database datafile 4 offline';

sql statement: alter database datafile 4 offline

RMAN> switch datafile 4 to copy;

datafile 4 switched to datafile copy "/u01/app/oracle/oradata/STONE/datafile/data_D-STONE_I-3001485737_TS-USERS_FNO-4_6hqrnagg.dbf"

RMAN> recover datafile 4;

Starting recover at 18-JAN-16
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 18-JAN-16

RMAN> sql 'alter database datafile 4 online';

sql statement: alter database datafile 4 online

使用SET NEWNAME

SET NEWNAME命令只能用于RUN块中,对后续的操作进行名称映射。

RUN
{ ALLOCATE CHANNEL dev1 DEVICE TYPE DISK;
  ALLOCATE CHANNEL dev2 DEVICE TYPE sbt;
  SQL "ALTER TABLESPACE users OFFLINE IMMEDIATE";
  SET NEWNAME FOR DATAFILE '/disk1/oradata/prod/users01.dbf'
                        TO '/disk2/users01.dbf';
  RESTORE TABLESPACE users;
  SWITCH DATAFILE ALL;
  RECOVER TABLESPACE users;
  SQL "ALTER TABLESPACE users ONLINE";
}

上面的例子中,SET NEWNAME命令定义了对数据文件进行还原操作的位置。当执行RESTORE命令,users01.dbf数据文件还原到/disk2/users01.dbf。但是控制文件还没有指向该位置,故需要使用SWITCH命令使控制文件更新指向。

更有效率的方式是使用SET NEWNAME为所有的数据文件指定默认的命名格式,命令如下:

  • SET NEWNAME FOR DATAFILE和SET NEWNAME FOR TEMPFILE
  • SET NEWNAME FOR TABLESPACE
  • SET NEWNAME FOR DATABASE

例子:使用拷贝的数据文件进行恢复

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ ----------------------------------------------------------------------
USERS                          /home/oracle/users01.dbf
UNDOTBS1                       /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
SYSAUX                         /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
SYSTEM                         /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
TEST_INDEX                     /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
EXAMPLE                        /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
RCAT_TS                        /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf

7 rows selected.

SQL> !cp /home/oracle/users01.dbf /u01/app/oracle/oradata/STONE/datafile/user01.dbf

RMAN> run{
2> allocate channel dev1 device type disk;
3> sql 'alter tablespace users offline immediate';
4> set newname for datafile '/home/oracle/users01.dbf' to '/u01/app/oracle/oradata/STONE/datafile/user01.dbf';
5> restore tablespace users;
6> switch datafile all;
7> recover tablespace users;
8> sql 'alter tablespace users online';}

released channel: ORA_DISK_1
allocated channel: dev1
channel dev1: SID=18 device type=DISK

sql statement: alter tablespace users offline immediate

executing command: SET NEWNAME

Starting restore at 18-JAN-16

skipping datafile 4; already restored to file /u01/app/oracle/oradata/STONE/datafile/user01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 18-JAN-16

datafile 4 switched to datafile copy
input datafile copy RECID=76 STAMP=901492898 file name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf

Starting recover at 18-JAN-16

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 18-JAN-16

sql statement: alter tablespace users online
released channel: dev1

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ ----------------------------------------------------------------------
USERS                          /u01/app/oracle/oradata/STONE/datafile/user01.dbf
UNDOTBS1                       /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
SYSAUX                         /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
SYSTEM                         /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
TEST_INDEX                     /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
EXAMPLE                        /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
RCAT_TS                        /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf

7 rows selected.

非归档模式下执行还原和恢复

非归档模式下数据文件的丢失需要进行数据库的完全还原,包括控制文件和数据文件。如果有增量备份,需要进行还原和恢复。如果丢失的数据文件属于只读表空间,则只需要还原该数据文件即可。

非归档模式下,只能恢复到最后一次备份的时刻,之后的数据需要重新录入。

执行步骤如下:

  1. 关闭数据库。
  2. 从备份还原整个数据库。
  3. 打开数据库。

例子:非归档模式下的备份和恢复

SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     9
Current log sequence           11

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 18 22:53:46 2016

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

connected to target database: STONE (DBID=3001485737, not open)

RMAN> backup database;

Starting backup at 18-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
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=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: starting piece 1 at 18-JAN-16
channel ORA_DISK_1: finished piece 1 at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnndf_TAG20160118T225352_c9sz40ps_.bkp tag=TAG20160118T225352 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45
Finished backup at 18-JAN-16

Starting Control File and SPFILE Autobackup at 18-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_18/o1_mf_s_901493394_c9sz7b6s_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-JAN-16

[oracle@test ~]$ rm /u01/app/oracle/oradata/STONE/datafile/user01.dbf

SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/STONE/datafile/user01.dbf'

[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 18 23:06:15 2016

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

connected to target database: STONE (DBID=3001485737, not open)

RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      18-JAN-16     One or more non-system datafiles are missing

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      18-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/STONE/datafile/user01.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      NOARCHIVELOG mode restore datafile 4  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_595042389.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_595042389.hm

contents of repair script:
   ## NOARCHIVELOG mode restore datafile
   restore datafile 4;
   recover datafile 4;
   sql 'alter database datafile 4 online';

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 18-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnndf_TAG20160118T225352_c9sz40ps_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnndf_TAG20160118T225352_c9sz40ps_.bkp tag=TAG20160118T225352
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 18-JAN-16

Starting recover at 18-JAN-16
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 18-JAN-16

sql statement: alter database datafile 4 online
repair failure complete

Do you want to open the database (enter YES or NO)? yes
database opened


SQL> create table emp tablespace users as select * from hr.employees;

Table created.

SQL> alter system checkpoint;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

SQL> shutdown immediate;
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/u01/app/oracle/oradata/STONE/datafile/user01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL> shutdown abort
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/STONE/datafile/user01.dbf'

[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 18 23:14:12 2016

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

connected to target database: STONE (DBID=3001485737, not open)

RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      18-JAN-16     One or more non-system datafiles are missing

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      18-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/STONE/datafile/user01.dbf was unintentionally renamed or moved, restore it
2. If you have an export of tablespace USERS, offline its data files, open the database read/write, then drop and re-create the tablespace and import the data.

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore database and recover with UNTIL CANCEL option  
  Strategy: The repair includes recovery in NOARCHIVELOG mode with some data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2663793134.hm

RMAN> repair failure;

Strategy: The repair includes recovery in NOARCHIVELOG mode with some data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2663793134.hm

contents of repair script:
   ## database restore and recover until cancel
   restore database;
   recover database;
   alter database open resetlogs;

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 18-JAN-16
using channel ORA_DISK_1

skipping datafile 5; already restored to file /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnndf_TAG20160118T225352_c9sz40ps_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_18/o1_mf_nnndf_TAG20160118T225352_c9sz40ps_.bkp tag=TAG20160118T225352
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 18-JAN-16

Starting recover at 18-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only

starting media recovery

archived log for thread 1 with sequence 19 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_1_c9kcnv60_.log
archived log for thread 1 with sequence 20 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9kcnx8j_.log
archived log for thread 1 with sequence 21 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_3_c9kcnz1n_.log
RMAN-08187: WARNING: media recovery until SCN 3919717 complete
Finished recover at 18-JAN-16

database opened
repair failure complete

还原点

可以为某个时间点或者SCN指定一个名字作为还原点(Restore Point),用于Point-in-Time恢复或者闪回操作。

例子:为当前时间创建还原点

SQL> CREATE RESTORE POINT before_mods;

例子:为SCN等于100创建还原点

SQL> CREATE RESTORE POINT end_q1 AS OF SCN 100;

还原点最短保留时间由参数CONTROL_FILE_RECORD_KEEP_TIME控制,可以使用PRESERVE选项创建永久保留的还原点。

可以通过V$RESTORE_POINT视图查看还原点的名字,SCN,TIMESTAMP等信息。

例子:创建还原点

SQL> create restore point before_mods;

Restore point created.

SQL> create restore point end_q1 as of scn 3902076;

Restore point created.

SQL> select scn,time,name from v$restore_point;

       SCN TIME                                     NAME
---------- ---------------------------------------- --------------------
   3656190 12-JAN-16 10.06.47.000000000 PM          %RESTORE_POINT
   3902336 18-JAN-16 08.09.52.000000000 PM          BEFORE_MODS
   3902076 18-JAN-16 08.12.00.000000000 PM          END_Q1

SQL> drop restore point end_q1;

Restore point dropped.

SQL> select scn,time,name from v$restore_point;

       SCN TIME                                     NAME
---------- ---------------------------------------- --------------------
   3656190 12-JAN-16 10.06.47.000000000 PM          %RESTORE_POINT
   3902336 18-JAN-16 08.09.52.000000000 PM          BEFORE_MODS

基于时间点的恢复

执行Point-in-Time恢复必须在归档模式下,具体步骤如下:

  1. 指定还原目标,可以是时间、SCN、还原点或者日志序列号,如果在下午3点提交了错误的事务,则可以指定2:59作为还原点时间。

  2. 设置NLS操作系统环境变量,以便对提供的时间进行正确格式化,示例如下:

$export NLS_LANG=american_america.us7ascii
$export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss"
  1. 挂载数据库,如果数据库是打开的,需要先关闭:
RMAN>shutdown immediate
RMAN>startup mount
  1. 创建和运行RUN块,RECOVER和RESTORE命令需要位于同一个RUN块内,以便UNTIL设置应用到这两个命令。示例如下:
RUN{
SET UNTIL TIME '2007-08-14 21:59:00';
RESTORE DATABASE;
RECOVER DATABASE;
}
  1. 以只读模式打开数据库,检查数据确认是否恢复到指定的时间点:
RMAN>SQL 'ALTER DATABASE OPEN READ ONLY';
  1. 如果满足恢复要求,使用RESETLOGS选项打开数据库:
RMAN>ALTER DATABASE OPEN RESETLOGS;

例子:执行Point-in-Time恢复

RMAN> backup database plus archivelog delete input;


Starting backup at 19-JAN-16
current log archived
using channel ORA_DISK_1
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=201 STAMP=901527711
input archived log thread=1 sequence=2 RECID=202 STAMP=901527712
input archived log thread=1 sequence=3 RECID=203 STAMP=901527714
input archived log thread=1 sequence=4 RECID=204 STAMP=901527715
input archived log thread=1 sequence=5 RECID=205 STAMP=901527716
input archived log thread=1 sequence=6 RECID=206 STAMP=901527718
input archived log thread=1 sequence=7 RECID=207 STAMP=901527744
channel ORA_DISK_1: starting piece 1 at 19-JAN-16
channel ORA_DISK_1: finished piece 1 at 19-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_19/o1_mf_annnn_TAG20160119T082224_c9v0g130_.bkp tag=TAG20160119T082224 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_1_c9v0dz9s_.arc RECID=201 STAMP=901527711
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_2_c9v0f0b8_.arc RECID=202 STAMP=901527712
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_3_c9v0f2jz_.arc RECID=203 STAMP=901527714
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_4_c9v0f3fv_.arc RECID=204 STAMP=901527715
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_5_c9v0f4s0_.arc RECID=205 STAMP=901527716
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_6_c9v0f64w_.arc RECID=206 STAMP=901527718
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_7_c9v0g0po_.arc RECID=207 STAMP=901527744
Finished backup at 19-JAN-16

Starting backup at 19-JAN-16
using channel ORA_DISK_1
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=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: starting piece 1 at 19-JAN-16
channel ORA_DISK_1: finished piece 1 at 19-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_19/o1_mf_nnndf_TAG20160119T082226_c9v0g30w_.bkp tag=TAG20160119T082226 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:06
Finished backup at 19-JAN-16

Starting backup at 19-JAN-16
current log archived
using channel ORA_DISK_1
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=8 RECID=208 STAMP=901527872
channel ORA_DISK_1: starting piece 1 at 19-JAN-16
channel ORA_DISK_1: finished piece 1 at 19-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_19/o1_mf_annnn_TAG20160119T082432_c9v0l0mp_.bkp tag=TAG20160119T082432 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_19/o1_mf_1_8_c9v0l075_.arc RECID=208 STAMP=901527872
Finished backup at 19-JAN-16

Starting Control File and SPFILE Autobackup at 19-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_19/o1_mf_s_901527873_c9v0l1z3_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-JAN-16

SQL> create restore point rp20160119082559;

Restore point created.

SQL> select scn,time,name from v$restore_point;

       SCN TIME                                     NAME
---------- ---------------------------------------- --------------------
   3656190 12-JAN-16 10.06.47.000000000 PM          %RESTORE_POINT
   3902336 18-JAN-16 08.09.52.000000000 PM          BEFORE_MODS
   3922886 19-JAN-16 08.26.12.000000000 AM          RP20160119082559

SQL> select count(*) from emp;

  COUNT(*)
----------
       107

SQL> delete from emp;

107 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from emp;

  COUNT(*)
----------
         0

RMAN> shutdown immediate

database closed
database dismounted
Oracle instance shut down

RMAN> startup mount

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     835104768 bytes

Fixed Size                     2257840 bytes
Variable Size                507513936 bytes
Database Buffers             322961408 bytes
Redo Buffers                   2371584 bytes

RMAN> run{
2> set until time "to_date('2016-01-19 08:26:12','yyyy-mm-dd hh24:mi:ss')";
3> restore database;
4> recover database;}

executing command: SET until clause

Starting restore at 19-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK

skipping datafile 5; already restored to file /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_19/o1_mf_nnndf_TAG20160119T082226_c9v0g30w_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_19/o1_mf_nnndf_TAG20160119T082226_c9v0g30w_.bkp tag=TAG20160119T082226
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 19-JAN-16

Starting recover at 19-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 19-JAN-16


RMAN> alter database open resetlogs;

database opened

SQL> select count(*) from emp;

  COUNT(*)
----------
       107

使用备份的控制文件执行恢复

如果丢失了所有的控制文件,可以使用备份的控制文件进行恢复,然后执行RECOVER命令,使用RESETLOGS选项打开数据库。

例子:丢失单个控制文件的恢复

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
/home/oracle/o1_mf_c06xh9fs_.ctl

SQL> !rm /home/oracle/o1_mf_c06xh9fs_.ctl

SQL> shutdown immediate
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/home/oracle/o1_mf_c06xh9fs_.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL> shutdown abort
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
ORA-00205: error in identifying control file, check alert log for more info
[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Jan 19 22:26:39 2016

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

connected to target database: STONE (not mounted)

RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
5930       CRITICAL OPEN      19-JAN-16     Control file /home/oracle/o1_mf_c06xh9fs_.ctl is missing

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
5930       CRITICAL OPEN      19-JAN-16     Control file /home/oracle/o1_mf_c06xh9fs_.ctl is missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
no manual actions available

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Use a multiplexed copy to restore control file /home/oracle/o1_mf_c06xh9fs_.ctl  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2365519798.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2365519798.hm

contents of repair script:
   ## restore control file using multiplexed copy
   restore controlfile from '/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl';
   sql 'alter database mount';

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 19-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: copied control file copy
output file name=/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
output file name=/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
output file name=/home/oracle/o1_mf_c06xh9fs_.ctl
Finished restore at 19-JAN-16

sql statement: alter database mount
released channel: ORA_DISK_1
repair failure complete

Do you want to open the database (enter YES or NO)? yes
database opened

从自动备份中还原控制文件

如果没有使用恢复目录,则应该配置控制文件自动备份。如果使用了快速恢复区,RMAN会隐式对控制文件列出的备份和镜像拷贝进行交叉检查,将没有记录到控制文件中的快速恢复区文件记录到控制文件。

RMAN> STARTUP NOMOUNT;
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;
RMAN> ALTER DATABASE MOUNT;
RMAN> RECOVER DATABASE;
RMAN> ALTER DATABASE OPEN RESETLOGS;

使用上面的命令进行恢复。首先启动数据库到NOMOUNT状态,从备份中还原控制文件,然后MOUNT数据库,由于还原的控制文件是以前的一个版本,故需要RECOVER数据库。同时由于新的控制文件表示一个不同的数据库实例,故需要使用RESETLOGS选项打开数据库。

从自动备份中还原控制文件,数据库必须处于NOMOUNT状态,如果自动备份不位于快速恢复区,则必须在执行RESTORE命令前先设置DBID,示例如下:

RMAN> SHUTDOWN ABORT;
RMAN> STARTUP NOMOUNT;
RMAN> SET DBID 1090770270;
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;

RMAN从自动备份中搜索控制文件,如果找到,则还原到参数文件中CONTROL_FILES指定的所有位置。

如果使用了恢复目录,则不需要设置DBID或者使用控制文件自动备份还原控制文件,直接使用RESTORE CONTROLFILE命令即可:

RMAN> RESTORE CONTROLFILE;

使用RESTORE CONTROLFILE ... TO <destination>命令将控制文件还原到非默认位置。

丢失参数文件的恢复

恢复参数文件最简单的方式是使用FROM MEMORY语句对当前系统参数配置创建PFILE或者SPFILE。

在实例启动过程中,所有参数配置都会被写入到alert.log文件,可以复制出来作为参数文件。

SQL> create pfile='/home/oracle/pfile.ora' from spfile;

File created.

SQL> create pfile='/home/oracle/pfile1.ora' from memory;

File created.

SQL> create spfile='/home/oracle/spfile.ora' from pfile='/home/oracle/pfile.ora';

File created.

SQL> create spfile='/home/oracle/spfile1.ora' from memory;

File created.

如果丢失了服务器参数文件且无法使用FROM MEMORY语句,与还原控制文件类似,可以从自动备份中还原。如果备份不在快速恢复区,需要设置DBID。使用命令RESTORE SPFILE FROM AUTOBACKUP

如果要还原SPFILE到非默认位置,使用如下命令:

RESTORE SPFILE TO <file_name> FROM AUTOBACKUP

如果从快速恢复区还原服务器参数文件,使用如下命令:

RMAN> run {
2> restore spfile from autobackup
3> recovery area = '<*flash recovery area destination*>'
4> db_name = '<*db_name*>';
5> }

例子:还原服务器参数文件

[oracle@test ~]$ mv /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilestone.ora /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilestone1.ora

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initstone.ora'

[oracle@test ~]$ vim /u01/app/oracle/product/11.2.0/dbhome_1/dbs/init.ora
#
## NOTE: The values that are used in this file are only intended to be used
## as a starting point. You may want to adjust/tune those values to your
## specific hardware and needs. You may also consider using Database
## Configuration Assistant tool (DBCA) to create INIT file and to size your
## initial set of tablespaces based on the user input.
###############################################################################

## Change '<ORACLE_BASE>' to point to the oracle base (the one you specify at
## install time)

db_name='STONE'
#memory_target=1G
processes = 150
audit_file_dest='/u01/app/oracle/admin/stone/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
## You may want to ensure that control files are created on separate physical

SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/init.ora'
ORACLE instance started.

Total System Global Area  221331456 bytes
Fixed Size                  2251856 bytes
Variable Size             163578800 bytes
Database Buffers           50331648 bytes
Redo Buffers                5169152 bytes

[oracle@test ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jan 20 08:22:40 2016

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

connected to target database: STONE (not mounted)

RMAN> restore spfile from autobackup;

Starting restore at 20-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

recovery area destination: /u01/app/oracle/fast_recovery_area
database name (or database unique name) used for search: STONE
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_19/o1_mf_s_901579118_c9wlmh11_.bkp found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_19/o1_mf_s_901579118_c9wlmh11_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 20-JAN-16

[oracle@test ~]$ ls /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilestone.ora 
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilestone.ora

SQL> startup force
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
Database opened.

非归档模式下使用增量备份恢复数据库

在非归档模式下可以使用连续的增量备份进行恢复。如果联机重做日志文件丢失或者不能应用于增量备份,则RECOVER DATABASE命令需要使用NOREDO选项。如果当前的联机重做日志文件包含了增量备份之后的所有改变,则可以不使用NOREDO选项。

例子:非归档模式下使用增量备份恢复数据库

SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Current log sequence           2

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.
进行0级备份
RMAN> backup incremental level 0 database;

Starting backup at 20-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: starting piece 1 at 20-JAN-16
channel ORA_DISK_1: finished piece 1 at 20-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_20/o1_mf_nnnd0_TAG20160120T192701_c9yvr5r3_.bkp tag=TAG20160120T192701 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:05
Finished backup at 20-JAN-16

Starting Control File and SPFILE Autobackup at 20-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_20/o1_mf_s_901654001_c9yvw36r_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 20-JAN-16

SQL> alter database open;

Database altered.

SQL> select count(*) from emp;

  COUNT(*)
----------
       107

SQL> insert into emp select * from emp;

107 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from emp;

  COUNT(*)
----------
       214

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
Database mounted.

进行1级备份
RMAN> backup incremental level 1 database;

Starting backup at 20-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
skipping datafile 00005 because it has not changed
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: starting piece 1 at 20-JAN-16
channel ORA_DISK_1: finished piece 1 at 20-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_20/o1_mf_nnnd1_TAG20160120T193707_c9ywc3n5_.bkp tag=TAG20160120T193707 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 20-JAN-16

Starting Control File and SPFILE Autobackup at 20-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_20/o1_mf_s_901654580_c9ywc6xx_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 20-JAN-16

删除所有的数据文件和控制文件
[oracle@test ~]$ ls /u01/app/oracle/oradata/STONE/datafile/
o1_mf_example_c9kcl362_.dbf  o1_mf_sysaux_c9kcl360_.dbf  o1_mf_temp_c9kco30z_.tmp      o1_mf_undotbs1_c9kcl368_.dbf
o1_mf_rcat_ts_c9kcl36f_.dbf  o1_mf_system_c9kjvdr4_.dbf  o1_mf_test_ind_c9kcl36o_.dbf  user01.dbf
[oracle@test ~]$ rm /u01/app/oracle/oradata/STONE/datafile/*
[oracle@test ~]$ rm /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
[oracle@test ~]$ rm /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl 
[oracle@test ~]$ rm /home/oracle/o1_mf_c06xh9fs_.ctl 

SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             507513936 bytes
Database Buffers          322961408 bytes
Redo Buffers                2371584 bytes
ORA-00205: error in identifying control file, check alert log for more info

恢复控制文件
RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
6487       CRITICAL OPEN      20-JAN-16     Control file /home/oracle/o1_mf_c06xh9fs_.ctl is missing
6484       CRITICAL OPEN      20-JAN-16     Control file /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl is missing
6481       CRITICAL OPEN      20-JAN-16     Control file /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl is missing
6441       CRITICAL OPEN      20-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf' is missing
3282       HIGH     OPEN      20-JAN-16     One or more non-system datafiles are missing

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
6487       CRITICAL OPEN      20-JAN-16     Control file /home/oracle/o1_mf_c06xh9fs_.ctl is missing
6484       CRITICAL OPEN      20-JAN-16     Control file /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl is missing
6481       CRITICAL OPEN      20-JAN-16     Control file /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl is missing
6441       CRITICAL OPEN      20-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf' is missing
3282       HIGH     OPEN      20-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete

Not all specified failures can currently be repaired.
The following failures must be repaired before advise for others can be given.

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
6487       CRITICAL OPEN      20-JAN-16     Control file /home/oracle/o1_mf_c06xh9fs_.ctl is missing
6484       CRITICAL OPEN      20-JAN-16     Control file /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl is missing
6481       CRITICAL OPEN      20-JAN-16     Control file /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl is missing

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /home/oracle/o1_mf_c06xh9fs_.ctl was unintentionally renamed or moved, restore it
2. If file /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl was unintentionally renamed or moved, restore it
3. If file /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl was unintentionally renamed or moved, restore it
4. If this is a primary database and a standby database is available, then perform a Data Guard failover initiated from the standby

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore a backup control file  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3607448101.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3607448101.hm

contents of repair script:
   ## restore control file
   restore controlfile from autobackup;
   sql 'alter database mount';

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 20-JAN-16
using channel ORA_DISK_1

recovery area destination: /u01/app/oracle/fast_recovery_area
database name (or database unique name) used for search: STONE
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_20/o1_mf_s_901654580_c9ywc6xx_.bkp found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_20/o1_mf_s_901654580_c9ywc6xx_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
output file name=/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
output file name=/home/oracle/o1_mf_c06xh9fs_.ctl
Finished restore at 20-JAN-16

sql statement: alter database mount
released channel: ORA_DISK_1
repair failure complete

还原和恢复数据文件
RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
6552       CRITICAL OPEN      20-JAN-16     Control file needs media recovery
6441       CRITICAL OPEN      20-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf' is missing
3282       HIGH     OPEN      20-JAN-16     One or more non-system datafiles are missing

RMAN> advise failure;

Starting implicit crosscheck backup at 20-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 20-JAN-16

Starting implicit crosscheck copy at 20-JAN-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 20-JAN-16

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_20/o1_mf_s_901654580_c9ywc6xx_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901208867_c9k913mg_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901210804_c9kbxnqb_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_19/o1_mf_s_901577753_c9wk8sbv_.bkp

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
6552       CRITICAL OPEN      20-JAN-16     Control file needs media recovery
6441       CRITICAL OPEN      20-JAN-16     System datafile 1: '/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf' is missing
3282       HIGH     OPEN      20-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If you have the correct version of the control file, then shutdown the database and replace the old control file
2. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf was unintentionally renamed or moved, restore it
3. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf was unintentionally renamed or moved, restore it
4. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf was unintentionally renamed or moved, restore it
5. If file /u01/app/oracle/oradata/STONE/datafile/user01.dbf was unintentionally renamed or moved, restore it
6. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf was unintentionally renamed or moved, restore it
7. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf was unintentionally renamed or moved, restore it
8. If file /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore database and recover with UNTIL CANCEL option  
  Strategy: The repair includes recovery in NOARCHIVELOG mode with some data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_1738708433.hm

RMAN> repair failure;

Strategy: The repair includes recovery in NOARCHIVELOG mode with some data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_1738708433.hm

contents of repair script:
   ## database restore and recover until cancel
   restore database;
   recover database;
   alter database open resetlogs;

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 20-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9kjvdr4_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9kcl360_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9kcl368_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9kcl362_.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9kcl36o_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9kcl36f_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_20/o1_mf_nnnd0_TAG20160120T192701_c9yvr5r3_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_20/o1_mf_nnnd0_TAG20160120T192701_c9yvr5r3_.bkp tag=TAG20160120T192701
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 20-JAN-16

Starting recover at 20-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9ywwthp_.dbf
destination for restore of datafile 00002: /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9ywwthy_.dbf
destination for restore of datafile 00003: /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9ywwtjb_.dbf
destination for restore of datafile 00004: /u01/app/oracle/oradata/STONE/datafile/user01.dbf
destination for restore of datafile 00006: /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9ywwtjx_.dbf
destination for restore of datafile 00007: /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9ywwtjk_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_20/o1_mf_nnnd1_TAG20160120T193707_c9ywc3n5_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_20/o1_mf_nnnd1_TAG20160120T193707_c9ywc3n5_.bkp tag=TAG20160120T193707
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

starting media recovery

archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9wk8m56_.log
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/onlinelog/o1_mf_2_c9wk8m56_.log thread=1 sequence=2
media recovery complete, elapsed time: 00:00:00
Finished recover at 20-JAN-16

database opened
repair failure complete

SQL> select count(*) from emp;

  COUNT(*)
----------
       214

还原和恢复数据库到异机

还原和恢复数据库到异机需要保持DBID一致,故不要把这两个数据库到注册到同一恢复目录。

可以使用RMAN的DUPLICATE命令创建一个复制的数据库,带有不同的DBID,可以注册到同一个恢复目录。

还原数据库到异机执行以下准备步骤:

  • 记录源数据库的DBID。
  • 复制源数据库的初始化参数到异机。
  • 确保异机可以访问源数据库的备份,包括控制文件的自动备份

还原数据库到异机的步骤:

  1. 设置ORACLE_SID环境变量:
$ setenv ORACLE_SID orcl
  1. 启动RMAN,不要连接到恢复目录:
$ rman target /
  1. 设置DBID:
RMAN> SET DBID 1090770270;
  1. 启动到NOMOUNT:
RMAN> STARTUP NOMOUNT

如果服务器参数文件不存在,则会出现如下报错:

startup failed: ORA-01078: failure in processing system parameters

RMAN使用模版参数文件启动实例。

  1. 从备份集中还原服务器参数文件:
RESTORE SPFILE TO PFILE '?/oradata/test/initorcl.ora' FROM AUTOBACKUP;
  1. 关闭实例:
SHUTDOWN IMMEDIATE;
  1. 根据异机的实际目录结构编辑PFILE。

  2. 使用PFILE启动实例到NOMOUNT:

RMAN> STARTUP NOMOUNT 
  > PFILE='?/oradata/test/initorcl.ora';
  1. 创建RUN块,从自动备份中还原控制文件并MOUNT数据库:
RUN
{
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
}
  1. 查询V$DATAFILE获取控制文件中记录的数据文件名称,创建RMAN恢复脚本还原和恢复数据库,包括:

    • 如果异机与源主机的目录结构不一致,需要使用SET NEWNAME为数据文件指定路径。

    • 使用SQL语句ALTER DATABASE RENMAE FILE命令指定联机重做日志文件路径。

    • 使用SET UNTIL命令指定恢复到归档日志结束。

    • 使用SWITCH命令让控制文件识别到数据文件新的路径及文件名。

例子:

RUN
{
SET NEWNAME FOR DATAFILE 1 TO '?/oradata/test/system01.dbf';
SET NEWNAME FOR DATAFILE 2 TO '?/oradata/test/undotbs01.dbf';
SET NEWNAME FOR DATAFILE 3 TO '?/oradata/test/sysaux.dbf';
SET NEWNAME FOR DATAFILE 4 TO '?/oradata/test/users01.dbf';
SET NEWNAME FOR DATAFILE 5 TO '?/oradata/test/example01.dbf';
SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/orcl/redo01.log''
TO ''?/oradata/test/redo01.log'' ";
SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/orcl/redo02.log''
TO ''?/oradata/test/redo02.log'' ";
SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/orcl/redo03.log''
TO ''?/oradata/test/redo03.log'' ";
SET UNTIL SCN 4545727;
RESTORE DATABASE;
SWITCH DATAFILE ALL;
RECOVER DATABASE;
}
  1. 执行脚本

  2. 使用RESETLOGS选项打开数据库。

RMAN> ALTER DATABASE OPEN RESETLOGS;

例子:还原数据库到异机

源数据库进行备份:
RMAN> backup incremental level 1 database plus archivelog delete input;


Starting backup at 21-JAN-16
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 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=226 STAMP=901723670
channel ORA_DISK_1: starting piece 1 at 21-JAN-16
channel ORA_DISK_1: finished piece 1 at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144750_cb0zrpom_.bkp tag=TAG20160121T144750 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_21/o1_mf_1_1_cb0zrohv_.arc RECID=226 STAMP=901723670
Finished backup at 21-JAN-16

Starting backup at 21-JAN-16
using channel ORA_DISK_1
no parent backup or copy of datafile 1 found
no parent backup or copy of datafile 2 found
no parent backup or copy of datafile 5 found
no parent backup or copy of datafile 3 found
no parent backup or copy of datafile 4 found
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9ywwthp_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9ywwthy_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9ywwtj3_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9ywwtjb_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: starting piece 1 at 21-JAN-16
channel ORA_DISK_1: finished piece 1 at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T144751_cb0zrrmr_.bkp tag=TAG20160121T144751 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9ywwtjk_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9ywwtjx_.dbf
channel ORA_DISK_1: starting piece 1 at 21-JAN-16
channel ORA_DISK_1: finished piece 1 at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd1_TAG20160121T144751_cb0zvqlf_.bkp tag=TAG20160121T144751 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 21-JAN-16

Starting backup at 21-JAN-16
current log archived
using channel ORA_DISK_1
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=2 RECID=227 STAMP=901723768
channel ORA_DISK_1: starting piece 1 at 21-JAN-16
channel ORA_DISK_1: finished piece 1 at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144928_cb0zvrsv_.bkp tag=TAG20160121T144928 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_21/o1_mf_1_2_cb0zvrod_.arc RECID=227 STAMP=901723768
Finished backup at 21-JAN-16

Starting Control File and SPFILE Autobackup at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 21-JAN-16

RMAN> list backup;


List of Backup Sets
===================


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
134     20.16M     DISK        00:00:01     21-JAN-16      
        BP Key: 145   Status: AVAILABLE  Compressed: NO  Tag: TAG20160121T144750
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144750_cb0zrpom_.bkp

  List of Archived Logs in backup set 134
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    1       3979524    20-JAN-16 3999597    21-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
135     Incr 0  1.44G      DISK        00:01:34     21-JAN-16      
        BP Key: 146   Status: AVAILABLE  Compressed: NO  Tag: TAG20160121T144751
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T144751_cb0zrrmr_.bkp
  List of Datafiles in backup set 135
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    0  Incr 3999608    21-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9ywwthp_.dbf
  2    0  Incr 3999608    21-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9ywwthy_.dbf
  3    0  Incr 3999608    21-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9ywwtjb_.dbf
  4    0  Incr 3999608    21-JAN-16 /u01/app/oracle/oradata/STONE/datafile/user01.dbf
  5    0  Incr 3618687    12-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9ywwtj3_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
136     Incr 1  21.01M     DISK        00:00:01     21-JAN-16      
        BP Key: 147   Status: AVAILABLE  Compressed: NO  Tag: TAG20160121T144751
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd1_TAG20160121T144751_cb0zvqlf_.bkp
  List of Datafiles in backup set 136
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  6    1  Incr 3999680    21-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9ywwtjx_.dbf
  7    1  Incr 3999680    21-JAN-16 /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9ywwtjk_.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
137     27.00K     DISK        00:00:00     21-JAN-16      
        BP Key: 148   Status: AVAILABLE  Compressed: NO  Tag: TAG20160121T144928
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144928_cb0zvrsv_.bkp

  List of Archived Logs in backup set 137
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    2       3999597    21-JAN-16 3999686    21-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
138     Full    9.58M      DISK        00:00:01     21-JAN-16      
        BP Key: 149   Status: AVAILABLE  Compressed: NO  Tag: TAG20160121T144929
        Piece Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp
  SPFILE Included: Modification time: 21-JAN-16
  SPFILE db_unique_name: STONE
  Control File Included: Ckp SCN: 3999697      Ckp time: 21-JAN-16

在异机上面安装相同版本的数据库,目录结构保持与源主机一致,但不要创建数据库。
同时根据源主机备份目录,在异机上面创建对应的目录,这样就不需要进行目录转换了。
[oracle@rmanrec ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/
[oracle@rmanrec ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/

拷贝备份文件和参数文件到异机
[oracle@rmanrec ~]$ scp oracle@192.168.230.138:/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/* /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/
The authenticity of host '192.168.230.138 (192.168.230.138)' can't be established.
RSA key fingerprint is 4d:57:54:66:9c:ee:ec:65:15:ae:ee:a4:93:68:f1:b4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.230.138' (RSA) to the list of known hosts.
reverse mapping checking getaddrinfo for bogon [192.168.230.138] failed - POSSIBLE BREAK-IN ATTEMPT!
oracle@192.168.230.138's password: 
Permission denied, please try again.
oracle@192.168.230.138's password: 
o1_mf_annnn_TAG20160121T144750_cb0zrpom_.bkp                                                  100%   20MB  20.2MB/s   00:00    
o1_mf_annnn_TAG20160121T144928_cb0zvrsv_.bkp                                                  100%   28KB  27.5KB/s   00:00    
o1_mf_nnnd0_TAG20160121T144751_cb0zrrmr_.bkp                                                  100% 1478MB  26.9MB/s   00:55    
o1_mf_nnnd1_TAG20160121T144751_cb0zvqlf_.bkp                                                  100%   21MB  21.0MB/s   00:00    
[oracle@rmanrec ~]$ scp oracle@192.168.230.138:/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/* /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/
reverse mapping checking getaddrinfo for bogon [192.168.230.138] failed - POSSIBLE BREAK-IN ATTEMPT!
oracle@192.168.230.138's password: 
o1_mf_s_901723769_cb0zvt13_.bkp                                                               100% 9824KB   9.6MB/s   00:00

[oracle@rmanrec ~]$ scp oracle@192.168.230.138:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilestone.ora /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
reverse mapping checking getaddrinfo for bogon [192.168.230.138] failed - POSSIBLE BREAK-IN ATTEMPT!
oracle@192.168.230.138's password: 
spfilestone.ora                                                                               100% 3584     3.5KB/s   00:00  

根据源主机参数文件相关参数创建目录:
[oracle@rmanrec database]$ mkdir -p /u01/app/oracle/admin/stone/adump
[oracle@rmanrec database]$ mkdir -p /u01/app/oracle/oradata/STONE/controlfile/
[oracle@rmanrec database]$ mkdir -p /u01/app/oracle/fast_recovery_area/STONE/controlfile/

[oracle@rmanrec ~]$ echo $ORACLE_SID
stone
[oracle@rmanrec ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 21 16:13:37 2016

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

connected to target database (not started)

RMAN> set DBID=3001485737

executing command: SET DBID

RMAN> startup nomount

Oracle instance started

Total System Global Area     835104768 bytes

Fixed Size                     2257840 bytes
Variable Size                507513936 bytes
Database Buffers             322961408 bytes
Redo Buffers                   2371584 bytes

RMAN> run{
2> restore controlfile from autobackup;
3> alter database mount;}

Starting restore at 21-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

recovery area destination: /u01/app/oracle/fast_recovery_area
database name (or database unique name) used for search: STONE
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160121
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
output file name=/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
output file name=/home/oracle/o1_mf_c06xh9fs_.ctl
Finished restore at 21-JAN-16

database mounted
released channel: ORA_DISK_1

RMAN> run{             
2> restore database;
3> recover database;}

Starting restore at 21-JAN-16
Starting implicit crosscheck backup at 21-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 21-JAN-16

Starting implicit crosscheck copy at 21-JAN-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 21-JAN-16

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9ywwthp_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9ywwthy_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9ywwtjb_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9ywwtj3_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T144751_cb0zrrmr_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T144751_cb0zrrmr_.bkp tag=TAG20160121T144751
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:49
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9ywwtjx_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9ywwtjk_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd1_TAG20160121T144751_cb0zvqlf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd1_TAG20160121T144751_cb0zvqlf_.bkp tag=TAG20160121T144751
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 21-JAN-16

Starting recover at 21-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144928_cb0zvrsv_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144928_cb0zvrsv_.bkp tag=TAG20160121T144928
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_21/o1_mf_1_2_cb15khhp_.arc thread=1 sequence=2
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_21/o1_mf_1_2_cb15khhp_.arc RECID=228 STAMP=901729583
unable to find archived log
archived log thread=1 sequence=3
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/21/2016 16:26:24
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 3 and starting SCN of 3999686

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 01/21/2016 16:31:49
ORA-19751: could not create the change tracking file
ORA-19750: change tracking file: '/u01/app/oracle/oradata/STONE/changetracking/o1_mf_c98v5ocs_.chg'
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

[oracle@rmanrec database]$ mkdir -p /u01/app/oracle/oradata/STONE/changetracking/

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 01/21/2016 16:32:53
ORA-01139: RESETLOGS option only valid after an incomplete database recovery

RMAN> alter database open;

database opened

灾难恢复

灾难恢复是指丢失了整个数据库,包括恢复目录,所有控制文件,所有联机重做日志文件以及所有参数文件,然后对其进行恢复。

进行灾难恢复,至少要求如下备份:

  • 数据文件备份
  • 备份之后产生的归档日志文件
  • 至少一个控制文件自动备份

步骤如下:

  • 从自动备份还原服务器参数文件
  • 启动数据库实例
  • 从自动备份还原控制文件
  • MOUNT数据库
  • RESTORE数据文件
  • RECOVER数据文件
  • 使用RESETLOGS选项打开数据库

例子:灾难恢复

删除控制文件,联机重做日志文件,参数文件以及数据文件
[oracle@test ~]$ rm /u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
[oracle@test ~]$ rm /u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
[oracle@test ~]$ rm /home/oracle/o1_mf_c06xh9fs_.ctl
[oracle@test ~]$ rm /u01/app/oracle/oradata/STONE/onlinelog/*
[oracle@test ~]$ rm /u01/app/oracle/fast_recovery_area/STONE/onlinelog/*
[oracle@test ~]$ rm /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilestone.ora
[oracle@test ~]$ rm /u01/app/oracle/oradata/STONE/datafile/*

SQL> shutdown immediate
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL> shutdown abort
ORACLE instance shut down.
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initstone.ora'

RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initstone.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                281019272 bytes
Database Buffers             780140544 bytes
Redo Buffers                   5517312 bytes


RMAN> set DBID=3001485737

executing command: SET DBID

RMAN> restore spfile from '/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp';

Starting restore at 21-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 21-JAN-16

RMAN> shutdown immediate;

Oracle instance shut down

RMAN> startup nomount;

connected to target database (not started)
Oracle instance started

Total System Global Area     835104768 bytes

Fixed Size                     2257840 bytes
Variable Size                507513936 bytes
Database Buffers             322961408 bytes
Redo Buffers                   2371584 bytes

RMAN> restore controlfile from autobackup;

Starting restore at 21-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

recovery area destination: /u01/app/oracle/fast_recovery_area
database name (or database unique name) used for search: STONE
channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160121
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/app/oracle/oradata/STONE/controlfile/o1_mf_c06xh9fs_.ctl
output file name=/u01/app/oracle/fast_recovery_area/STONE/controlfile/o1_mf_c06xh9jx_.ctl
output file name=/home/oracle/o1_mf_c06xh9fs_.ctl
Finished restore at 21-JAN-16


RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 21-JAN-16
Starting implicit crosscheck backup at 21-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 21-JAN-16

Starting implicit crosscheck copy at 21-JAN-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 21-JAN-16

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_20/o1_mf_s_901654580_c9ywc6xx_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901208867_c9k913mg_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_15/o1_mf_s_901210804_c9kbxnqb_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901723769_cb0zvt13_.bkp
File Name: /u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_19/o1_mf_s_901577753_c9wk8sbv_.bkp

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_c9ywwthp_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_c9ywwthy_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_c9ywwtjb_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_c9ywwtj3_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T144751_cb0zrrmr_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T144751_cb0zrrmr_.bkp tag=TAG20160121T144751
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:16
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_c9ywwtjx_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_c9ywwtjk_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd1_TAG20160121T144751_cb0zvqlf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd1_TAG20160121T144751_cb0zvqlf_.bkp tag=TAG20160121T144751
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 21-JAN-16

RMAN> recover database;

Starting recover at 21-JAN-16
using channel ORA_DISK_1
datafile 5 not processed because file is read-only

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144928_cb0zvrsv_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_annnn_TAG20160121T144928_cb0zvrsv_.bkp tag=TAG20160121T144928
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_21/o1_mf_1_2_cb1797w5_.arc thread=1 sequence=2
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_21/o1_mf_1_2_cb1797w5_.arc RECID=228 STAMP=901731367
unable to find archived log
archived log thread=1 sequence=3
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/21/2016 16:56:09
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 3 and starting SCN of 3999686

RMAN> alter database open resetlogs;

database opened

Monitoring and Tuning

并行

可以在CONFIGURE命令中设置PARALLELISM选项配置并行备份,也可以手工分配多个通道进行并行备份,指定文件到特定的通道。

RMAN> RUN {
 2>  ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
 3>  ALLOCATE CHANNEL c2 DEVICE TYPE sbt;
 4>  ALLOCATE CHANNEL c3 DEVICE TYPE sbt;
 5>  BACKUP
 6>  INCREMENTAL LEVEL = 0
 7>  (DATAFILE 1,4,5 CHANNEL c1)
 8>  (DATAFILE 2,3,9 CHANNEL c2)
 9>  (DATAFILE 6,7,8 CHANNEL c3);
10>  SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
11> }

当备份数据文件,可以指定数据文件名称或者数据文件编号,例如:

BACKUP DEVICE TYPE sbt DATAFILE '/home/oracle/system01.dbf';
BACKUP DEVICE TYPE sbt DATAFILE 1;

当分配多个通道创建多个备份集时,RMAN自动并行写入到备份集。

例子:并行备份,指定文件使用某个通道

RMAN> report schema;

using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name STONE

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    910      SYSTEM               ***     /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_cb1769f2_.dbf
2    890      SYSAUX               ***     /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_cb1769f6_.dbf
3    115      UNDOTBS1             ***     /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_cb1769ff_.dbf
4    7        USERS                ***     /u01/app/oracle/oradata/STONE/datafile/user01.dbf
5    346      EXAMPLE              ***     /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_cb1769f9_.dbf
6    10       TEST_INDEX           ***     /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_cb178or2_.dbf
7    15       RCAT_TS              ***     /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_cb178oqs_.dbf


RMAN> run{
2> allocate channel c1 device type disk;
3> allocate channel c2 device type disk;
4> allocate channel c3 device type disk;
5> backup
6> incremental level=0
7> (datafile 1 channel c1)
8> (datafile 2 channel c2)
9> (datafile 3,4,5,6,7 channel c3);
10> sql 'alter system archive log current';}

released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=19 device type=DISK

allocated channel: c2
channel c2: SID=45 device type=DISK

allocated channel: c3
channel c3: SID=51 device type=DISK

Starting backup at 21-JAN-16
channel c1: starting incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_cb1769f2_.dbf
channel c1: starting piece 1 at 21-JAN-16
channel c2: starting incremental level 0 datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_cb1769f6_.dbf
channel c2: starting piece 1 at 21-JAN-16
channel c3: starting incremental level 0 datafile backup set
channel c3: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_cb1769f9_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_cb1769ff_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_cb178oqs_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_cb178or2_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel c3: starting piece 1 at 21-JAN-16
channel c3: finished piece 1 at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T175149_cb1bkphw_.bkp tag=TAG20160121T175149 comment=NONE
channel c3: backup set complete, elapsed time: 00:00:35
channel c1: finished piece 1 at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T175149_cb1bkpjc_.bkp tag=TAG20160121T175149 comment=NONE
channel c1: backup set complete, elapsed time: 00:01:55
channel c2: finished piece 1 at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_21/o1_mf_nnnd0_TAG20160121T175149_cb1bkpfg_.bkp tag=TAG20160121T175149 comment=NONE
channel c2: backup set complete, elapsed time: 00:01:55
Finished backup at 21-JAN-16

Starting Control File and SPFILE Autobackup at 21-JAN-16
piece handle=/u01/app/oracle/fast_recovery_area/STONE/autobackup/2016_01_21/o1_mf_s_901734825_cb1bo9o5_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 21-JAN-16

sql statement: alter system archive log current
released channel: c1
released channel: c2
released channel: c3

监控

通过V$SESSIONV$PROCESS,可以查询RMAN通道对应的服务器会话,V$PROCESS的SPID字段显示操作系统进程或者线程ID。在UNIX平台,SPID表示进程ID,在Windows平台,SPID表示线程ID。

当只有一个RMAN会话活动时,执行下面语句查询:

SQL> COLUMN CLIENT_INFO FORMAT a30
SQL> COLUMN SID FORMAT 999
SQL> COLUMN SPID FORMAT 9999
SQL> SELECT s.sid, p.spid, s.client_info
  2  FROM v$process p, v$session s
  3  WHERE p.addr = s.paddr
  4  AND CLIENT_INFO LIKE 'rman%';
 SID SPID         CLIENT_INFO
---- ------------ ------------------------------
  15 2714         rman channel=ORA_SBT_TAPE_1
  13 2715         rman channel=ORA_SBT_TAPE_2

当有多个RMAN会话运行时,通过使用SET COMMAND ID命令关联进程和通道,如下:

(1)在每一个会话设置COMMAND ID为不同的值,例如在会话1:

RUN
{
SET COMMAND ID TO 'sess1';
BACKUP DATABASE;
}

在会话2:

RUN
{
SET COMMAND ID TO 'sess2';
BACKUP DATABASE;
}

(2)当RMAN job执行时,在SQL*Plus会话中查询V$SESSIONV$PROCESS视图,例如:

SELECT SID, SPID, CLIENT_INFO
FROM V$PROCESS p, V$SESSION s
WHERE p.ADDR = s.PADDR
AND CLIENT_INFO LIKE '%id=sess%';

例子:监控RMAN会话

SQL> col client_info for a30
SQL> col sid for 999
SQL> col spid for 9999
SQL> select s.sid,p.spid,s.client_info
  2  from v$process p,v$session s
  3  where p.addr=s.paddr
  4  and client_info like 'rman%';

 SID SPID                     CLIENT_INFO
---- ------------------------ ------------------------------
  39 23387                    rman channel=ORA_DISK_1

RMAN> run{
2> set command id to 'sess1';
3> backup database;}

RMAN> run{
2> set command id to 'sess2';
3> backup database;}

SQL> select s.sid,p.spid,s.client_info
  2  from v$process p,v$session s
  3  where p.addr=s.paddr
  4  and client_info like '%id=sess%';

 SID SPID                     CLIENT_INFO
---- ------------------------ -----------------------------------
  37 23459                    id=sess2
  53 23384                    id=sess1
  39 23387                    id=sess1,rman channel=ORA_DISK_1

通过查询视图V$SESSION_LONGOPSopen in new window监控备份、拷贝以及恢复过程。opname字段带有detail关键字的行表示一个作业步骤(job step)正在处理的文件,opname字段带有aggregate关键字的行表示一个RMAN命令中所有作业步骤处理的文件。一个作业步骤表示创建或者还原一个备份集或者镜像拷贝。detail粒度比aggregate粒度更细。

使用V$SESSION_LONGOPS视图查看信息需要设置参数STATISTICS_LEVEL为TYPICAL或者ALL。

V$SESSION_LONGOPS常用的字段含义如下:

  • OPNAME:对一行信息的描述,detail信息包括RMAN:datafile copy,RMAN:full datafile backup和RMAN:full datafile restore。
  • CONTEXT:有关备份的行,值为2,其他情况(不包括proxy copy),值为1。
  • SOFAR:对于镜像拷贝,表示已经读入的块数量;对于备份输入行,表示已经读入备份的块数量,对于备份输出行,表示已经写入到备份片的块数量;对于还原,表示一个作业步骤中已经还原的块数量;对于proxy copies,表示复制的文件数量。
  • TOTALWORK:对于镜像拷贝,表示文件所有块数量;对于备份输入行,表示一个作业步骤中需要读入文件块的总量,对于备份输出行,由于不能预先知道会写入多少块到备份片,所有该值为0;对于还原,表示一个作业步骤中所有文件块的总量;对于proxy copies,表示一个作业步骤中复制的文件总数量。

例子:进行备份,监控运行情况

SQL> select opname,context,sofar,totalwork,
  2  round(sofar/totalwork*100,2) "%_complete"
  3  from v$session_longops
  4  where opname like 'RMAN%'
  5  and opname not like '%aggregate%'
  6  and totalwork != 0
  7  and sofar<>totalwork;

OPNAME                            CONTEXT      SOFAR  TOTALWORK %_complete
------------------------------ ---------- ---------- ---------- ----------
RMAN: full datafile backup              1     133050     293600      45.32

例子:进行还原,监控运行情况

SQL> select opname,context,sofar,totalwork,
  2  round(sofar/totalwork*100,2) "%_complete"
  3  from v$session_longops
  4  where opname like 'RMAN%'
  5  and opname not like '%aggregate%'
  6  and totalwork != 0
  7  and sofar<>totalwork;

OPNAME                            CONTEXT      SOFAR  TOTALWORK %_complete
------------------------------ ---------- ---------- ---------- ----------
RMAN: full datafile restore             1      28570      44320      64.46

在RMAN命令挂起或者出现错误的时候可以使用DEBUG选项来定位,DEBUG选项显示RMAN编译中执行的所有SQL语句和执行结果,由恢复目录PL/SQL包产生的任何信息也会被显示。可以在RMAN提示符或者RUN块中指定DEBUG选项。下面的例子中,DEBUG选项用于数据文件3的备份,但不用于数据文件4:

RMAN> run {
      debug on;
      allocate channel c1 type disk;
      backup datafile 3;
      debug off;
      backup datafile 4; }

注意DUBUG会产生大量的信息,要有足够的磁盘空间来保留这些信息,一般不产生任何错误的备份操作会产生大约500K的信息。

[oracle@test ~]$ rman target / debug trace sample.log
RMAN> backup database plus archivelog delete input;

RMAN> host 'ls -l sample.log';

-rw-r--r-- 1 oracle oinstall 453561 Jan 24 22:12 sample.log
RMAN-06134: host command complete

快速找到RMAN错误信息中有用的信息:

  • RMAN错误信息中大部分没有什么用处,需要找到最重要的一个或者两个错误。

  • 检查包含“Additional information”加数字的信息,表示介质管理错误。

  • 从下往上分析输出信息,最后的一两个错误信息一般最有用。

  • 查看RMAN-03002或者RMAN-03009后的信息定位失败的命令。语法错误会产生RMAN-00558错误。

调优

参考如下步骤获取最佳备份性能:

  • 在配置和分配通道时移除RATE设置。RATE参数用于指定RMAN通道每秒读取的最大字节数。用于指定上限以防RMAN消耗过多磁盘带宽而影响性能。如果不是备份到磁带,建议不要在ALLOCATE CHANNEL或者CONFIGURE CHANNEL命令设置RATE参数。
  • 如果使用同步磁盘I/O,设置DBWR_IO_SLAVES参数。如果磁盘不支持异步I/O,设置DBWR_IO_SLAVES为非零值,可以使用4个磁盘I/O SLAVES进行备份和还原,以模拟异步I/O。如果使用了I/O SLAVES,从SGA中分配I/O BUFFERS,如果配置了大池,则使用大池,否则使用共享池。注意:设置了DBWR_IO_SLAVES,则DBWn进程也会使用SLAVES,因此可能需要增大PROCESSES参数。
  • 设置大池LARGE_POOL_SIZE。

通过如下公式计算大池LARGE_POOL_SIZE:

#_of_allocated_channels * (16 MB + (4*size_of_tape_buffer ))

对于备份到磁盘,磁带缓冲区为0,故设置LARGE_POOL_SIZE为16MB。对于磁带,使用RMAN通道参数BLKSIZE指定单个磁带缓冲区大小,默认值为256K。假如有2个磁带驱动器,磁带缓冲区大小为256K,则LARGE_POOL_SIZE为18MB,如果增大BLKSIZE为512K,则LARGE_POOL_SIZE为20M。

注意:只有当DBWR_IO_SLAVES>0(磁盘缓存)或者BACKUP_TAPE_IO_SLAVES=TURE(磁带缓存)时,才需要手动设置大池。如果使用自动内存管理,则系统根据负载自动调整大小。

Diagnosing

Data Recovery Advisor

当遇到错误时,数据恢复顾问(Data Recovery Advisor)自动收集错误信息,检查分析问题。

数据问题有时会很严重,比如丢失日志文件导致不能启动数据库。有时不严重(比如数据文件块损坏),不需要关闭数据库或者不能启动实例。故数据恢复顾问可以用于以下2种情况:一是不能启动数据库(由于数据库文件丢失、不一致或者损坏),一是运行时文件损坏。

使用数据恢复顾问进行自动诊断的流程如下:

  1. 健康监测自动检查并记录问题到ADR。
  2. 列出级别为CRITICAL或者HIGH的问题。
  3. 进行修复建议,包括自动和手动修复选项,并检查可行性。
  4. 可以选择手动执行修复或者使用数据恢复顾问执行修复。
  5. 使用VALIDATE命令进行检查。
RMAN CommandAction
LIST FAILURELists previously executed failure assessment
ADVISE FAILUREDisplays recommended repair option
REPAIR FAILURERepairs and closes failures (after ADVISE in the same RMAN session)
CHANGE FAILUREChanges or closes one or more failures

如果怀疑数据库出现问题,使用LIST FAILURE命令列出问题信息。

使用ADVISE FAILURE命令为问题列出推荐的修复建议,隐式关闭已经修复的问题。如果不加选项,默认动作是为记录在ADR中所有CRITICAL和HIGH级别错误提出建议。

在同一个会话中,使用ADVISE FAILURE命令后,使用REPAIR FAILURE命令进行修复。修复完成后,关闭问题。

使用CHANGE FAILURE命令修改问题优先级或者关闭问题。只能修改级别为HIGH或者LOW的问题优先级。问题修复后会隐式关闭,也可以显示关闭。

相关视图:

  • V$IR_FAILURE:列出所有的问题,包括关闭的,RMAN命令LIST FAILURE的结果

  • V$IR_MANUAL_CHECKLIST:列出需要手动操作的建议,RMAN命令ADVISE FAILURE的结果

  • V$IR_REPAIR:列出自动修复建议,RMAN命令ADVISE FAILURE的结果

  • V$IR_FAILURE_SET:是否只能手动修复

LIST FAILURE

LIST FAILURE命令列出问题。如果目标实例使用了恢复目录,可以在STARTED(NOMOUNT)模式使用,否则需要在MOUNTED模式使用。

LIST FAILURE命令不会去检查诊断新的问题,而是列出先前评估的结果。重复执行LIST FAILURE命令重新验证所有存在的问题。如果用户手动修复问题,或如果问题消失,则数据恢复顾问从LIST FAILURE输出中删除这些问题。语法:

LIST FAILURE
[ ALL | CRITICAL | HIGH | LOW | CLOSED | failnum[,failnum,…] ]
[ EXCLUDE FAILURE failnum[,failnum,…] ]
[ DETAIL ] 

描述如下:

  • failnum:要显示修复选项的问题数量
  • ALL:列出所有优先级的问题
  • CRITICAL:列出CRITICAL优先级和OPEN状态的问题。这些问题会导致整个数据库不可用(例如丢失控制文件)
  • HIGH:列出HIGH优先级和OPEN状态的问题,这些问题会导致数据库部分不可用或者不可恢复(例如丢失归档日志文件)
  • LOW:列出LOW优先级和OPEN状态的问题
  • CLOSED:只列出关闭的问题
  • EXCLUDE FAILURE:排除指定的问题
  • DETAIL:列出问题详细信息,例如文件中多个块损坏,会列出每一个块信息

例子:列出问题

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      27-JAN-16     One or more non-system datafiles are missing

ADVISE FAILURE

ADVISE FAILURE命令为问题列出了推荐的修复选项,隐式关闭已经修复了的所有问题,显示输入问题的概要信息。

ADVISE FAILURE默认(不加选项)为记录在ADR中所有CRITICAL和HIGH优先级的问题提出建议。如果自上一次LAST FAILURE命令之后有新的问题记录到ADR,则该命令的输出会包含WARNING。

当数据恢复顾问生成一个自动修复选项,会生成一个脚本,显示RMAN将如何修复问题。

语法:

ADVISE FAILURE
[ ALL | CRITICAL | HIGH | LOW | failnum[,failnum,…] ]
[ EXCLUDE FAILURE failnum [,failnum,…] ]

例子:修复建议

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      27-JAN-16     One or more non-system datafiles are missing

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/STONE/datafile/user01.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore and recover datafile 4  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_277717931.hm

REPAIR FAILURE

REPAIR FAILURE命令需要在同一个RMAN会话中,ADVISE FAILURE命令之后使用。默认(不加选项)使用一个推荐的修复选项。如果没有推荐的修复选项,REPAIR FAILURE命令发出一个隐式的ADVISE FAILURE命令。

使用USING ADVISE OPTION interger,通过选项编号指定使用哪一个修复选项。

由于修复可能会需要很长时间进行大量修改,故需要对其进行确认。完成修复后,会关闭问题。

不能同时运行多个修复会话,但可以同时运行REPAIR ... PREVIEW。

  • PREVIEW:不执行修复而是显示修复脚本
  • NOPROMPT:不需要确认

例子:执行修复

RMAN> repair failure preview;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3201719897.hm

contents of repair script:
   ## restore and recover datafile
   restore datafile 4;
   recover datafile 4;
   sql 'alter database datafile 4 online';

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_3201719897.hm

contents of repair script:
   ## restore and recover datafile
   restore datafile 4;
   recover datafile 4;
   sql 'alter database datafile 4 online';

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 27-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_24/o1_mf_nnndf_TAG20160124T211323_cb9mhmmc_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_24/o1_mf_nnndf_TAG20160124T211323_cb9mhmmc_.bkp tag=TAG20160124T211323
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 27-JAN-16

Starting recover at 27-JAN-16
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 8 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_26/o1_mf_1_8_cbfqhwdr_.arc
archived log for thread 1 with sequence 9 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_27/o1_mf_1_9_cbj37c44_.arc
archived log for thread 1 with sequence 10 is already on disk as file /u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_27/o1_mf_1_10_cbj9dox3_.arc
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_24/o1_mf_annnn_TAG20160124T211500_cb9mlnkc_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_24/o1_mf_annnn_TAG20160124T211500_cb9mlnkc_.bkp tag=TAG20160124T211500
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_27/o1_mf_1_7_cbjtpskc_.arc thread=1 sequence=7
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_27/o1_mf_1_7_cbjtpskc_.arc RECID=240 STAMP=902242777
archived log file name=/u01/app/oracle/fast_recovery_area/STONE/archivelog/2016_01_26/o1_mf_1_8_cbfqhwdr_.arc thread=1 sequence=8
media recovery complete, elapsed time: 00:00:02
Finished recover at 27-JAN-16

sql statement: alter database datafile 4 online
repair failure complete

Do you want to open the database (enter YES or NO)? yes
database opened

CHANGE FAILURE

CHANGE FAILURE命令用于修改问题优先级以及关闭问题。

语法:

CHANGE FAILURE
{ ALL | CRITICAL | HIGH | LOW | failnum[,failnum,…] }
[ EXCLUDE FAILURE failnum[,failnum,…] ]
{ PRIORITY {CRITICAL | HIGH | LOW} |
CLOSE } – change status of the failure(s) to closed
[ NOPROMPT ]do not ask user for a confirmation

问题优先级只能从HIGH到LOW和从LOW到HIGH。不能修改为CRITICAL的优先级。(修改优先级从HIHG到LOW的情况之一是不想在LIST FAILURE命令的默认输出中看到该问题。例如块损坏为HIGH优先级,如果块位于一个很少使用的表空间,可以临时将其优先级修改为LOW。)

问题修复后会隐式关闭问题,也可以显示关闭问题。

该命令默认需要用户进行确认。

例子:更改问题优先级

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      27-JAN-16     One or more non-system datafiles are missing

RMAN> change failure 3282 priority low;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      27-JAN-16     One or more non-system datafiles are missing

Do you really want to change the above failures (enter YES or NO)? yes
changed 1 failures to LOW priority

RMAN> list failure;

no failures found that match specification

RMAN> list failure all;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       LOW      OPEN      27-JAN-16     One or more non-system datafiles are missing

RMAN> change failure 3282 priority high;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       LOW      OPEN      27-JAN-16     One or more non-system datafiles are missing

Do you really want to change the above failures (enter YES or NO)? yes
changed 1 failures to HIGH priority

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
3282       HIGH     OPEN      27-JAN-16     One or more non-system datafiles are missing

Block Corruption

对于非常重要的数据库,可能需要执行额外的前瞻性主动检查(在每天的业务低峰期间)。可以通过Health Monitor或者使用RMAN的VALIDATE命令进行定期的健康检查。在一般情况下,当被动检查检测到数据库组件中的问题时,可以对受影响的组件执行一个更完整的检查。

RMAN的VALIDATE DATABASE命令用于为数据库及其组件调用健康检查,扩展了现有的VALIDATE BACKUPSET命令,将显示验证过程中检测到的所有问题。如果检测到问题,则将其作为FINDING记录到ADR。可以使用LIST FAILURE命令来查看存储库中记录的所有问题。

VALIDATE命令支持单个备份集和数据块的验证。默认情况下,VALIDATE命令只检查物理损坏。可以指定CHECK LOGICAL检查逻辑损坏。

块损坏可分为块间(Interblock)和块内(Intrablock)损坏。块内损坏发生在块体本身,可以是物理的或逻辑的损坏。块间损坏发生在块之间,只能是逻辑损坏。VALIDATE命令只检查块内损坏。

一个已损坏的数据块是指块不是Oracle可以识别的格式或其内容内部不一致。通常情况下,损坏是由硬件故障或操作系统问题造成的。数据库将块损坏分为“逻辑损坏”或“介质损坏”。如果是逻辑损坏,则有一个Oracle内部错误。逻辑损坏的块在数据库检测到不一致后会被标记为损坏。如果是介质损坏,则块格式不正确;在被读取到磁盘后,该块中的信息没有任何意义。

通过恢复块或删除包含损坏块的数据库对象可以修复一个介质损坏块。如果介质损坏是由于硬件故障导致,则需要修复硬件故障。

通常ORA-01578错误是由硬件问题造成的。如果ORA-01578错误总是返回相同的参数,则最有可能是介质损坏块。

如果错误参数每次都发生变化,则可能会是硬件问题,应该进行内存、页空间以及I/O控制器检查。

注意:ORA-01578返回相对文件号,但随之而来的ORA-01110错误显示绝对文件号。

例子:模拟块损坏

SQL> create tablespace tstest datafile '/home/oracle/tstest.dbf' size 10m;

Tablespace created.

SQL> create table emptest tablespace tstest as select * from hr.employees where rownum<10;

Table created.

定位表对应的块。
SQL> select rowid,dbms_rowid.rowid_relative_fno(rowid) rel_fno,dbms_rowid.rowid_block_number(rowid) block from emptest;

ROWID                 REL_FNO      BLOCK
------------------ ---------- ----------
AAAWO6AAIAAAACDAAA          8        131
AAAWO6AAIAAAACDAAB          8        131
AAAWO6AAIAAAACDAAC          8        131
AAAWO6AAIAAAACDAAD          8        131
AAAWO6AAIAAAACDAAE          8        131
AAAWO6AAIAAAACDAAF          8        131
AAAWO6AAIAAAACDAAG          8        131
AAAWO6AAIAAAACDAAH          8        131
AAAWO6AAIAAAACDAAI          8        131
验证是否有坏块,目前没有:
[oracle@test ~]$ dbv userid=sys/123456 file=/home/oracle/tstest.dbf

DBVERIFY: Release 11.2.0.4.0 - Production on Wed Jan 27 16:30:20 2016

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

DBVERIFY - Verification starting : FILE = /home/oracle/tstest.dbf


DBVERIFY - Verification complete

Total Pages Examined         : 1280
Total Pages Processed (Data) : 1
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 127
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1152
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 4154173 (0.4154173)

先进行数据库全备。
RMAN> backup database plus archivelog delete input;

RMAN标记坏块。
RMAN> recover datafile 8 block 131 clear;

Starting recover at 27-JAN-16
using channel ORA_DISK_1
Finished recover at 27-JAN-16

再次验证,发现坏块。
[oracle@test ~]$ dbv userid=sys/123456 file=/home/oracle/tstest.dbf

DBVERIFY: Release 11.2.0.4.0 - Production on Wed Jan 27 16:34:57 2016

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

DBVERIFY - Verification starting : FILE = /home/oracle/tstest.dbf
Page 131 is marked corrupt
Corrupt block relative dba: 0x02000083 (file 8, block 131)
Bad header found during dbv: 
Data in bad block:
 type: 6 format: 6 rdba: 0x02000094
 last change scn: 0x0000.003f633d seq: 0x2 flg: 0x04
 spare1: 0xed spare2: 0xf3 spare3: 0x0
 consistency value in tail: 0x633d0602
 check value in block header: 0xadcc
 computed block checksum: 0xe7fa



DBVERIFY - Verification complete

Total Pages Examined         : 1280
Total Pages Processed (Data) : 0
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 129
Total Pages Processed (Seg)  : 1
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1149
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 4154177 (0.4154177)

查询报错。
SQL> select count(*) from emptest;
select count(*) from emptest
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file ## 8, block ## 131)
ORA-01110: data file 8: '/home/oracle/tstest.dbf'

例子:运行ANALYZE命令分析表

SQL> analyze table emptest validate structure cascade;
analyze table emptest validate structure cascade
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file ## 8, block ## 131)
ORA-01110: data file 8: '/home/oracle/tstest.dbf'

大多数情况下,当首次遇到损坏的块,数据库标记块为介质损坏并写入到相关视图中,后续对块的读取都会失败。可以只对标记为损坏的块进行块恢复。使用RMAN命令RECOVER ... BLOCK进行块介质恢复。默认情况下,RMAN搜索闪回日志查找损坏块的可用拷贝,然后搜索全备或者0级增量备份查找可用块。找到后,还原并进行介质恢复。

V$DATABASE_BLOCK_CORRUPTIONopen in new window视图显示被RMAN命令、ANALYZE、dbv、SQL查询等标记为损坏的块。以下类型的损坏将会增加到这个视图:

  • 物理/介质损坏:数据库不能识别块:校验和无效,块内都是0或者块头损坏。默认启用物理损坏检查。
  • 逻辑损坏:块有有效的校验和,块头和块尾匹配,但内容不一致。块介质恢复不能修复逻辑块损坏。默认不启用逻辑损坏检查。可以通过BACKUP,RESTORE,RECOVER和VALIDATE命令指定CHECK LOGICAL选项启用逻辑损坏检查。

执行RECOVER ... BLOCK命令的前提条件:

  • 目标数据库必须是归档模式,并使用当前控制文件打开或者挂载。
  • 包含损坏块的数据文件的备份必须是全备或者0级增量备份,不能是代理拷贝。如果只有代理拷贝,需要还原到非默认位置以便让RMAN认为是数据文件的拷贝。
  • 只能使用归档日志文件进行恢复。不能使用1级增量备份。
  • 从闪回日志中搜索损坏块的可用拷贝需要启用闪回数据库,如果闪回日志有损坏块的老版本的完好的块,则RMAN会使用这些块加快恢复速度。

块恢复前,需要先定位到损坏的块,一般使用如下方法定位:

  • LIST FAILURE,VALIDATE或者BACKUP ... VALIDATE命令
  • V$DATABASE_BLOCK_CORRUPTION视图
  • 标准输出的错误消息
  • 告警日志和用户跟踪文件
  • ANALYZE TABLE和ANALYZE INDEX命令
  • DBVERIFY工具

块修复语法:

RECOVER DATAFILE 6 BLOCK 3;  #Recover a single block

RECOVER  		     #Recover multiple blocks in multiple data files
DATAFILE 2 BLOCK 43
DATAFILE 2 BLOCK 79
DATAFILE 6 BLOCK 183;

RECOVER CORRUPTION LIST;	 #Recover all blocks logged in V$DATABASE_BLOCK_CORRUPTION

例子:定位损坏的块并恢复

RMAN> list failure;

using target database control file instead of recovery catalog
List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
8323       HIGH     OPEN      27-JAN-16     Datafile 8: '/home/oracle/tstest.dbf' contains one or more corrupt blocks

RMAN> validate database;

Starting validate at 27-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00001 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_system_cb1769f2_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_cb1769f6_.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_example_cb33c57f_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_cb1769ff_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_cb178oqs_.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_cb178or2_.dbf
input datafile file number=00008 name=/home/oracle/tstest.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/STONE/datafile/user01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:01:26
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
1    OK     0              13892        116552          4168226   
  File Name: /u01/app/oracle/oradata/STONE/datafile/o1_mf_system_cb1769f2_.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              66551           
  Index      0              13992           
  Other      0              22045           

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2    OK     0              19632        116550          4168231   
  File Name: /u01/app/oracle/oradata/STONE/datafile/o1_mf_sysaux_cb1769f6_.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              33407           
  Index      0              28236           
  Other      0              35205           

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
3    OK     0              1            14721           4168230   
  File Name: /u01/app/oracle/oradata/STONE/datafile/o1_mf_undotbs1_cb1769ff_.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              0               
  Index      0              0               
  Other      0              14719           

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4    OK     0              78           989             3979319   
  File Name: /u01/app/oracle/oradata/STONE/datafile/user01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              268             
  Index      0              51              
  Other      0              563             

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5    OK     0              31371        44323           3351224   
  File Name: /u01/app/oracle/oradata/STONE/datafile/o1_mf_example_cb33c57f_.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              4547            
  Index      0              1149            
  Other      0              7253            

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
6    OK     0              1            1281            3759632   
  File Name: /u01/app/oracle/oradata/STONE/datafile/o1_mf_test_ind_cb178or2_.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              0               
  Index      0              0               
  Other      0              1279            

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              513          1921            3706513   
  File Name: /u01/app/oracle/oradata/STONE/datafile/o1_mf_rcat_ts_cb178oqs_.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              409             
  Index      0              234             
  Other      0              764             

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
8    FAILED 0              1149         1280            4154177   
  File Name: /home/oracle/tstest.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       1              1               
  Index      0              0               
  Other      0              130             

validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/stone/stone/trace/stone_ora_11705.trc for details
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
including current control file for validation
including current SPFILE in backup set
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Control File and SPFILE
===============================
File Type    Status Blocks Failing Blocks Examined
------------ ------ -------------- ---------------
SPFILE       OK     0              2               
Control File OK     0              608             
Finished validate at 27-JAN-16

SQL> select * from v$database_block_corruption;

     FILE##     BLOCK##     BLOCKS CORRUPTION_CHANGE## CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         8        131          1            4154173 CORRUPT

SQL> select count(*) from emptest;
select count(*) from emptest
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file ## 8, block ## 131)
ORA-01110: data file 8: '/home/oracle/tstest.dbf'


SQL> analyze table emptest validate structure cascade;
analyze table emptest validate structure cascade
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file ## 8, block ## 131)
ORA-01110: data file 8: '/home/oracle/tstest.dbf'

[oracle@test ~]$ dbv userid=sys/123456 file=/home/oracle/tstest.dbf

DBVERIFY: Release 11.2.0.4.0 - Production on Wed Jan 27 19:11:02 2016

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

DBVERIFY - Verification starting : FILE = /home/oracle/tstest.dbf
Page 131 is marked corrupt
Corrupt block relative dba: 0x02000083 (file 8, block 131)
Bad header found during dbv: 
Data in bad block:
 type: 6 format: 6 rdba: 0x02000094
 last change scn: 0x0000.003f633d seq: 0x2 flg: 0x04
 spare1: 0xed spare2: 0xf3 spare3: 0x0
 consistency value in tail: 0x633d0602
 check value in block header: 0xadcc
 computed block checksum: 0xe7fa



DBVERIFY - Verification complete

Total Pages Examined         : 1280
Total Pages Processed (Data) : 0
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 129
Total Pages Processed (Seg)  : 1
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1149
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 4154177 (0.4154177)

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
8323       HIGH     OPEN      27-JAN-16     Datafile 8: '/home/oracle/tstest.dbf' contains one or more corrupt blocks

analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
no manual actions available

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Perform block media recovery of block 131 in file 8  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2387623021.hm

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/stone/stone/hm/reco_2387623021.hm

contents of repair script:
   ## block media recovery
   recover datafile 8 block 131;

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting recover at 27-JAN-16
using channel ORA_DISK_1

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00008
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_27/o1_mf_nnndf_TAG20160127T163123_cbk02w4k_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/STONE/backupset/2016_01_27/o1_mf_nnndf_TAG20160127T163123_cbk02w4k_.bkp tag=TAG20160127T163123
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 27-JAN-16
repair failure complete

Automatic Diagnostic Repository

Automatic Diagnostic Repository(ADR)是一个基于文件的知识库,包括跟踪文件,事件转储和包,告警日志,健康监测报告,核心转储等数据。多个实例以及多个产品共用一个统一的位于数据库之外的目录结构。因此可以在数据库关闭时用于问题诊断。

Description of Figure 9-1 follows

从Oracle数据库11gR1开始,数据库,自动存储管理(ASM),集群就绪服务(CRS),和其他Oracle产品或部件存储所有诊断数据到ADR。每个产品的每个实例都存储诊断数据到自己的ADR主目录。例如,在一个共享存储和ASM的RAC环境中,每个数据库实例和每个ASM实例都有一个在ADR中的主目录。ADR的统一目录结构,统一的诊断数据格式和一套统一的工具,可以使用户和Oracle支持跨多个实例进行关联和分析相关诊断数据。

ADR基目录通过DIAGNOSTIC_DEST初始化参数设置,如果忽略该参数或者为空,那么如果设置了ORACLE_BASE环境变量,则DIAGNOSTIC_DEST就为ORACLE_BASE,如果没有设置ORACLE_BASE环境变量,则DIAGNOSTIC_DEST为$ORACLE_HOME/log。

SQL> show parameter diag

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
diagnostic_dest                      string      /u01/app/oracle
[oracle@test ~]$ tree -L 2 /u01/app/oracle/diag/
/u01/app/oracle/diag/
├── asm
├── clients
│   └── user_oracle
├── crs
├── diagtool
├── lsnrctl
├── netcman
├── ofm
├── rdbms
│   ├── dummy
│   └── stone
└── tnslsnr
    └── test

V$DIAG_INFO视图列出了所有重要的ADR的位置:

  • ADR Base:ADR基目录
  • ADR Home:当前数据库实例的ADR主目录
  • Diag Trace:文本告警日志和前后台进程的跟踪文件的位置
  • Diag Alert:XML版本的告警日志的位置
  • Diag Incident:事件日志位置
  • Diag Cdump:诊断核心文件位置
  • Health Monitor:健康监测日志位置
  • Default Trace File:用户会话跟踪文件路径,SQL跟踪文件位置。
SQL> select * from v$diag_info;

   INST_ID NAME                      VALUE
---------- ------------------------- -----------------------------------------------------------------
         1 Diag Enabled              TRUE
         1 ADR Base                  /u01/app/oracle
         1 ADR Home                  /u01/app/oracle/diag/rdbms/stone/stone
         1 Diag Trace                /u01/app/oracle/diag/rdbms/stone/stone/trace
         1 Diag Alert                /u01/app/oracle/diag/rdbms/stone/stone/alert
         1 Diag Incident             /u01/app/oracle/diag/rdbms/stone/stone/incident
         1 Diag Cdump                /u01/app/oracle/diag/rdbms/stone/stone/cdump
         1 Health Monitor            /u01/app/oracle/diag/rdbms/stone/stone/hm
         1 Default Trace File        /u01/app/oracle/diag/rdbms/stone/stone/trace/stone_ora_14570.trc
         1 Active Problem Count      1
         1 Active Incident Count     7

11 rows selected.

ADRCI是一个命令行工具,可以:

  • 查看ADR内的诊断数据
  • 打包事件和问题信息到zip文件,用于发给Oracle Support

例子:通过ADRCI查看事件

[oracle@test ~]$ adrci

ADRCI: Release 11.2.0.4.0 - Production on Wed Jan 27 21:02:27 2016

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

ADR base = "/u01/app/oracle"
adrci> show incident 

ADR Home = /u01/app/oracle/diag/clients/user_oracle/host_3709602581_80:
*************************************************************************
0 rows fetched

ADR Home = /u01/app/oracle/diag/tnslsnr/oracletest/listener:
*************************************************************************
0 rows fetched

ADR Home = /u01/app/oracle/diag/rdbms/dummy/stone:
*************************************************************************
0 rows fetched

ADR Home = /u01/app/oracle/diag/rdbms/stone/stone:
*************************************************************************
INCIDENT_ID          PROBLEM_KEY                                                 CREATE_TIME                              
-------------------- ----------------------------------------------------------- ---------------------------------------- 
73353                ORA 1578                                                    2016-01-27 16:35:59.925000 +08:00       
73354                ORA 1578                                                    2016-01-27 16:36:04.770000 +08:00       
73355                ORA 1578                                                    2016-01-27 16:46:00.525000 +08:00       
73356                ORA 1578                                                    2016-01-27 16:50:18.178000 +08:00       
74781                ORA 1578                                                    2016-01-27 19:09:09.792000 +08:00       
74782                ORA 1578                                                    2016-01-27 19:09:26.033000 +08:00       
74783                ORA 1578                                                    2016-01-27 19:09:30.499000 +08:00       
7 rows fetched

可以使用ADRCI创建和查看健康监测检查报告。需要先确保正确设置操作系统环境变量,如ORACLE_HOME,然后在操作系统命令提示符输入命令:adrci

使用show homes列出所有ADR主目录,使用set homepath改变当前ADR主目录。使用create report hm_run命令生成报告,使用show report hm_rum命令查看报告。

例子:使用ADRCI工具查看健康检查报告

adrci> show homes
ADR Homes: 
diag/clients/user_oracle/host_3709602581_80
diag/tnslsnr/test/listener
diag/rdbms/dummy/stone
diag/rdbms/stone/stone

adrci> show hm_run -p "run_id=8585"

ADR Home = /u01/app/oracle/diag/clients/user_oracle/host_3709602581_80:
*************************************************************************
0 rows fetched
<ADR_RELATION name="">
<ADR_HOME name="/u01/app/oracle/diag/clients/user_oracle/host_3709602581_80">

ADR Home = /u01/app/oracle/diag/tnslsnr/oracletest/listener:
*************************************************************************
0 rows fetched
</ADR_HOME>
<ADR_HOME name="/u01/app/oracle/diag/tnslsnr/test/listener">

ADR Home = /u01/app/oracle/diag/rdbms/dummy/stone:
*************************************************************************
0 rows fetched
</ADR_HOME>
<ADR_HOME name="/u01/app/oracle/diag/rdbms/dummy/stone">

ADR Home = /u01/app/oracle/diag/rdbms/stone/stone:
*************************************************************************

**********************************************************
HM RUN RECORD 1
**********************************************************
   RUN_ID                        8585
   RUN_NAME                      stone
   CHECK_NAME                    Data Block Integrity Check
   NAME_ID                       3
   MODE                          0
   START_TIME                    2016-01-27 22:52:01.234049 +08:00
   RESUME_TIME                   <NULL>
   END_TIME                      2016-01-27 22:52:01.533168 +08:00
   MODIFIED_TIME                 2016-01-27 22:53:09.975723 +08:00
   TIMEOUT                       0
   FLAGS                         0
   STATUS                        5
   SRC_INCIDENT_ID               0
   NUM_INCIDENTS                 0
   ERR_NUMBER                    0
   REPORT_FILE                   /u01/app/oracle/diag/rdbms/stone/stone/hm/HMREPORT_stone.hm
1 rows fetched

adrci> set homepath diag/rdbms/stone/stone
adrci> create report hm_run stone
adrci> show report hm_run stone
<?xml version="1.0" encoding="US-ASCII"?>
<HM-REPORT REPORT_ID="stone">
    <TITLE>HM Report: stone</TITLE>
    <RUN_INFO>
        <CHECK_NAME>Data Block Integrity Check</CHECK_NAME>
        <RUN_ID>8585</RUN_ID>
        <RUN_NAME>stone</RUN_NAME>
        <RUN_MODE>MANUAL</RUN_MODE>
        <RUN_STATUS>COMPLETED</RUN_STATUS>
        <RUN_ERROR_NUM>0</RUN_ERROR_NUM>
        <SOURCE_INCIDENT_ID>0</SOURCE_INCIDENT_ID>
        <NUM_INCIDENTS_CREATED>0</NUM_INCIDENTS_CREATED>
        <RUN_START_TIME>2016-01-27 22:52:01.234049 +08:00</RUN_START_TIME>
        <RUN_END_TIME>2016-01-27 22:52:01.533168 +08:00</RUN_END_TIME>
    </RUN_INFO>
    <RUN_PARAMETERS>
        <RUN_PARAMETER>BLC_DF_NUM=8</RUN_PARAMETER>
        <RUN_PARAMETER>BLC_BL_NUM=131</RUN_PARAMETER>
    </RUN_PARAMETERS>
    <RUN-FINDINGS>
        <FINDING>
            <FINDING_NAME>Media Block Corruption</FINDING_NAME>
            <FINDING_ID>8589</FINDING_ID>
            <FINDING_TYPE>FAILURE</FINDING_TYPE>
            <FINDING_STATUS>OPEN</FINDING_STATUS>
            <FINDING_PRIORITY>HIGH</FINDING_PRIORITY>
            <FINDING_CHILD_COUNT>0</FINDING_CHILD_COUNT>
            <FINDING_CREATION_TIME>2016-01-27 22:52:01.526152 +08:00</FINDING_CREATION_TIME>
            <FINDING_MESSAGE>Block 131 in datafile 8: '/home/oracle/tstest.dbf' is media corrupt</FINDING_MESSAGE>
            <FINDING_MESSAGE>Object EMPTEST owned by SYS might be unavailable</FINDING_MESSAGE>
        </FINDING>
    </RUN-FINDINGS>
</HM-REPORT>
上次编辑于:
贡献者: stonebox