lsof恢復oracle誤刪除檔案

jst143發表於2013-02-28
8.1 檢視ORACLE執行的程式

[oracle@xml-ora1 ~]$ uname -a

Linux xml-ora1 2.6.18-194.el5 #1 SMP TueMar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

[oracle@xml-ora1 ~]$ cat /etc/redhat-release

Red Hat Enterprise Linux Server release 5.5(Tikanga)


[oracle@xml-ora1 ~]$ ps -ef | grep ora_

oracle  23923 23896  0 09:43 pts/3    00:00:00 grep ora_

oracle  25342     1  0 Aug06 ?        00:00:52 ora_pmon_xmlgis

oracle  25344     1  0 Aug06 ?        00:00:00 ora_psp0_xmlgis

oracle  25346     1  0 Aug06 ?        00:00:00 ora_mman_xmlgis

oracle   25348     1  0Aug06 ?        00:00:13 ora_dbw0_xmlgis

8.2 建立測試環境

建立表空間、表、資料以及資料檔案:

SQL> create tablespace test_del datafile '/u01/app/oracle/oradata/xmlgis/test_del.dbf'size 50m;

Tablespace created.


SQL> select file_name from dba_data_files where file_name like'%del%';

FILE_NAME

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

/u01/app/oracle/oradata/xmlgis/test_del.dbf


SQL> select name from v$datafile where name like '%del%';

NAME

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

/u01/app/oracle/oradata/xmlgis/test_del.dbf



SQL> create table test_del  tablespace test_del  as select * from dba_objects;

Table created.


SQL> commit;

Commit complete.


SQL> alter system checkpoint;

System altered.


SQL> select count(*) from test_del;

COUNT(*)

----------

    51459


SQL>select OWNER,OBJECT_NAME from test_del WHERE  OWNER<>'SYS' AND ROWNUM<3;

OWNER        OBJECT_NAME

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

PUBLIC          DUAL

PUBLIC          SYSTEM_PRIVILEGE_MAP


[oracle@xml-ora1 ~]$ strings/u01/app/oracle/oradata/xmlgis/test_del.dbf | grep"SYSTEM_PRIVILEGE_MAP"

SYSTEM_PRIVILEGE_MAP

I_SYSTEM_PRIVILEGE_MAP

SYSTEM_PRIVILEGE_MAP

8.3 檢視dbwr0開啟的資料檔案

[oracle@xml-ora1 ~]$ lsof -a -p 25348 -d ^txt | egrep"COMMAND|dbf"

     Output information may be incomplete.

COMMAND  PID   USER   FD  TYPE DEVICE       SIZE      NODE NAME

oracle 25348 oracle   18uW  REG   8,8  566239232 105186656 /u01/app/oracle/oradata/xmlgis/system01.dbf

…..省略其它檔案…..

oracle 25348 oracle   48uW REG     8,8   52436992 21364739 /u01/app/oracle/oradata/xmlgis/test_del.dbf

8.4 刪除test_del.dbf資料檔案

SQL> !

[oracle@xml-ora1 ~]$ ll/u01/app/oracle/oradata/xmlgis/test_del.dbf

-rw-r----- 1 oracle oinstall 52436992 Sep20 14:17 /u01/app/oracle/oradata/xmlgis/test_del.dbf


[oracle@xml-ora1 ~]$ rm/u01/app/oracle/oradata/xmlgis/test_del.dbf


[oracle@xml-ora1 ~]$ ll/u01/app/oracle/oradata/xmlgis/test_del.dbf

ls:/u01/app/oracle/oradata/xmlgis/test_del.dbf: No such file or directory


[oracle@xml-ora1 ~]$ exit

Exit

SQL> select file_name from dba_data_files where file_name like'%del%';

FILE_NAME

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

/u01/app/oracle/oradata/xmlgis/test_del.dbf


SQL> select name from v$datafile where name like '%del%';

NAME

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

/u01/app/oracle/oradata/xmlgis/test_del.dbf


SQL> insert into test_del select * from dba_objects;

51459 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from test_del;

COUNT(*)

----------

102918

SQL> alter system checkpoint;

System altered.


SQL> create table test_del_new tablespace test_del  as select * from dba_objects;

Table created.


操作正常,說明資料檔案雖然被刪除,但是可以繼續寫入,說明可以恢復。但是注意,不能關掉DBWR0進行,重新啟動後將丟失檔案描述符,則無法恢復。

8.5 刪除檔案描述符查詢

[oracle@xml-ora1 ~]$ lsof | grep test_del

oracle   25348    oracle  48uW     REG                8,8   52436992 21364739 /u01/app/oracle/oradata/xmlgis/test_del.dbf (deleted)

oracle   25350    oracle   30u     REG                8,8   52436992 21364739 /u01/app/oracle/oradata/xmlgis/test_del.dbf (deleted)

oracle   25356    oracle   45u     REG                8,8   52436992 21364739 /u01/app/oracle/oradata/xmlgis/test_del.dbf (deleted)

oracle   25358    oracle   44u     REG                8,8   52436992 21364739 /u01/app/oracle/oradata/xmlgis/test_del.dbf (deleted)

oracle   32244    oracle   15u     REG                8,8   52436992 21364739 /u01/app/oracle/oradata/xmlgis/test_del.dbf (deleted)

oracle   32244    oracle   19u     REG                8,8   52436992 21364739 /u01/app/oracle/oradata/xmlgis/test_del.dbf (deleted)

注意:/u01/app/oracle/oradata/xmlgis/test_delete.dbf(deleted)說明該資料庫檔案被刪除了,但是卻出現了這麼多是描述符號。仔細看了下其中的資訊,發現PID為25348的才是DBWR0進行寫入的檔案,同時48uW也說明了是原來刪除的檔案,那其它資訊呢,根據PID去查詢程式。得到如下資訊

[oracle@xml-ora1 ~]$ ps -ef | egrep"25348|25350|25356|25358|32244" | grep -v egrep

oracle   25348     1  0Aug06 ?        00:00:13 ora_dbw0_xmlgis

oracle  25350     1  0 Aug06 ?        00:00:22 ora_dbw1_xmlgis

oracle  25356     1  0 Aug06 ?        00:02:29 ora_ckpt_xmlgis

oracle  25358     1  0 Aug06 ?        00:01:33 ora_smon_xmlgis

oracle  32244 32243  0 12:58 ?        00:00:03 oraclexmlgis(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

原來除了DBWR0對該程式進行讀寫,還包括DBWR1,CKPT,SMON以及我當前連線的session進行讀寫。哪個才是要恢復的檔案呢?

8.6 檢視/proc檔案系統

Cd /proc/819/fd/ 就可以得到所要查詢的資料

[oracle@xml-ora1 ~]$ ll /proc/25348/fd/* | grep test_del

lrwx------ 1 oracle oinstall 64 Sep 2014:15 /proc/25348/fd/48-> /u01/app/oracle/oradata/xmlgis/test_del.dbf (deleted)

看來他們都是對同一個檔案進行開啟,只是返回的值不同而且,而真正開啟該檔案的是DBWR0,恢復該檔案即可。


驗證檔案內容:

[oracle@xml-ora1 ~]$ strings /proc/25348/fd/48 | grep"TEST_DEL"

TEST_DEL

TEST_DEL

TEST_DEL

TEST_DEL_NEW

TEST_DEL

8.7 恢復誤刪除檔案

[oracle@xml-ora1 ~]$ cat /proc/25348/fd/48>/u01/app/oracle/oradata/xmlgis/test_del.dbf

[oracle@xml-ora1 ~]$ ll/u01/app/oracle/oradata/xmlgis/test_del.dbf

-rw-r--r-- 1 oracle oinstall 52436992 Sep20 14:45 /u01/app/oracle/oradata/xmlgis/test_del.dbf

8.8 驗證檔案恢復

新建表在此表空間:

SQL> create table test_del_recover tablespace test_del  as select * from dba_objects;

Table created.

SQL> alter system checkpoint;

System altered.

SQL> !

[oracle@xml-ora1 ~]$ ll/u01/app/oracle/oradata/xmlgis/test_del.dbf

-rw-r--r-- 1 oracle oinstall 52436992 Sep20 14:45 /u01/app/oracle/oradata/xmlgis/test_del.dbf

[oracle@xml-ora1 ~]$ strings /proc/25348/fd/48 | grep"TEST_DEL"

TEST_DEL

TEST_DEL

TEST_DEL

TEST_DEL_NEW

TEST_DEL

TEST_DEL_RECOVER

TEST_DEL_NEW

TEST_DEL


附:全文連結:http://blog.csdn.net/java3344520/article/details/8000617

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

相關文章