solaris下使用lsof恢复删除的文件

作者 ora110 http://www.itpub.net/viewthread.php?tid=1044449

http://www.eygle.com/archives/2004/10/recover_backup_missing_datafile.html

http://hi.baidu.com/dba_dream/blog/item/0ddc3013eb60be56f919b84b.html

[@more@]

使用lsof删除恢复的文件


模拟lsof恢复删除的文件(tools.dbf):

Solaris 9 + lsof 4.77 + oracle 8.1.7

1. 数据文件由dbwr进程打开。

bash-2.05# ps -ef | grep ora_ | grep 817

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.itpub.net/viewthread.php?tid=1044449&extra=&page=1

用linux下的命令恢复的。

http://ora110.itpub.net/post/33978/445354



DB # ps -ef | grep ora_ | grep SID

oracle 817 1 0 15:56:30 ? 0:00 ora_pmon_testSID
oracle 819 1 0 15:56:30 ? 0:00 ora_dbw0_testSID
oracle 821 1 0 15:56:30 ? 0:00 ora_lgwr_testSID
oracle 823 1 0 15:56:30 ? 0:00 ora_ckpt_testSID

oracle 819 1 0 15:56:30 ? 0:00 ora_dbw0_testSID 这个dbwr 的进程号: 819

然后
# ls -alh /proc/819/fd/

可以看到删除的文件的的连接号码比如 16

cat /proc/819/fd/16 > /u01/oracle/oradata/testSID/system01.dbf

/proc内存文件系统中还有那个文件的inode块,所以可以恢复回来.

也就是说,这个文件(system01.dbf) inode块没有被其他新文件覆盖的话,都是可以恢复的 ?

如果在误删除之后,这个误删除的文件inode又被其他新建立的文件覆盖inode , 那么是没有办法回复的 ?

还好以后对这台DB都没有任何操作,也没有产生任何归档等 。

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

我们的情况是这样的,system01.dbf 文件被删除之后,恢复回来之前还有一个归档生成(相当于切换redo log),这时候dbwr进程还是读写system01.dbf 文件所在的inode ,block (数据库没有close), 其他的新建文件(假设)不能覆盖它的inode, block , 应该可以找到吧 ?

找到文件的方式还有一种:

[oracle@eslhdb01 proc]$ ps -ef | grep ora_dbwr*
oracle 23603 1 0 Aug23 ? 00:05:59 ora_dbw0_eslhdb01
oracle 21354 21287 0 17:15 pts/3 00:00:00 grep ora_dbwr*


[oracle@eslhdb01 proc]$ cd 23603/
[oracle@eslhdb01 23603]$ cd fd/
[oracle@eslhdb01 fd]$ ls -alh


[oracle@eslhdb01 fd]$ ls -alh
total 0
dr-x------ 2 oracle dba 0 Aug 27 17:15 .
dr-xr-xr-x 3 oracle dba 0 Aug 27 17:15 ..
lr-x------ 1 oracle dba 64 Aug 27 17:16 0 -> /dev/null
lr-x------ 1 oracle dba 64 Aug 27 17:16 1 -> /dev/null
lr-x------ 1 oracle dba 64 Aug 27 17:16 10 -> /u01/product/oracle/rdbms/mesg/oraus.msb
lrwx------ 1 oracle dba 64 Aug 27 17:16 11 -> /u01/product/oracle/rdbms/audit/ora_10152.aud
lrwx------ 1 oracle dba 64 Aug 27 17:16 15 -> /data/product/oradata/eslhdb0/control03.ctl
lrwx------ 1 oracle dba 64 Aug 27 17:16 16 -> /u01/product/oradata/eslhdb0/system01.dbf (deleted)
lrwx------ 1 oracle dba 64 Aug 27 17:16 17 -> /data/product/oradata/eslhdb0/undotbs02.dbf

可以看到 (deleted)标示的文件在闪烁 。 是一个软链接文件, 号码 16 指向它 。
通过
cat /proc/23603/fd/16 >/data/bak/system01.dbf


注意: 不要恢复到system01.dbf文件的原目录地点 。先恢复到某个bak目录,然后拷贝过去。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/271283/viewspace-1057040/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/271283/viewspace-1057040/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值