(1)备份数据库
在使用RMAN进行数据库恢复之前,先用RMAN进行全库备份
[oracle@redhat6 ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Wed May 16 14:32:54 2018 Copyright (c) 1982,2009,Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1486787650) RMAN> backup database; Starting backup at 16-MAY-18 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile set channel ORA_DISK_1: specifying datafile(s) in input datafile file number00001 name=/u01/app/oracle/oradata/orcl/system01.dbf input datafile 00002 namesysaux01.dbf input datafile 00003 nameundotbs01.dbf input datafile 00005 nameexample01.dbf input datafile 00009 namemark.bdf input datafile 00011 nametbs01.bdf input datafile 00012 nametbs03.dbf input datafile 00013 nametbs04.dbf input datafile 00004 nameusers01.dbf channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece piece handle/product/0/db_1/dbs/01t31soh_1_1 tag=TAG20180516T144121 comment=NONE channel ORA_DISK_1: set complete,elapsed time: 00:02:33 channel ORA_DISK_1: starting 00008 nametbs_32k.dbf channel ORA_DISK_1: starting piece /02t31sta_1_1 tag01 including current control file current SPFILE channel ORA_DISK_1: starting piece /03t31stc_1_1 tag Finished 18
select t."NAME",d."NAME",d."FILE#" from v$tablespace t,v$datafile d where t."TS#" d."TS#" order by t.ts#; NAME NAME # ------------------------------ -------------------------------------------------------------------------------- ---------- SYSTEM /u01/system01.dbf 1 SYSAUX /sysaux01.dbf 2 UNDOTBS1 /undotbs01.dbf 3 USERS /users01.dbf 4 EXAMPLE /example01.dbf 5 TBS_32K /tbs_32k.dbf 8 MARK /mark.bdf 9 TBS01 /tbs01.bdf 11 TBS03 /tbs03.dbf 12 TBS04 /tbs04.dbf 13 10 rows selected
]$ rm -f /tbs04.dbf
(3)恢复数据文件
(3.1)使用list failure查看失败操作
RMAN> list failure; List of Database Failures ========================= Failure ID Priority Status Time Detected Summary -------- -------- --------- ------------- ------- 8 HIGH OPEN 18 One or more non-system datafiles need media recovery 42 HIGH 13DEC17 One -system datafiles are missing
(3.2)使用RMAN建议来恢复丢失的文件
RMAN advise failure 2 ; List 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 restored the wrong version of data /tbs04.dbf,then replace it with the correct one 2. If /tbs04.dbf was unintentionally renamed or moved,1)">restore it Automated Repair Options ======================== Option Repair Description ---- ------------------ 1 Restore and recover datafile 13; Recover datafile 13 Strategy: The repair includes complete media recovery no data loss Repair script: /u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_1931299378.hm
最后一行给出了恢复的脚本,查看脚本
]$ more /diag/rdbms/hmreco_1931299378.hm # restore and recover datafile sql 'alter database datafile 13 offline'; restore datafile ; recover datafile ; sql alter database datafile 13 online; # recover datafile sql ';
根据脚本,执行修复和恢复
RMAN> sql '; sql statement: alter database datafile offline RMAN> 13; Starting restore at using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile set channel ORA_DISK_1: specifying datafile(s) to restore from channel ORA_DISK_1: restoring datafile 00013 to tbs04.dbf channel ORA_DISK_1: reading backup piece 01t31soh_1_1 channel ORA_DISK_1: piece handleTAG20180516T144121 channel ORA_DISK_1: restored channel ORA_DISK_1: restore complete,1); font-weight: bold">03 RMAN> recover datafile 13; Starting recover at using channel ORA_DISK_1 starting media recovery media recovery complete,elapsed time: 00 Finished recover at 13 online
(4)重启数据库,确认无异常
sql> shutdown immediate; closed. dismounted. ORACLE instance shut down. sql startup ORACLE instance started. Total System Global Area 730714112 bytes Fixed Size 2216944 bytes Variable Size 314575888 bytes Database Buffers 411041792 bytes Redo Buffers 2879488 mounted. Database opened.
完结。