您的位置:首页 > 数据库 > Oracle

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

2015-10-19 23:16 507 查看
一、实验说明: 本文转载EYGLE的《数据安全警示录》中的一个案例,也有在itpub上发表过http://www.itpub.net/thread-1721724-1-1.html,在这里只是做一个模拟,并记录一下! 操作系统:rhel 5.4 x32 数据库:oracle 11g r2二、实验操作: 在UNIX、Linux系统中,误删除数据文件后,虽然该文件已从操作系统中删除,但是其文件句柄仍由数据库进行打开持有,所以在数据库层面仍然不会释放其链表信息,因而也就能够从进程的地址信息中,通过复制将其直接恢复。但是请注意,这要求数据库不能中途关闭,如果关闭了数据库,则所有文件句柄被释放,文件就真的难以回归了。
----首先创建一个环境----
SQL> create tablespace jack datafile '/u01/app/oracle/oradata/yft/jack01.dbf' size 50m;

Tablespace created.

SQL> create user echo identified by echo default tablespace jack;

User created.

SQL> grant resource,connect to echo;

Grant succeeded.

SQL> create table echo.tab(domian varchar2(100)) tablespace jack;

Table created.

SQL> insert into echo.tab values('www.jack.com');

1 row created.

SQL> commit;

Commit complete.

----在这里删除数据文件,告警日志没有报错----
[oracle@yft ~]$ rm /u01/app/oracle/oradata/yft/jack01.dbf

----查看一下句柄----
[oracle@yft ~]$ ps -ef|grep dbw|grep -v grep
oracle    3911     1  0 07:10 ?        00:00:01 ora_dbw0_yft

[oracle@yft ~]$ ll /proc/3911/fd
total 0
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 1 -> /dev/null
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 10 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trc
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 11 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trm
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 12 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 13 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 14 -> /proc/3911/fd
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 15 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 16 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_yft.dat
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 17 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkYFT
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 18 -> /u01/app/oracle/oradata/yft/control01.ctl
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 19 -> /u01/app/oracle/flash_recovery_area/yft/control02.ctl
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 20 -> /u01/app/oracle/oradata/yft/jack01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 22 -> socket:[13943]

----直接把数据文件拷贝回来----
[oracle@yft ~]$ cp /proc/3911/fd/20 /u01/app/oracle/oradata/yft/jack01.dbf

[oracle@yft ~]$ ll /u01/app/oracle/oradata/yft/
total 2698480
-rw-r----- 1 oracle oinstall    9879552 Jan 10 08:28 control01.ctl
-rw-r----- 1 oracle oinstall    9748480 Jan  9 19:42 control01.ctl.bak
-rw-r----- 1 oracle oinstall  104865792 Jan 10 08:22 example01.dbf
-rw-r----- 1 oracle oinstall   52436992 Jan 10 08:27 jack01.dbf
-rw-r----- 1 oracle oinstall   52429312 Jan 10 08:27 redo01.log
-rw-r----- 1 oracle oinstall   52429312 Jan 10 07:16 redo02.log
-rw-r----- 1 oracle oinstall   52429312 Jan 10 07:16 redo03.log
-rw-r----- 1 oracle oinstall  513810432 Jan 10 08:22 sysaux01.dbf
-rw-r----- 1 oracle oinstall  713039872 Jan 10 08:27 system01.dbf
-rw-r----- 1 oracle oinstall   30416896 Jan 10 08:22 temp01.dbf
-rw-r----- 1 oracle oinstall   99622912 Jan 10 08:27 undotbs01.dbf
-rw-r----- 1 oracle oinstall    5251072 Jan 10 08:22 users01.dbf
-rw-r----- 1 oracle oinstall 1073750016 Jan 10 08:22 yft01.dbf
如果我在删除之后使用alter system checkpoint之后就有可能恢复不过来。
----在拷贝之前,数据库checkpoint了一下----
SQL> alter system checkpoint;

System altered.

----告警日志中的错误----
Thu Jan 10 08:35:08 2013
Errors in file /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ckpt_3915.trc:
ORA-01171: datafile 7 going offline due to error advancing checkpoint
ORA-01116: error in opening database file 7
ORA-01110: data file 7: '/u01/app/oracle/oradata/yft/jack01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3

----查询不到数据,并报错----
SQL> select * from echo.tab;
select * from echo.tab
*
ERROR at line 1:
ORA-00376: file 7 cannot be read at this time
ORA-01110: data file 7: '/u01/app/oracle/oradata/yft/jack01.dbf'

----句柄已经消失----
[oracle@yft ~]$ ll /proc/3911/fd
total 0
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 1 -> /dev/null
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 10 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trc
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 11 -> /u01/app/oracle/diag/rdbms/yft/yft/trace/yft_ora_3855.trm
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 12 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 13 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 14 -> /proc/3911/fd
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 15 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 16 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_yft.dat
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 17 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkYFT
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 18 -> /u01/app/oracle/oradata/yft/control01.ctl
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 19 -> /u01/app/oracle/flash_recovery_area/yft/control02.ctl
l-wx------ 1 oracle oinstall 64 Jan 10 08:14 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 22 -> socket:[13943]
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 23 -> /u01/app/oracle/oradata/yft/system01.dbf
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 24 -> /u01/app/oracle/oradata/yft/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 25 -> /u01/app/oracle/oradata/yft/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 26 -> /u01/app/oracle/oradata/yft/users01.dbf
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 27 -> /u01/app/oracle/oradata/yft/example01.dbf
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 28 -> /u01/app/oracle/oradata/yft/yft01.dbf
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 29 -> /u01/app/oracle/oradata/yft/temp01.dbf
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
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 30 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 5 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 6 -> /dev/null
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 7 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_yft.dat
lrwx------ 1 oracle oinstall 64 Jan 10 08:14 8 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkinstyft (deleted)
lr-x------ 1 oracle oinstall 64 Jan 10 08:14 9 -> /proc/3911/fd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle 数据安全 create