误操作删除数据文件恢复案例讨论

一、实验说明:

     本文转载EYGLE的《数据安全警示录》中的一个案例,也有在itpub上发表过http://www.itpub.net/thread-1721724-1-1.html,在这里只是做一个模拟,并记录一下!

     操作系统:rhel 5.4 x32

     数据库:oracle 11g r2

二、实验操作:

     在UNIX、Linux系统中,误删除数据文件后,虽然该文件已从操作系统中删除,但是其文件句柄仍由数据库进行打开持有,所以在数据库层面仍然不会释放其链表信息,因而也就能够从进程的地址信息中,通过复制将其直接恢复。但是请注意,这要求数据库不能中途关闭,如果关闭了数据库,则所有文件句柄被释放,文件就真的难以回归了。

 ----首先创建一个环境----
1
SQL> create tablespace jack datafile '/u01/app/oracle/oradata/yft/jack01.dbf' size 50m; 2 3 Tablespace created. 4 5 SQL> create user echo identified by echo default tablespace jack; 6 7 User created. 8 9 SQL> grant resource,connect to echo; 10 11 Grant succeeded. 12 13 SQL> create table echo.tab(domian varchar2(100)) tablespace jack; 14 15 Table created. 16 17 SQL> insert into echo.tab values('www.jack.com'); 18 19 1 row created. 20 21 SQL> commit; 22 23 Commit complete. 24 ----在这里删除数据文件,告警日志没有报错----
25
[oracle@yft ~]$ rm /u01/app/oracle/oradata/yft/jack01.dbf 26 ----查看一下句柄----
27
[oracle@yft ~]$ ps -ef|grep dbw|grep -v grep 28 oracle 3911 1 0 07:10 ? 00:00:01 ora_dbw0_yft 29 30 [oracle@yft ~]$ ll /proc/3911/fd 31 total 0 32 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 0 -> /dev/null 33 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 1 -> /dev/null 34 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 10 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trc 35 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 11 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trm 36 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 12 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb 37 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 13 -> /dev/zero 38 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 14 -> /proc/3911/fd 39 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 15 -> /dev/zero 40 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 16 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_yft.dat 41 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 17 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkYFT 42 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 18 -> /u01/app/oracle/oradata/yft/control01.ctl 43 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 19 -> /u01/app/oracle/flash_recovery_area/yft/control02.ctl 44 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 2 -> /dev/null 45 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 20 -> /u01/app/oracle/oradata/yft/jack01.dbf (deleted) 46 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 22 -> socket:[13943] 47 ----直接把数据文件拷贝回来----
48
[oracle@yft ~]$ cp /proc/3911/fd/20 /u01/app/oracle/oradata/yft/jack01.dbf 49 50 [oracle@yft ~]$ ll /u01/app/oracle/oradata/yft/ 51 total 2698480 52 -rw-r----- 1 oracle oinstall 9879552 Jan 10 08:28 control01.ctl 53 -rw-r----- 1 oracle oinstall 9748480 Jan 9 19:42 control01.ctl.bak 54 -rw-r----- 1 oracle oinstall 104865792 Jan 10 08:22 example01.dbf 55 -rw-r----- 1 oracle oinstall 52436992 Jan 10 08:27 jack01.dbf 56 -rw-r----- 1 oracle oinstall 52429312 Jan 10 08:27 redo01.log 57 -rw-r----- 1 oracle oinstall 52429312 Jan 10 07:16 redo02.log 58 -rw-r----- 1 oracle oinstall 52429312 Jan 10 07:16 redo03.log 59 -rw-r----- 1 oracle oinstall 513810432 Jan 10 08:22 sysaux01.dbf 60 -rw-r----- 1 oracle oinstall 713039872 Jan 10 08:27 system01.dbf 61 -rw-r----- 1 oracle oinstall 30416896 Jan 10 08:22 temp01.dbf 62 -rw-r----- 1 oracle oinstall 99622912 Jan 10 08:27 undotbs01.dbf 63 -rw-r----- 1 oracle oinstall 5251072 Jan 10 08:22 users01.dbf 64 -rw-r----- 1 oracle oinstall 1073750016 Jan 10 08:22 yft01.dbf

如果我在删除之后使用alter system checkpoint之后就有可能恢复不过来。

 ----在拷贝之前,数据库checkpoint了一下----
1
SQL> alter system checkpoint; 2 3 System altered. 4 ----告警日志中的错误----
5
Thu Jan 10 08:35:08 2013 6 Errors in file /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ckpt_3915.trc: 7 ORA-01171: datafile 7 going offline due to error advancing checkpoint 8 ORA-01116: error in opening database file 7 9 ORA-01110: data file 7: '/u01/app/oracle/oradata/yft/jack01.dbf' 10 ORA-27041: unable to open file 11 Linux Error: 2: No such file or directory 12 Additional information: 3 13 ----查询不到数据,并报错----
14
SQL> select * from echo.tab; 15 select * from echo.tab 16 * 17 ERROR at line 1: 18 ORA-00376: file 7 cannot be read at this time 19 ORA-01110: data file 7: '/u01/app/oracle/oradata/yft/jack01.dbf' 20 ----句柄已经消失----
21
[oracle@yft ~]$ ll /proc/3911/fd 22 total 0 23 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 0 -> /dev/null 24 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 1 -> /dev/null 25 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 10 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trc 26 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 11 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trm 27 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 12 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb 28 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 13 -> /dev/zero 29 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 14 -> /proc/3911/fd 30 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 15 -> /dev/zero 31 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 16 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_yft.dat 32 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 17 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkYFT 33 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 18 -> /u01/app/oracle/oradata/yft/control01.ctl 34 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 19 -> /u01/app/oracle/flash_recovery_area/yft/control02.ctl 35 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 2 -> /dev/null 36 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 22 -> socket:[13943] 37 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 23 -> /u01/app/oracle/oradata/yft/system01.dbf 38 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 24 -> /u01/app/oracle/oradata/yft/sysaux01.dbf 39 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 25 -> /u01/app/oracle/oradata/yft/undotbs01.dbf 40 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 26 -> /u01/app/oracle/oradata/yft/users01.dbf 41 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 27 -> /u01/app/oracle/oradata/yft/example01.dbf 42 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 28 -> /u01/app/oracle/oradata/yft/yft01.dbf 43 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 29 -> /u01/app/oracle/oradata/yft/temp01.dbf 44 l-wx------ 1 oracle oinstall 64 Jan 10 08:14 3 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/log/yft_ora_3855.trc 45 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 30 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb 46 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 4 -> /dev/null 47 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 5 -> /dev/null 48 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 6 -> /dev/null 49 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 7 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_yft.dat 50 lrwx------ 1 oracle oinstall 64 Jan 10 08:14 8 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkinstyft (deleted) 51 lr-x------ 1 oracle oinstall 64 Jan 10 08:14 9 -> /proc/3911/fd

 

    

 

 

posted @ 2013-01-08 21:29  I’m Me!  阅读(299)  评论(0编辑  收藏  举报