備份恢復之資料檔案丟失

蘭在晨發表於2012-06-14

一、實驗環境

執行環境:

[root@localhost ~]# lsb_release -a

LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch

Distributor ID: RedHatEnterpriseServer

Description:    Red Hat Enterprise Linux Server release 5.4 (Tikanga)

Release:        5.4

Codename:       Tikanga

資料庫版本:

SQL> select * from v$version;

 

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

PL/SQL Release 10.2.0.1.0 - Production

CORE    10.2.0.1.0      Production

TNS for Linux: Version 10.2.0.1.0 - Production

NLSRTL Version 10.2.0.1.0 - Production

歸檔狀態:

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

二、實驗步驟

     1、對資料庫進行一次全備

     2、將資料庫檔案任一刪除一個(system表空間的資料檔案或者undo表空間的資料檔案)

    3、通過RMAN對進行恢復

 三、具體過程

1、檢視資料檔案

 

SQL>  select t.name tname,d.name dname from v$datafile d,v$tablespace t

  2   where t.ts#=d.ts#;

 

TNAME   DNAME

------- ------------------------------------------------------------

SYSTEM  /u01/app/oracle/oradata/lzcdb/system01.dbf

UNDOTBS /u01/app/oracle/oradata/lzcdb/undotbs01.dbf

1

 

SYSAUX  /u01/app/oracle/oradata/lzcdb/sysaux01.dbf

USERS   /u01/app/oracle/oradata/lzcdb/users01.dbf

LZCDB01 /u01/app/oracle/oradata/lzcdb/lzcdb0101

LZCDB01 /u01/app/oracle/oradata/lzcdb/lzcdb0102

2、將控制檔案刪除

SQL> !rm /u01/app/oracle/oradata/lzcdb/system01.dbf

SQL> !ls /u01/app/oracle/oradata/lzcdb/system01.dbf

ls: /u01/app/oracle/oradata/lzcdb/system01.dbf: No such file or directory

成功刪除

3、在刪除資料檔案之後資料庫有可能會直接掛掉,但由於我的實驗資料庫沒有任何負載所以現在手動將其關閉

     (注意同時動態檢視alert日子)

 

SQL> shutdown abort;

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              96470608 bytes

Database Buffers          184549376 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 1 - see DBWR trace file

ORA-01110: data file 1: '/u01/app/oracle/oradata/lzcdb/system01.dbf'

在有mount狀態啟動到open狀態是會出現如上錯誤,此時檢視alert日誌會看到如下資訊

ALTER DATABASE OPEN

Thu Jun 14 17:25:03 2012

ORA-01110: data file 1: '/u01/app/oracle/oradata/lzcdb/system01.dbf'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

我們可以看到錯誤資訊提示我們system01.dbf檔案找不到

4、使用RMAN恢復

[oracle@localhost ~]$ rman target sys/oracle/lzcdb

 

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jun 14 17:28:33 2012

 

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

 

connected to target database: LZCDB (DBID=404353836, not open)

 

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

------- ---- -- ---------- ----------- ------------ ---------------

3       Full    920.27M    DISK        00:01:58     14-JUN-12

        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20120614T091107

        Piece Name: /u01/app/oracle/flash_recovery_area/03ndgj9b_1_1

  List of Datafiles in backup set 3

  File LV Type Ckp SCN    Ckp Time  Name

  ---- -- ---- ---------- --------- ----

  1       Full 682642     14-JUN-12 /u01/app/oracle/oradata/lzcdb/system01.dbf

  2       Full 682642     14-JUN-12 /u01/app/oracle/oradata/lzcdb/undotbs01.dbf

  3       Full 682642     14-JUN-12 /u01/app/oracle/oradata/lzcdb/sysaux01.dbf

  4       Full 682642     14-JUN-12 /u01/app/oracle/oradata/lzcdb/users01.dbf

可以看到我的實驗庫的備份資訊如上

RMAN> restore datafile 1;          ------這兒我用的是system01.dbf檔案號

RMAN> recover database;           

將資料庫啟動!

四、實驗總結

 在實驗的過程中遇到了一些小插曲,由於自己搗鼓的時候有部分歸檔日誌被我刪掉了卻且沒有其他備份。

所以當我執行

RMAN> recover database;   

恢復資料庫時告訴我

 

RMAN-03002: failure of recover command at 06/14/2012 18:18:06

RMAN-06053: unable to perform. media recovery because of missing log

RMAN-06025: no backup of log thread 1 seq 36 lowscn 730729 found to restore

這樣我就只能將整個資料庫恢復到我上次的全備點了,這就造成了大量資料的丟失

所以體會就是歸檔日誌不要隨便刪除,除非你已經確定它沒有用了或者你有備份!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26723566/viewspace-732848/,如需轉載,請註明出處,否則將追究法律責任。

相關文章