Linux下使用lsof恢復刪除的檔案

tolywang發表於2008-08-26

使用lsof刪除恢復的檔案


模擬lsof恢復刪除的檔案(tools.dbf):

Solaris 9 + lsof 4.77 + oracle 8.1.7

1. 資料檔案由dbwr程式開啟。

bash-2.05# ps -ef | grep ora_ | grep 817          (其中test表示sid)

oracle 817 1 0 15:56:30 ? 0:00 ora_pmon_test817

oracle 819 1 0 15:56:30 ? 0:00 ora_dbw0_test817

oracle 821 1 0 15:56:30 ? 0:00 ora_lgwr_test817

oracle 823 1 0 15:56:30 ? 0:00 ora_ckpt_test817

oracle 825 1 0 15:56:31 ? 0:01 ora_smon_test817

oracle 827 1 0 15:56:31 ? 0:00 ora_reco_test817

oracle 829 1 0 15:56:31 ? 0:00 ora_snp0_test817

oracle 831 1 0 15:56:31 ? 0:00 ora_snp1_test817

oracle 833 1 0 15:56:31 ? 0:00 ora_snp2_test817

oracle 835 1 0 15:56:31 ? 0:00 ora_snp3_test817

oracle 837 1 0 15:56:31 ? 0:00 ora_s000_test817

oracle 839 1 0 15:56:31 ? 0:00 ora_d000_test817

oracle 841 1 0 15:56:31 ? 0:00 ora_arc0_test817

2. 列出dbwr程式開啟的資料檔案

bash-2.05# lsof -a -p 819 -d ^txt | egrep "COMMAND|dbf"

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

oracle 819 oracle *200uW VREG 32,4 10493952 22545 /u01/oracle/oradata/test817/garychen01.dbf

oracle 819 oracle *201uW VREG 32,4 104865792 22544 /u01/oracle/oradata/test817/test01.dbf

oracle 819 oracle *202uW VREG 32,4 88088576 22563 /u01/oracle/oradata/test817/drsys01.dbf

oracle 819 oracle *203uW VREG 32,4 56631296 22560 /u01/oracle/oradata/test817/indx01.dbf

oracle 819 oracle *204uW VREG 32,4 109060096 22559 /u01/oracle/oradata/test817/users01.dbf

oracle 819 oracle *205uW VREG 32,4 71311360 22558 /u01/oracle/oradata/test817/temp01.dbf

oracle 819 oracle *206uW VREG 32,4 541073408 22557 /u01/oracle/oradata/test817/rbs01.dbf

oracle 819 oracle *207uW VREG 32,4 8396800 22556 /u01/oracle/oradata/test817/tools01.dbf

oracle 819 oracle *208uW VREG 32,4 283123712 22555 /u01/oracle/oradata/test817/system01.dbf

3.刪除tools.dbf資料檔案

bash-2.05# rm /u01/oracle/oradata/test817/tools01.dbf

4. Solaris 中,刪除的檔案將顯示檔案所在的磁碟的名稱

bash-2.05# lsof -a -p 819 -d ^txt

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

oracle 819 oracle cwd VDIR 32,11 512 158092 /u03/oracle/product/8.1.7/dbs

oracle 819 oracle 0r VCHR 13,2 0t0 281623 /devices/pseudo/mm@0:null

oracle 819 oracle 1r VCHR 13,2 0t0 281623 /devices/pseudo/mm@0:null

oracle 819 oracle 2r VCHR 13,2 0t0 281623 /devices/pseudo/mm@0:null

oracle 819 oracle 3r VCHR 13,2 0t0 281623 /devices/pseudo/mm@0:null

oracle 819 oracle 4r VCHR 13,2 0t0 281623 /devices/pseudo/mm@0:null

oracle 819 oracle 5r VCHR 13,2 0t0 281623 /devices/pseudo/mm@0:null

oracle 819 oracle 6w VREG 32,11 43794 171624 /u03/oracle/admin/test817/bdump/alert_test817.log

oracle 819 oracle 7r VCHR 24,3 0t0 281702 /devices/pseudo/pts@0:3->ttcompat->ldterm->ptem->pts

oracle 819 oracle 8w VREG 32,11 43794 171624 /u03/oracle/admin/test817/bdump/alert_test817.log

oracle 819 oracle 9r DOOR 268,0 0t0 58 /var/run (swap) (door to nscd[269])

oracle 819 oracle 10r VREG 32,11 358912 84962 /u03/oracle/product/8.1.7/rdbms/mesg/oraus.msb

oracle 819 oracle 11u VREG 32,11 1124 171764 /u03/oracle/product/8.1.7/rdbms/audit/ora_815.aud

oracle 819 oracle 12uR VREG 32,11 24 158548 /u03/oracle/product/8.1.7/dbs/lkTEST817

oracle 819 oracle *200uW VREG 32,4 10493952 22545 /u01/oracle/oradata/test817/garychen01.dbf

oracle 819 oracle *201uW VREG 32,4 104865792 22544 /u01/oracle/oradata/test817/test01.dbf

oracle 819 oracle *202uW VREG 32,4 88088576 22563 /u01/oracle/oradata/test817/drsys01.dbf

oracle 819 oracle *203uW VREG 32,4 56631296 22560 /u01/oracle/oradata/test817/indx01.dbf

oracle 819 oracle *204uW VREG 32,4 109060096 22559 /u01/oracle/oradata/test817/users01.dbf

oracle 819 oracle *205uW VREG 32,4 71311360 22558 /u01/oracle/oradata/test817/temp01.dbf

oracle 819 oracle *206uW VREG 32,4 541073408 22557 /u01/oracle/oradata/test817/rbs01.dbf

oracle 819 oracle *207uW VREG 32,4 8396800 22556 /u01 (/dev/dsk/c1t0d0s4)

oracle 819 oracle *208uW VREG 32,4 283123712 22555 /u01/oracle/oradata/test817/system01.dbf

oracle 819 oracle *209u VREG 32,4 4431872 22551 /u01/oracle/oradata/test817/control03.ctl

oracle 819 oracle *210u VREG 32,4 4431872 22550 /u01/oracle/oradata/test817/control02.ctl

oracle 819 oracle *211u VREG 32,4 4431872 22549 /u01/oracle/oradata/test817/control01.ctl

5.檢視/proc檔案系統

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

bash-2.05# ls /proc/819/fd/*207

/proc/819/fd/26207

cat /proc/819/fd/26207 > /u01/oracle/oradata/test817/tools01.dbf

chown oracle:dba /u01/oracle/oradata/test817/tools01.dbf

6. 驗證檔案已經恢復了。

Sqlplus> alter system checkpoint;

參考:
http://www.ibm.com/developerworks/cn/aix/library/au-lsof.html#listing2

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

相關文章