Linux下利用文件描述符恢复的成功失败实验

Posted 空白葛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下利用文件描述符恢复的成功失败实验相关的知识,希望对你有一定的参考价值。

1、测试环境准备
[[email protected] ~]$ uname -a
Linux redhat3 2.6.32-573.el6.x86_64 #1 SMP Wed Jul 1 18:23:37 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]$ sqlplus / as sysdba
set pagesize 999

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 16 05:13:19 2018

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


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

SQL> SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production


创建专门的表空间、用户和数据表,用于进行试验。
create tablespace rmdtest datafile ‘/u01/app/oracle/oradata/inf/rmdtest01.dbf‘ size 50m extent management local uniform size 1m segment space management auto;

create user rmtest identified by rmtest default tablespace rmdtest;
grant resource, connect to rmtest;
grant select any dictionary to rmtest;

conn rmtest/rmtest
create table rm_tab as select * from dba_objects;
insert into rm_tab select * from rm_tab;

select tablespace_name, bytes/1024/1024 M from dba_segments where owner=‘RMTEST‘ and segment_name=‘RM_TAB‘;

2、开始实验
删除数据文件。
[[email protected] inf]$ rm rmdtest01.dbf

删除之后,借助文件描述符,我们还是可以查询的。
SQL> SQL> select count(*) from rmtest.rm_tab;

COUNT(*)
----------
173304
查找dbwr进程,确定进程编号。
[[email protected] inf]$ ps -ef | grep dbw
oracle 2537 1 0 04:24 ? 00:00:00 ora_dbw0_inf
oracle 3313 2925 0 05:33 pts/0 00:00:00 grep dbw
使用lsof –p确定文件描述符信息。
[[email protected] inf]$ lsof -p 2537
oracle 2537 oracle 256u REG 253,0 10043392 651611 /u01/app/oracle/oradata/inf/control01.ctl
oracle 2537 oracle 257u REG 253,0 10043392 651613 /u01/app/oracle/fast_recovery_area/inf/control02.ctl
oracle 2537 oracle 258uW REG 253,0 817897472 651602 /u01/app/oracle/oradata/inf/system01.dbf
oracle 2537 oracle 259uW REG 253,0 566239232 651604 /u01/app/oracle/oradata/inf/sysaux01.dbf
oracle 2537 oracle 260uW REG 253,0 471867392 651606 /u01/app/oracle/oradata/inf/undotbs01.dbf
oracle 2537 oracle 261uW REG 253,0 9183232 651608 /u01/app/oracle/oradata/inf/users01.dbf
oracle 2537 oracle 262uW REG 253,0 2252349440 655877 /u01/app/oracle/oradata/inf/inf01.dbf
oracle 2537 oracle 264uW REG 253,0 81797120 651634 /u01/app/oracle/oradata/inf/temp01.dbf
oracle 2537 oracle 265uW REG 253,0 52436992 657854 /u01/app/oracle/oradata/inf/rmdtest01.dbf (deleted)

注意:lsof是描述文件描述符最好的工具,其中包括FD列。我们从dbwr的连接中,找到了rmdtest01.dbf的信息行。其中FD=265uW。这个265就表示了连接文件的名称。
联合dbwr的进程编号2537,我们在目录/proc/2537/fd中找到所有的文件符。
[[email protected] inf]$ cd /proc/2537/fd
[[email protected] fd]$
[[email protected] fd]$ pwd
/proc/2537/fd
[[email protected] fd]$ ls -l
total 0
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Mar 16 05:35 1 -> /dev/null
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 10 -> /u01/app/oracle/11.2.0.4/dbs/lkINF
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 11 -> /u01/app/oracle/11.2.0.4/rdbms/mesg/oraus.msb
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 12 -> socket:[20147]
l-wx------ 1 oracle oinstall 64 Mar 16 05:35 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 256 -> /u01/app/oracle/oradata/inf/control01.ctl
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 257 -> /u01/app/oracle/fast_recovery_area/inf/control02.ctl
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 258 -> /u01/app/oracle/oradata/inf/system01.dbf
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 259 -> /u01/app/oracle/oradata/inf/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 260 -> /u01/app/oracle/oradata/inf/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 261 -> /u01/app/oracle/oradata/inf/users01.dbf
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 262 -> /u01/app/oracle/oradata/inf/inf01.dbf
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 264 -> /u01/app/oracle/oradata/inf/temp01.dbf
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 265 -> /u01/app/oracle/oradata/inf/rmdtest01.dbf (deleted)
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 5 -> /dev/null
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 6 -> /u01/app/oracle/11.2.0.4/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 7 -> /proc/2537/fd
lr-x------ 1 oracle oinstall 64 Mar 16 05:35 8 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Mar 16 05:35 9 -> /u01/app/oracle/11.2.0.4/dbs/hc_inf.dat

这个265对应的文件还存在,就是已经被删除的那个rmdtest01.dbf文件。进行拷贝出来。
[[email protected] fd]# cp 265 /u01/app/oracle/oradata/inf/rmdtest01res.dbf
[[email protected] inf]$ pwd
/u01/app/oracle/oradata/inf
[[email protected] inf]$ ll
total 4318668
-rw-r----- 1 oracle oinstall 10043392 Mar 16 05:52 control01.ctl
-rw-r----- 1 oracle oinstall 2252349440 Mar 16 05:30 inf01.dbf
-rw-r----- 1 oracle oinstall 52429312 Jan 29 06:54 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Mar 16 05:30 redo02.log
-rw-r----- 1 oracle oinstall 52429312 Mar 16 05:51 redo03.log
-rw-r----- 1 oracle oinstall 52436992 Mar 16 05:50 rmdtest01res.dbf
-rw-r----- 1 oracle oinstall 566239232 Mar 16 05:47 sysaux01.dbf
-rw-r----- 1 oracle oinstall 817897472 Mar 16 05:37 system01.dbf
-rw-r----- 1 oracle oinstall 81797120 Mar 14 10:32 temp01.dbf
-rw-r----- 1 oracle oinstall 5251072 Dec 22 10:36 test01.dbfbak
-rw-r----- 1 oracle oinstall 471867392 Mar 16 05:47 undotbs01.dbf
-rw-r----- 1 oracle oinstall 9183232 Mar 16 05:30 users01.dbf

拷贝出来之后,最好进行一定转换。先将其offline,之后进行控制文件中的rename动作,最后recover和online操作。具体流程常见笔者专门的文章

SQL> select TABLESPACE_NAME,FILE_ID,STATUS,FILE_NAME,BYTES/1024/1024 from dba_data_files;

TABLESPACE_NAME FILE_ID STATUS FILE_NAME BYTES/1024/1024
-------------------- ---------- --------- ------------------------------------------------------------ ---------------
RMDTEST 7 AVAILABLE /u01/app/oracle/oradata/inf/rmdtest01.dbf 50
USERS 4 AVAILABLE /u01/app/oracle/oradata/inf/users01.dbf 8.75
UNDOTBS1 3 AVAILABLE /u01/app/oracle/oradata/inf/undotbs01.dbf 450
SYSAUX 2 AVAILABLE /u01/app/oracle/oradata/inf/sysaux01.dbf 540
SYSTEM 1 AVAILABLE /u01/app/oracle/oradata/inf/system01.dbf 780
INF 5 AVAILABLE /u01/app/oracle/oradata/inf/inf01.dbf 2148


SQL> alter database datafile 7 offline;

Database altered.

SQL> alter database rename file ‘/u01/app/oracle/oradata/inf/rmdtest01.dbf‘ to ‘/u01/app/oracle/oradata/inf/rmdtest01res.dbf‘;

Database altered.

SQL> recover datafile 7;
Media recovery complete.
SQL> alter database datafile 7 online;

Database altered.

使用rman中的recovery advisor工具,来判断错误是否存在。
[[email protected] inf]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Mar 16 05:55:20 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: INF (DBID=2613824471)

RMAN> list failure;

using target database control file instead of recovery catalog
no failures found that match specification

 


































































































以上是关于Linux下利用文件描述符恢复的成功失败实验的主要内容,如果未能解决你的问题,请参考以下文章

Linux中用extundelete恢复误删文件

利用extundelete恢复rm 的文件

利用extundelete工具恢复Centos6.5中误删除的文件

Linux dup dup2函数理解

实验三( 实时系统的移植)问题总结

引导检查失败 [1] 的 [1]:弹性搜索过程的最大文件描述符 [4096] 太低