(1)備份數據庫sql
在使用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 backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf input datafile file number=00009 name=/u01/app/oracle/oradata/orcl/mark.bdf input datafile file number=00011 name=/u01/app/oracle/oradata/orcl/tbs01.bdf input datafile file number=00012 name=/u01/app/oracle/oradata/orcl/tbs03.dbf input datafile file number=00013 name=/u01/app/oracle/oradata/orcl/tbs04.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 16-MAY-18 channel ORA_DISK_1: finished piece 1 at 16-MAY-18 piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/01t31soh_1_1 tag=TAG20180516T144121 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:02:33 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00008 name=/u01/app/oracle/oradata/orcl/tbs_32k.dbf channel ORA_DISK_1: starting piece 1 at 16-MAY-18 channel ORA_DISK_1: finished piece 1 at 16-MAY-18 piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/02t31sta_1_1 tag=TAG20180516T144121 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 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 including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 16-MAY-18 channel ORA_DISK_1: finished piece 1 at 16-MAY-18 piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/03t31stc_1_1 tag=TAG20180516T144121 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 16-MAY-18
(2)刪除數據文件oracle
查看數據庫的數據文件信息:app
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 FILE# ------------------------------ -------------------------------------------------------------------------------- ---------- SYSTEM /u01/app/oracle/oradata/orcl/system01.dbf 1 SYSAUX /u01/app/oracle/oradata/orcl/sysaux01.dbf 2 UNDOTBS1 /u01/app/oracle/oradata/orcl/undotbs01.dbf 3 USERS /u01/app/oracle/oradata/orcl/users01.dbf 4 EXAMPLE /u01/app/oracle/oradata/orcl/example01.dbf 5 TBS_32K /u01/app/oracle/oradata/orcl/tbs_32k.dbf 8 MARK /u01/app/oracle/oradata/orcl/mark.bdf 9 TBS01 /u01/app/oracle/oradata/orcl/tbs01.bdf 11 TBS03 /u01/app/oracle/oradata/orcl/tbs03.dbf 12 TBS04 /u01/app/oracle/oradata/orcl/tbs04.dbf 13 10 rows selected
刪除一個數據文件,這裏把文件編號爲13的數據文件給刪除:this
[oracle@redhat6 ~]$ rm -f /u01/app/oracle/oradata/orcl/tbs04.dbf
(3)恢復數據文件spa
(3.1)使用list failure查看失敗操做rest
RMAN> list failure; List of Database Failures ========================= Failure ID Priority Status Time Detected Summary ---------- -------- --------- ------------- ------- 8 HIGH OPEN 16-MAY-18 One or more non-system datafiles need media recovery 42 HIGH OPEN 13-DEC-17 One or more non-system datafiles are missing
(3.2)使用RMAN建議來恢復丟失的文件code
RMAN> advise failure 2> ; List of Database Failures ========================= Failure ID Priority Status Time Detected Summary ---------- -------- --------- ------------- ------- 8 HIGH OPEN 16-MAY-18 One or more non-system datafiles need media recovery 42 HIGH OPEN 13-DEC-17 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 restored the wrong version of data file /u01/app/oracle/oradata/orcl/tbs04.dbf, then replace it with the correct one 2. If file /u01/app/oracle/oradata/orcl/tbs04.dbf was unintentionally renamed or moved, restore it Automated Repair Options ======================== Option Repair Description ------ ------------------ 1 Restore and recover datafile 13; Recover datafile 13 Strategy: The repair includes complete media recovery with no data loss Repair script: /u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_1931299378.hm
最後一行給出了恢復的腳本,查看腳本blog
[oracle@redhat6 ~]$ more /u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_1931299378.hm # restore and recover datafile sql 'alter database datafile 13 offline'; restore datafile 13; recover datafile 13; sql 'alter database datafile 13 online'; # recover datafile sql 'alter database datafile 13 offline'; recover datafile 13; sql 'alter database datafile 13 online';
根據腳本,執行修復和恢復ip
RMAN> sql 'alter database datafile 13 offline'; sql statement: alter database datafile 13 offline RMAN> restore datafile 13; Starting restore at 16-MAY-18 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 00013 to /u01/app/oracle/oradata/orcl/tbs04.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/product/11.2.0/db_1/dbs/01t31soh_1_1 channel ORA_DISK_1: piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/01t31soh_1_1 tag=TAG20180516T144121 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:03 Finished restore at 16-MAY-18 RMAN> recover datafile 13; Starting recover at 16-MAY-18 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 16-MAY-18 RMAN> sql 'alter database datafile 13 online'; sql statement: alter database datafile 13 online
(4)重啓數據庫,確認無異常
SQL> shutdown immediate; Database closed. Database 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 bytes Database mounted. Database opened.
完結。