ITPub博客

首页 > Linux操作系统 > Linux操作系统 > lsof恢复误删的文件

lsof恢复误删的文件

原创 Linux操作系统 作者:wailon 时间:2013-11-11 22:12:10 2 删除 编辑

[oracle@dg ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Sep 28 10:39:00 2013

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

10:40:10 SYS@wailon> select TABLESPACE_NAME,FILE_NAME from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ ------------------------------------------------------------
TBS_LRJ                        /u01/app/oracle/oradata/lrj.dbf                               -- 模拟要删除的文件
SYSTEM                         /u01/app/oracle/oradata/system01.dbf
SYSAUX                         /u01/app/oracle/oradata/sysaux01.dbf
UNDOTBS1                       /u01/app/oracle/oradata/undotbs01.dbf
USERS                          /u01/app/oracle/oradata/users01.dbf


10:40:51 SYS@wailon> select segment_name,owner from dba_segments where tablespace_name='TBS_LRJ';

SEGMENT_NAME                                                                      OWNER
--------------------------------------------------------------------------------- ------------------------------
UNDOTEST                                                                          SYS
REDOTEST                                                                          SYS
BBED_TEST                                                                         LRJ

10:41:01 SYS@wailon> select count(*) from redotest;

  COUNT(*)
----------
     10000

10:41:28 SYS@wailon> !rm -f /u01/app/oracle/oradata/lrj.dbf        -- 删除文件

10:41:45 SYS@wailon> !ls -lk /u01/app/oracle/oradata/lrj.dbf          -- 已删除,找不到该文件
ls: cannot access /u01/app/oracle/oradata/lrj.dbf: No such file or directory

10:41:51 SYS@wailon> insert into redotest select * from redotest where rownum<11;           -- 还可以往该文件写入数据

10 rows created.

10:42:21 SYS@wailon> commit;

Commit complete.

10:42:27 SYS@wailon> select count(*) from redotest;

  COUNT(*)
----------
     10010

10:42:36 SYS@wailon> host

[oracle@dg ~]$ lsof | grep deleted                -- 查找被删除的文件,切记此时不能关闭或重启数据库,否则将丢失文件描述符,则无法恢复。
oracle    2059    oracle  262uW     REG              252,0  961224704  525160 /u01/app/oracle/oradata/lrj.dbf (deleted)
oracle    2061    oracle  265u      REG              252,0  961224704  525160 /u01/app/oracle/oradata/lrj.dbf (deleted)
oracle    2065    oracle  260u      REG              252,0  961224704  525160 /u01/app/oracle/oradata/lrj.dbf (deleted)
oracle    5067    oracle  259u      REG              252,0  961224704  525160 /u01/app/oracle/oradata/lrj.dbf (deleted)

[oracle@dg ~]$ ps -ef | grep dbw                -- DBWR进程操作的文件就是要恢复的文件
oracle    2059     1  0 02:07 ?        00:00:10 ora_dbw0_wailon
oracle    5100  5079  0 10:43 pts/1    00:00:00 grep dbw
oracle    5100  5079  0 10:43 pts/1    00:00:00 grep dbw

[oracle@dg ~]$ ll /proc/2059/fd/* | grep lrj        -- 根据进程ID号查找文件描述符,找到具体的句柄
lrwx------ 1 oracle oinstall 64 Sep 28 10:42 /proc/2059/fd/262 -> /u01/app/oracle/oradata/lrj.dbf (deleted)

[oracle@dg ~]$
[oracle@dg ~]$ cat /proc/2059/fd/262 > /u01/app/oracle/oradata/lrj.dbf     -- 恢复文件
[oracle@dg ~]$ ll /u01/app/oracle/oradata/lrj.dbf
-rw-r--r-- 1 oracle oinstall 961224704 Sep 28 10:47 /u01/app/oracle/oradata/lrj.dbf
[oracle@dg ~]$ exit
exit

10:48:19 SYS@wailon> select count(*) from redotest;

  COUNT(*)
----------
     10010

10:48:26 SYS@wailon> alter tablespace tbs_lrj offline;        -- 测试文件是否恢复成功

Tablespace altered.

10:48:39 SYS@wailon> alter tablespace tbs_lrj online;
alter tablespace tbs_lrj online
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/u01/app/oracle/oradata/lrj.dbf'


10:48:44 SYS@wailon> recover datafile 5;
Media recovery complete.
10:48:54 SYS@wailon> alter tablespace tbs_lrj online;

Tablespace altered.

10:48:57 SYS@wailon> select count(*) from redotest;

  COUNT(*)
----------
     10010

 
以上文件恢复成功,无数据丢失。

切记:DBA或SA在执行任何命令前,必须明确该命令带来的风险,尤其是删除等不可逆的操作。否则宁可保留现状,也不要轻举妄动。

 

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

上一篇: Oracle 10g手工建库
请登录后发表评论 登录
全部评论

注册时间:2013-11-08

  • 博文量
    51
  • 访问量
    290809