rman从多份备份中还原操作

1、现象重现

RMAN> shutdown immediate

database dismounted
Oracle instance shut down

RMAN> startup

connected to target database (not started)
Oracle instance started
database mounted
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 11/18/2011 14:40:40
ORA-01157: cannot identify/lock data file 11 - see DBWR trace file
ORA-01110: data file 11: '/opt/oracle/oradata/test/xifenfei03.dbf'

RMAN> restore datafile 11;

Starting restore at 2011-11-18 14:41:04
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK

channel ORA_DISK_1: restoring datafile 00011
input datafile copy recid=13 stamp=767543949 filename=/tmp/11.dbf
destination for restore of datafile 00011: /opt/oracle/oradata/test/xifenfei03.dbf
ORA-19505: failed to identify file "/tmp/11.dbf"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-19600: input file is datafile-copy 13 (/tmp/11.dbf)
ORA-19601: output file is datafile 11 (/opt/oracle/oradata/test/xifenfei03.dbf)
failover to previous backup

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00011 to /opt/oracle/oradata/test/xifenfei03.dbf
channel ORA_DISK_1: reading from backup piece /tmp/test_full_01mrkqdh_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/tmp/test_full_01mrkqdh_1_1 tag=TAG20111114T124433
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 2011-11-18 14:41:08

虽然整个过程datafile 11恢复成功了,但是在恢复过程中,先是去读取/tmp/11.dbf的copy文件,读取这个文件失败,然后继续使用/tmp/test_full_01mrkqdh_1_1来恢复数据文件,为什么会出现这样的情况呢?

2、原因分析

RMAN> list copy of datafile 11;


List of Datafile Copies
Key     File S Completion Time     Ckp SCN    Ckp Time            Name
------- ---- - ------------------- ---------- ------------------- ----
13      11   A 2011-11-18 14:39:09 11517136   2011-11-14 12:44:33 /tmp/11.dbf
--确实存在datafile 11的copy文件/tmp/11.dbf,并且有效
--checkpoint time为:2011-11-14 12:44:33,创建时间为:2011-11-18 14:39:09

RMAN> list backup of datafile 11;


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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
1       Full    9.32G      DISK        00:04:24     2011-11-14 12:48:57
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20111114T124433
        Piece Name: /tmp/test_full_01mrkqdh_1_1
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  11      Full 11517136   2011-11-14 12:44:33 /opt/oracle/oradata/test/xifenfei03.dbf
--backupset中也有datafile 11
--checkpoint time为:2011-11-14 12:44:33,创建时间为:2011-11-14 12:48:57

--通过比较这两个关于datafile 11的备份时间,rman自动选择了创建时间比较新的备份恢复

RMAN> crosscheck copy of datafile 11;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
validation failed for datafile copy
datafile copy filename=/tmp/11.dbf recid=13 stamp=767543949
Crosschecked 1 objects

RMAN> list copy of datafile 11;

List of Datafile Copies
Key     File S Completion Time     Ckp SCN    Ckp Time            Name
------- ---- - ------------------- ---------- ------------------- ----
13      11   X 2011-11-18 14:39:09 11517136   2011-11-14 12:44:33 /tmp/11.dbf
--通过检测发现/tmp/11.dbf是无效的,所以rman继续使用backupset进行恢复datafile 11

在有些时候,当rman对中关于一个对象的备份有多个(备份时间不一致),rman会从最新备份的开始还原,如果第一个失败,使用下一个备份,但是在有些时候可能第一个失败后,rman不自动使用下一个,这个时候的处理思路是:使用crosscheck backup/copy检测无效的备份,删除掉,继续执行

rman恢复spfile最快捷方式

一、sqlplus nomount数据库并恢复spfile

SQL> startup
ORA-01078: failure in processing system parameters                       
LRM-00109: 无法打开参数文件 'E:\ORACLE\11_2_0\DATABASE\INITXFF.ORA' 

RMAN> restore spfile to 'e:\oracle\11_2_0\database\spfilexff.ora'  
2> from 'F:\rmanbackup\20111113_0KMRIT19_1_1';                           

启动 restore 于 14-11月-11                                               
RMAN-00571: ===========================================================  
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================  
RMAN-00601: fatal error in recovery manager                              
RMAN-03004: 执行命令期间出现严重错误       
RMAN-10041: 无法在失败后重新创建轮询通道上下文。
RMAN-10024: 设置 rpc 轮询时出错                                          
RMAN-10005: 打开游标时出错                                               
RMAN-10002: ORACLE 错误 : ORA-03114: not connected to ORACLE             
RMAN-03002: restore 命令 (在 11/14/2011 22:23:24 上) 失败
ORA-03113: 通信通道的文件结尾                                            
进程 ID: 2884                                                            
会话 ID: 97 序列号: 1

1、无spfilexff.ora/initxff.ora/init.ora文件,sqlplus不能启动数据库至nomount状态
2、在数据库没有nomount状态下,不能恢复spfile

二、rman nomount数据库并恢复spfile

RMAN> startup           

已连接到目标数据库 (未启动)
启动失败: ORA-01078: failure in processing system parameters             
LRM-00109: 无法打开参数文件 'E:\ORACLE\11_2_0\DATABASE\INITXFF.ORA'      

在没有参数文件的情况下启动 Oracle 实例以检索 spfile
Oracle 实例已启动
RMAN-00571: =========================================================== 
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============  
RMAN-00571: ===========================================================  
RMAN-03002: startup 命令 (在 11/14/2011 22:00:32 上) 失败
ORA-00205: 标识控制文件时出错, 有关详细信息, 请查看预警日志

RMAN> restore spfile to 'e:\oracle\11_2_0\database\spfilexff.ora'        
2> from 'F:\rmanbackup\20111113_0KMRIT19_1_1';                           

启动 restore 于 14-11月-11                                               
分配的通道: ORA_DISK_1                                                   
通道 ORA_DISK_1: SID=10 设备类型=DISK

通道 ORA_DISK_1: 正在从 AUTOBACKUP F:\rmanbackup\20111113_0KMRIT19_1_1 还原 spfile 
通道 ORA_DISK_1: 从 AUTOBACKUP 还原 SPFILE 已完成                        
完成 restore 于 14-11月-11

1、rman会使用一个隐含(默认的参数文件启动数据库至nomount状态)
2、在nomount状态下,rman可以恢复spfile

三、rman启动数据库日志

Mon Nov 14 22:00:26 2011
Starting ORACLE instance (restrict)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 2
Using LOG_ARCHIVE_DEST_1 parameter default value as e:\oracle\11_2_0\RDBMS
Autotune of undo retention is turned on. 
IMODE=BR
ILAT =18
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options.
Using parameter settings in client-side pfile C:\S5O4.1 on machine XIFENFEI-PC
System parameters with non-default values:
  sga_target               = 152M
  compatible               = "11.2.0.1.0"
  _dummy_instance          = TRUE
  remote_login_passwordfile= "EXCLUSIVE"
  db_name                  = "XFF"
Mon Nov 14 22:00:27 2011
PMON started with pid=2, OS id=2932 
Mon Nov 14 22:00:28 2011
VKTM started with pid=3, OS id=4364 at elevated priority
VKTM running at (10)millisec precision with DBRM quantum (100)ms
Mon Nov 14 22:00:29 2011
GEN0 started with pid=4, OS id=4524 
Mon Nov 14 22:00:30 2011
DIAG started with pid=5, OS id=5472 
Mon Nov 14 22:00:30 2011
DBRM started with pid=6, OS id=5296 
Mon Nov 14 22:00:30 2011
PSP0 started with pid=7, OS id=6120 
Mon Nov 14 22:00:30 2011
DIA0 started with pid=8, OS id=4528 
Mon Nov 14 22:00:30 2011
MMAN started with pid=9, OS id=6052 
Mon Nov 14 22:00:30 2011
DBW0 started with pid=10, OS id=5348 
Mon Nov 14 22:00:30 2011
LGWR started with pid=11, OS id=4904 
Mon Nov 14 22:00:30 2011
CKPT started with pid=12, OS id=5388 
Mon Nov 14 22:00:30 2011
SMON started with pid=13, OS id=4492 
Mon Nov 14 22:00:30 2011
RECO started with pid=14, OS id=576 
Mon Nov 14 22:00:30 2011
MMON started with pid=15, OS id=6072 
Mon Nov 14 22:00:30 2011
MMNL started with pid=16, OS id=5720 
ORACLE_BASE from environment = e:\oracle
Mon Nov 14 22:00:31 2011
alter database mount
ORA-00210: cannot open the specified control file
ORA-00202: control file: 'E:\ORACLE\11_2_0\DATABASE\CTL1XFF.ORA'
ORA-27041: unable to open file
OSD-04002: 无法打开文件
O/S-Error: (OS 2) 系统找不到指定的文件。
ORA-205 signalled during: alter database mount...
Mon Nov 14 22:00:33 2011
Checker run found 1 new persistent data failures

1、查看系统没有发现 C:\S5O4.1文件
2、restrict方式nomount数据库

使用rman找回被误删除表空间

一、案例说明
利用rman备份数据库后,因为人工误删除表空间,现在需要使用非完全恢复来找回被误删除的表空间

二、环境准备

[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Nov 14 12:35:14 2011

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
USERS
XFF
ODU
TEMP

7 rows selected.

SQL> select name from v$datafile;

NAME
---------------------------------------------------------------
/opt/oracle/oradata/test/system01.dbf
/opt/oracle/oradata/test/undotbs01.dbf
/opt/oracle/oradata/test/sysaux01.dbf
/opt/oracle/oradata/test/users01.dbf
/opt/oracle/oradata/test/user32g.dbf
/opt/oracle/oradata/test/xifenfei01.dbf
/opt/oracle/oradata/test/user02.dbf
/opt/oracle/oradata/test/odu02.dbf
/opt/oracle/oradata/test/odu01.dbf
/opt/oracle/oradata/test/odu03.dbf
/opt/oracle/oradata/test/xifenfei02.dbf

11 rows selected.

SQL> create tablespace xifenfei datafile 
2   '/opt/oracle/oradata/test/t_xifenfei01.dbf' size 10m ;

Tablespace created.

SQL> create table chf.t_xifenfei tablespace xifenfei 
  2  as
  3  select * from dba_objects;

Table created.


SQL> select count(*) from chf.t_xifenfei;

  COUNT(*)
----------
     50476

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@ECP-UC-DB1 ~]$ $ORACLE_HOME/bin/rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Nov 14 12:43:35 2011

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

connected to target database: TEST (DBID=2056006906)

RMAN> list backup summary;                 

using target database control file instead of recovery catalog

RMAN> backup database format '/tmp/test_full_%U';

Starting backup at 2011-11-14 12:44:32
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=134 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00008 name=/opt/oracle/oradata/test/odu02.dbf
input datafile fno=00002 name=/opt/oracle/oradata/test/undotbs01.dbf
input datafile fno=00001 name=/opt/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/opt/oracle/oradata/test/sysaux01.dbf
input datafile fno=00009 name=/opt/oracle/oradata/test/odu01.dbf
input datafile fno=00006 name=/opt/oracle/oradata/test/xifenfei01.dbf
input datafile fno=00005 name=/opt/oracle/oradata/test/user32g.dbf
input datafile fno=00007 name=/opt/oracle/oradata/test/user02.dbf
input datafile fno=00010 name=/opt/oracle/oradata/test/odu03.dbf
input datafile fno=00011 name=/opt/oracle/oradata/test/xifenfei02.dbf
input datafile fno=00012 name=/opt/oracle/oradata/test/t_xifenfei01.dbf
input datafile fno=00004 name=/opt/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2011-11-14 12:44:33
channel ORA_DISK_1: finished piece 1 at 2011-11-14 12:48:59
piece handle=/tmp/test_full_01mrkqdh_1_1 tag=TAG20111114T124433 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:04:26
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 2011-11-14 12:49:02
channel ORA_DISK_1: finished piece 1 at 2011-11-14 12:49:03
piece handle=/tmp/test_full_02mrkqlr_1_1 tag=TAG20111114T124433 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 2011-11-14 12:49:03

RMAN> exit


Recovery Manager complete.
[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Nov 14 12:50:53 2011

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> drop tablespace xifenfei including contents and datafiles;

Tablespace dropped.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@ECP-UC-DB1 ~] cd /opt/oradata
[oracle@ECP-UC-DB1 oradata]$ mv test test_bak
[oracle@ECP-UC-DB1 oradata]$ mkdir test
[oracle@ECP-UC-DB1 oradata]$ ll
total 16
drwxr-x--- 3 oracle oinstall 4096 Aug 12 21:50 ecp
drwxr-x--- 3 oracle oinstall 4096 Jun 25 14:23 ecp_bak
drwxr-xr-x 2 oracle oinstall 4096 Nov 14 12:53 test
drwxr-x--- 3 oracle oinstall 4096 Nov 14 12:51 test_bak

通过alert日志,查找出删除表空间xifenfei的时间:Mon Nov 14 12:49:102011

三、恢复测试

[oracle@ECP-UC-DB1 oradata]$ $ORACLE_HOME/bin/rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Nov 14 12:58:47 2011

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

connected to target database (not started)

RMAN> startup

Oracle instance started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 11/14/2011 12:58:56
ORA-00205: error in identifying control file, check alert log for more info

RMAN> restore controlfile from '/tmp/test_full_02mrkqlr_1_1';

Starting restore at 2011-11-14 12:59:15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/opt/oracle/oradata/test/control01.ctl
output filename=/opt/oracle/oradata/test/control02.ctl
output filename=/opt/oracle/oradata/test/control03.ctl
Finished restore at 2011-11-14 12:59:19

RMAN> restore database;

Starting restore at 2011-11-14 13:00:16
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 11/14/2011 13:00:16
ORA-01507: database not mounted

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 2011-11-14 13:00:32
Starting implicit crosscheck backup at 2011-11-14 13:00:32
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 2011-11-14 13:00:33

Starting implicit crosscheck copy at 2011-11-14 13:00:33
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2011-11-14 13:00:33

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /opt/oracle/oradata/test/system01.dbf
restoring datafile 00002 to /opt/oracle/oradata/test/undotbs01.dbf
restoring datafile 00003 to /opt/oracle/oradata/test/sysaux01.dbf
restoring datafile 00004 to /opt/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /opt/oracle/oradata/test/user32g.dbf
restoring datafile 00006 to /opt/oracle/oradata/test/xifenfei01.dbf
restoring datafile 00007 to /opt/oracle/oradata/test/user02.dbf
restoring datafile 00008 to /opt/oracle/oradata/test/odu02.dbf
restoring datafile 00009 to /opt/oracle/oradata/test/odu01.dbf
restoring datafile 00010 to /opt/oracle/oradata/test/odu03.dbf
restoring datafile 00011 to /opt/oracle/oradata/test/xifenfei02.dbf
restoring datafile 00012 to /opt/oracle/oradata/test/t_xifenfei01.dbf
channel ORA_DISK_1: reading from backup piece /tmp/test_full_01mrkqdh_1_1
   channel ORA_DISK_1: restored backup piece 1
piece handle=/tmp/test_full_01mrkqdh_1_1 tag=TAG20111114T124433
channel ORA_DISK_1: restore complete, elapsed time: 00:07:08
Finished restore at 2011-11-14 13:07:42

RMAN> run
2> {
3> sql 'alter session set nls_date_format ="yyyy-mm-dd hh24:mi:ss"';
4> set until time='2011-11-14 12:49:10';
5> recover database;
6> }

sql statement: alter session set nls_date_format ="yyyy-mm-dd hh24:mi:ss"

executing command: SET until clause

Starting recover at 2011-11-14 13:18:09
using channel ORA_DISK_1

starting media recovery

unable to find archive log
archive log thread=1 sequence=248
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/14/2011 13:18:10
RMAN-06054: media recovery requesting unknown log: thread 1 seq 248 lowscn 11517136

--另外打开一个会话查询当前最大的归档日志seq#情况
[oracle@ECP-UC-DB1 archivelog]$ ll -thr|tail -10
-rw-r----- 1 oracle oinstall  45M Nov  5 19:00 1_238_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov  7 10:00 1_239_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov  8 02:25 1_240_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov  8 22:25 1_241_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov  9 22:26 1_242_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov 10 22:01 1_243_757860476.dbf
-rw-r----- 1 oracle oinstall  46M Nov 11 22:01 1_244_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov 12 00:00 1_245_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov 13 07:26 1_246_757860476.dbf
-rw-r----- 1 oracle oinstall  45M Nov 14 07:27 1_247_757860476.dbf
--证明最大的seq为247,而恢复需要日志的seq为248,就是说需要应用未归档的redo log
--那么我们采用在sqlplus中恢复

RMAN> exit


Recovery Manager complete.


[oracle@ECP-UC-DB1 oradata]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Nov 14 13:21:24 2011

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> alter session set nls_date_format ="yyyy-mm-dd hh24:mi:ss"
  2  ;

Session altered.

SQL>  recover database until time '2011-11-14 12:49:10' using backup controlfile;
ORA-00279: change 11517136 generated at 11/14/2011 12:44:33 needed for thread 1
ORA-00289: suggestion : /opt/oracle/oradata/test/archivelog1_248_757860476.dbf
ORA-00280: change 11517136 for thread 1 is in sequence #248


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/opt/oracle/oradata/test_bak/redo01.log
ORA-00310: archived log contains sequence 247; sequence 248 required
ORA-00334: archived log: '/opt/oracle/oradata/test_bak/redo01.log'


SQL> recover database until time '2011-11-14 12:49:10' using backup controlfile;
ORA-00279: change 11517136 generated at 11/14/2011 12:44:33 needed for thread 1
ORA-00289: suggestion : /opt/oracle/oradata/test/archivelog1_248_757860476.dbf
ORA-00280: change 11517136 for thread 1 is in sequence #248


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/opt/oracle/oradata/test_bak/redo02.log
Log applied.
Media recovery complete.
SQL> alter database open resetlogs;

Database altered.

SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
USERS
XFF
ODU
TEMP
XIFENFEI

8 rows selected.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------
/opt/oracle/oradata/test/system01.dbf
/opt/oracle/oradata/test/undotbs01.dbf
/opt/oracle/oradata/test/sysaux01.dbf
/opt/oracle/oradata/test/users01.dbf
/opt/oracle/oradata/test/user32g.dbf
/opt/oracle/oradata/test/xifenfei01.dbf
/opt/oracle/oradata/test/user02.dbf
/opt/oracle/oradata/test/odu02.dbf
/opt/oracle/oradata/test/odu01.dbf
/opt/oracle/oradata/test/odu03.dbf
/opt/oracle/oradata/test/xifenfei02.dbf
/opt/oracle/oradata/test/t_xifenfei01.dbf

12 rows selected.

SQL> select count(*) from chf.t_xifenfei;

  COUNT(*)
----------
     50476

使用flashback database找回被误删除表空间

ORA-19693: backup piece %s already included

一、问题现象

RMAN> restore database;

启动 restore 于 13-11月-11
使用通道 ORA_DISK_1

通道 ORA_DISK_1: 正在开始还原数据文件备份集
通道 ORA_DISK_1: 正在指定从备份集还原的数据文件
通道 ORA_DISK_1: 将数据文件 00001 还原到 E:\ORACLE\ORADATA\XFF\SYSTEM01.DBF
通道 ORA_DISK_1: 将数据文件 00002 还原到 E:\ORACLE\ORADATA\XFF\SYSAUX01.DBF
通道 ORA_DISK_1: 将数据文件 00003 还原到 E:\ORACLE\ORADATA\XFF\UNDOTBS01.DBF
通道 ORA_DISK_1: 将数据文件 00004 还原到 E:\ORACLE\ORADATA\XFF\USERS01.DBF
通道 ORA_DISK_1: 将数据文件 00005 还原到 E:\ORACLE\ORADATA\XFF\EXAMPLE01.DBF
通道 ORA_DISK_1: 将数据文件 00006 还原到 E:\ORACLE\ORADATA\XFF\O_ORACLE.DBF
通道 ORA_DISK_1: 将数据文件 00007 还原到 E:\ORACLE\ORADATA\XFF\XIFENFEI01.DBF
通道 ORA_DISK_1: 将数据文件 00008 还原到 E:\ORACLE\ORADATA\XFF\P_TEST01.DBF
通道 ORA_DISK_1: 将数据文件 00009 还原到 E:\ORACLE\ORADATA\XFF\SYS_MG01.DBF
通道 ORA_DISK_1: 将数据文件 00010 还原到 E:\ORACLE\ORADATA\XFF\P101.DBF
通道 ORA_DISK_1: 将数据文件 00011 还原到 E:\ORACLE\ORADATA\XFF\P201.DBF
通道 ORA_DISK_1: 将数据文件 00012 还原到 E:\ORACLE\ORADATA\XFF\P301.DBF
通道 ORA_DISK_1: 将数据文件 00015 还原到 E:\ORACLE\ORADATA\XFF\OGG01.DBF
通道 ORA_DISK_1: 将数据文件 00016 还原到 E:\ORACLE\ORADATA\XFF\SPOT01.DBF
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: restore 命令 (在 11/13/2011 18:19:31 上) 失败
ORA-19693: 已包括备份片段 F:\RMANBACKUP\9_12_0GMMD2KI_1_1

RMAN> list backup summary;


备份列表
===============
关键字     TY LV S 设备类型 完成时间   段数 副本数 压缩标记
------- -- -- - ----------- ---------- ------- ------- ---------- ---
6       B  F  A DISK        12-9月 -11 1       2       NO         TAG20110912T215425
7       B  F  A DISK        12-9月 -11 1       1       NO         TAG20110912T215425
8       B  F  A DISK        12-9月 -11 1       1       NO         TAG20110912T220120

19693, 00000, "backup piece %s already included"
// *Cause:  This backup piece was already specified for inclusion in the
//          restore conversation. A restore conversation may process only
//          a single instance of a backup piece.
// *Action: Remove the specified duplicate backup piece in restore steps
//          and restart the conversation.

二、解决办法
1、查找出副本数大于1的备份集
2、重命名对应的备份集
3、使用crosscheck backup检测出无效的备份集
4、使用delete noprompt expired backup删除无效备份集
5、使用CATALOG START WITH重新添加刚刚重命名的备份集

三、问题原因
Bug 4483368: SEVERAL RMAN CATALOG START WITH CREATES DUPLICATE CATALOG ENTRIES

After several "RMAN  catalog start with "we have several copies of the same backuppiece 
in our catalog which we can see with "list backup;" and also "list backup summary;".
However, when I now try to restore with that controlfile instead of a catalog 
I receive  ORA-19693 backup piece "/opt/oracle/admin/mnt/HERMES2/bkp/..." 
is already included.

议rman的crosscheck和obsolete

今天有朋友对于crosscheck和obsolete理解的不太清楚,网上查找了一些资料,也发现很多错误,其中典型的理解就是:crosscheck 可以检测/删除违背(obsolete)备份策略的备份集

--登录rman
[oracle@node1 ~]$ $ORACLE_HOME/bin/rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Nov 8 13:39:17 2011

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

connected to target database: ECP (DBID=1669273445)

RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
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 2 BACKUP TYPE TO COMPRESSED BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 2048 M;
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/opt/oracle/product/10.2.0/db_1/dbs/snapcf_ecp.f'; # default
--发现配置的策略是保留1份

--全库备份
RMAN> list backup summary;
--当前数据库无备份集备份

RMAN> backup database format '/opt/backup/ecp_full_%U';

Starting backup at 2011-11-08 13:22:06
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=536 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=534 devtype=DISK
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=/opt/oracle/oradata/ecp/users01.dbf
input datafile fno=00003 name=/opt/oracle/oradata/ecp/sysaux01.dbf
input datafile fno=00008 name=/opt/oracle/oradata/ecp/TS_Public_1.003.dbf
input datafile fno=00009 name=/opt/oracle/oradata/ecp/TS_Index_Base.001.dbf
input datafile fno=00010 name=/opt/oracle/oradata/ecp/TS_Index_Base.002.dbf
input datafile fno=00011 name=/opt/oracle/oradata/ecp/TS_Index_Base.003.dbf
channel ORA_DISK_1: starting piece 1 at 2011-11-08 13:22:07
channel ORA_DISK_2: starting compressed full datafile backupset
channel ORA_DISK_2: specifying datafile(s) in backupset
input datafile fno=00002 name=/opt/oracle/oradata/ecp/undotbs01.dbf
input datafile fno=00001 name=/opt/oracle/oradata/ecp/system01.dbf
input datafile fno=00012 name=/opt/oracle/oradata/ecp/OGG.001.dbf
input datafile fno=00005 name=/opt/oracle/oradata/ecp/example01.dbf
input datafile fno=00006 name=/opt/oracle/oradata/ecp/TS_Public_1.001.dbf
input datafile fno=00007 name=/opt/oracle/oradata/ecp/TS_Public_1.002.dbf
channel ORA_DISK_2: starting piece 1 at 2011-11-08 13:22:07
channel ORA_DISK_1: finished piece 1 at 2011-11-08 13:22:22
piece handle=/opt/backup/ecp_full_11mr52bv_1_1 tag=TAG20111108T132207 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2011-11-08 13:22:23
channel ORA_DISK_1: finished piece 1 at 2011-11-08 13:22:24
piece handle=/opt/backup/ecp_full_13mr52ce_1_1 tag=TAG20111108T132207 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 2011-11-08 13:22:25
channel ORA_DISK_1: finished piece 1 at 2011-11-08 13:22:26
piece handle=/opt/backup/ecp_full_14mr52cg_1_1 tag=TAG20111108T132207 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_2: finished piece 1 at 2011-11-08 13:22:41
piece handle=/opt/backup/ecp_full_12mr52bv_1_1 tag=TAG20111108T132207 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:34
Finished backup at 2011-11-08 13:22:41

--备份sysdata01.dbf文件
RMAN> backup datafile 1 format '/opt/backup/ecp_system_%U';

Starting backup at 2011-11-08 13:23:44
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/opt/oracle/oradata/ecp/system01.dbf
channel ORA_DISK_1: starting piece 1 at 2011-11-08 13:23:45
channel ORA_DISK_2: starting compressed full datafile backupset
channel ORA_DISK_2: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_2: starting piece 1 at 2011-11-08 13:23:45
channel ORA_DISK_2: finished piece 1 at 2011-11-08 13:23:46
piece handle=/opt/backup/ecp_system_16mr52f1_1_1 tag=TAG20111108T132344 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_2: starting compressed full datafile backupset
channel ORA_DISK_2: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_2: starting piece 1 at 2011-11-08 13:23:47
channel ORA_DISK_2: finished piece 1 at 2011-11-08 13:23:48
piece handle=/opt/backup/ecp_system_17mr52f2_1_1 tag=TAG20111108T132344 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: finished piece 1 at 2011-11-08 13:24:13
piece handle=/opt/backup/ecp_system_15mr52f1_1_1 tag=TAG20111108T132344 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:28
Finished backup at 2011-11-08 13:24:13
--注:所有备份system空间,都是会自动备份spfile和控制文件

RMAN> list backup summary;


List of Backups
===============
Key     TY LV S Device Type Completion Time     #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
28      B  F  A DISK        2011-11-08 13:22:19 1       1       YES        TAG20111108T132207
29      B  F  A DISK        2011-11-08 13:22:23 1       1       YES        TAG20111108T132207
30      B  F  A DISK        2011-11-08 13:22:25 1       1       YES        TAG20111108T132207
31      B  F  A DISK        2011-11-08 13:22:35 1       1       YES        TAG20111108T132207
32      B  F  A DISK        2011-11-08 13:23:45 1       1       YES        TAG20111108T132344
33      B  F  A DISK        2011-11-08 13:23:47 1       1       YES        TAG20111108T132344
34      B  F  A DISK        2011-11-08 13:24:03 1       1       YES        TAG20111108T132344
--查看所有备份集情况

RMAN> crosscheck backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_11mr52bv_1_1 recid=28 stamp=766675327
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_13mr52ce_1_1 recid=29 stamp=766675343
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_14mr52cg_1_1 recid=30 stamp=766675345
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_12mr52bv_1_1 recid=31 stamp=766675327
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_system_16mr52f1_1_1 recid=32 stamp=766675425
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_system_17mr52f2_1_1 recid=33 stamp=766675427
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_system_15mr52f1_1_1 recid=34 stamp=766675425
--查看全部有效

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           29     2011-11-08 13:22:23
  Backup Piece       29     2011-11-08 13:22:23 /opt/backup/ecp_full_13mr52ce_1_1
Backup Set           30     2011-11-08 13:22:25
  Backup Piece       30     2011-11-08 13:22:25 /opt/backup/ecp_full_14mr52cg_1_1
--因为system01.dbf备份了两次,所以违背了备份策略

drwxr-xr-x  2 root    root      4096 07-12 15:54 vmdir
[root@node1 opt]# cd /opt/backup/
[root@node1 backup]# ll
总计 265356
-rw-r----- 1 oracle oinstall  47497216 11-08 13:22 ecp_full_11mr52bv_1_1
-rw-r----- 1 oracle oinstall 129433600 11-08 13:22 ecp_full_12mr52bv_1_1
-rw-r----- 1 oracle oinstall   1130496 11-08 13:22 ecp_full_13mr52ce_1_1
-rw-r----- 1 oracle oinstall     98304 11-08 13:22 ecp_full_14mr52cg_1_1
-rw-r----- 1 oracle oinstall  92012544 11-08 13:24 ecp_system_15mr52f1_1_1
-rw-r----- 1 oracle oinstall   1130496 11-08 13:23 ecp_system_16mr52f1_1_1
-rw-r----- 1 oracle oinstall     98304 11-08 13:23 ecp_system_17mr52f2_1_1
[root@node1 backup]# mv ecp_system_15mr52f1_1_1 ecp_system_15mr52f1_1_1_bak
[root@node1 backup]# ll
总计 265356
-rw-r----- 1 oracle oinstall  47497216 11-08 13:22 ecp_full_11mr52bv_1_1
-rw-r----- 1 oracle oinstall 129433600 11-08 13:22 ecp_full_12mr52bv_1_1
-rw-r----- 1 oracle oinstall   1130496 11-08 13:22 ecp_full_13mr52ce_1_1
-rw-r----- 1 oracle oinstall     98304 11-08 13:22 ecp_full_14mr52cg_1_1
-rw-r----- 1 oracle oinstall  92012544 11-08 13:24 ecp_system_15mr52f1_1_1_bak
-rw-r----- 1 oracle oinstall   1130496 11-08 13:23 ecp_system_16mr52f1_1_1
-rw-r----- 1 oracle oinstall     98304 11-08 13:23 ecp_system_17mr52f2_1_1
--对备份集中的其中一个文件重命名

RMAN> crosscheck backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_11mr52bv_1_1 recid=28 stamp=766675327
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_13mr52ce_1_1 recid=29 stamp=766675343
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_14mr52cg_1_1 recid=30 stamp=766675345
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_12mr52bv_1_1 recid=31 stamp=766675327
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_system_16mr52f1_1_1 recid=32 stamp=766675425
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_system_17mr52f2_1_1 recid=33 stamp=766675427
Crosschecked 6 objects

crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/backup/ecp_system_15mr52f1_1_1 recid=34 stamp=766675425
Crosschecked 1 objects
--发现一个无效的备份集

RMAN> list backup summary;


List of Backups
===============
Key     TY LV S Device Type Completion Time     #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
28      B  F  A DISK        2011-11-08 13:22:19 1       1       YES        TAG20111108T132207
29      B  F  A DISK        2011-11-08 13:22:23 1       1       YES        TAG20111108T132207
30      B  F  A DISK        2011-11-08 13:22:25 1       1       YES        TAG20111108T132207
31      B  F  A DISK        2011-11-08 13:22:35 1       1       YES        TAG20111108T132207
32      B  F  A DISK        2011-11-08 13:23:45 1       1       YES        TAG20111108T132344
33      B  F  A DISK        2011-11-08 13:23:47 1       1       YES        TAG20111108T132344
34      B  F  X DISK        2011-11-08 13:24:03 1       1       YES        TAG20111108T132344
--也标志为无效'X'

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           29     2011-11-08 13:22:23
  Backup Piece       29     2011-11-08 13:22:23 /opt/backup/ecp_full_13mr52ce_1_1
Backup Set           30     2011-11-08 13:22:25
  Backup Piece       30     2011-11-08 13:22:25 /opt/backup/ecp_full_14mr52cg_1_1
--策略还是显示这两个备份集违背规则

RMAN> DELETE NOPROMPT OBSOLETE;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
using channel ORA_DISK_2
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           29     2011-11-08 13:22:23
  Backup Piece       29     2011-11-08 13:22:23 /opt/backup/ecp_full_13mr52ce_1_1
Backup Set           30     2011-11-08 13:22:25
  Backup Piece       30     2011-11-08 13:22:25 /opt/backup/ecp_full_14mr52cg_1_1
deleted backup piece
backup piece handle=/opt/backup/ecp_full_13mr52ce_1_1 recid=29 stamp=766675343
deleted backup piece
backup piece handle=/opt/backup/ecp_full_14mr52cg_1_1 recid=30 stamp=766675345
Deleted 2 objects

RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
no obsolete backups found
--删除违法策略的备份集

RMAN> delete  NOPROMPT  expired backup;

using channel ORA_DISK_1
using channel ORA_DISK_2

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
34      34      1   1   EXPIRED     DISK        /opt/backup/ecp_system_15mr52f1_1_1
deleted backup piece
backup piece handle=/opt/backup/ecp_system_15mr52f1_1_1 recid=34 stamp=766675425
Deleted 1 EXPIRED objects

RMAN> crosscheck backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_11mr52bv_1_1 recid=28 stamp=766675327
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_full_12mr52bv_1_1 recid=31 stamp=766675327
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_system_16mr52f1_1_1 recid=32 stamp=766675425
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/backup/ecp_system_17mr52f2_1_1 recid=33 stamp=766675427
Crosschecked 4 objects
--删除无效的备份集

通过实验说明:crosscheck只能够检测备份集是否有效(最常见的情况就是物理上是否还存在),并且可以用它来删除失效(expired)的备份集,而不是用来删除违背备份策略(obsolete)的备份集,如果要删除违背备份策略(废弃)的备份集,需要使用obsolete操作。出现这个问题的主要原因应该是expired和obsolete翻译成中文的时候理解的出入导致。