透過控制程式碼檔案恢復linux下誤刪除的資料檔案

guyuanli發表於2012-09-28
資料庫在open的時候資料檔案被刪除(從系統級別刪除)
因為在linux系統中,之前開啟過該檔案的程式仍然持有相應的檔案控制程式碼,所指向的檔案仍然可以讀寫,
檔案描述符可以從/proc目錄中得到
如果關閉資料庫,則該控制程式碼會消失
[@more@]
透過簡單的實驗演示一下
SYS SQL> select status from v$instance;
STATUS
------------
OPEN
SYS SQL> select name from v$datafile;
NAME
-------------------------------------------------------
/opt/app/oracle/oradata/ora10g/system01.dbf
/opt/app/oracle/oradata/ora10g/undotbs01.dbf
/opt/app/oracle/oradata/ora10g/sysaux01.dbf
/opt/app/oracle/oradata/ora10g/users01.dbf

刪除users表空間的資料檔案
SYS SQL> ! rm -rf /opt/app/oracle/oradata/ora10g/users01.dbf

在users表空間建表的時候,報錯
SYS SQL> create table t3 tablespace users as select * from scott.emp;
create table t3 tablespace users as select * from scott.emp *
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/opt/app/oracle/oradata/ora10g/users01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SYS SQL> select status from v$instance;
STATUS
------------
OPEN

檢視dbw0寫程式的程式號
[oracle@report bdump]$ ps -ef | grep dbw0 |grep -v grep
oracle 3393 1 0 17:32 ? 00:00:05 ora_dbw0_ora10g

proc目錄下檢視控制程式碼號,可以看到users表空間的資料檔案後面標示有deleted的字樣 控制程式碼檔名為21
[root@report ora10g]# cd /proc/3393/fd/
[root@report fd]# ll
lr-x------ 1 oracle dba 64 Dec 26 23:20 0 -> /dev/null
lr-x------ 1 oracle dba 64 Dec 26 23:20 1 -> /dev/null
lr-x------ 1 oracle dba 64 Dec 26 23:20 10 -> /dev/zero
lr-x------ 1 oracle dba 64 Dec 26 23:20 11 -> /dev/zero
lr-x------ 1 oracle dba 64 Dec 26 23:20 12 -> /opt/app/oracle/product/10.2.0/rdbms/mesg/oraus.msb
lrwx------ 1 oracle dba 64 Dec 26 23:20 13 -> /opt/app/oracle/product/10.2.0/dbs/hc_ora10g.dat
lrwx------ 1 oracle dba 64 Dec 26 23:20 14 -> /opt/app/oracle/product/10.2.0/dbs/lkORA10G
lrwx------ 1 oracle dba 64 Dec 26 23:20 15 -> /opt/app/oracle/oradata/ora10g/control01.ctl
lrwx------ 1 oracle dba 64 Dec 26 23:20 16 -> /opt/app/oracle/oradata/ora10g/control02.ctl
lrwx------ 1 oracle dba 64 Dec 26 23:20 17 -> /opt/app/oracle/oradata/ora10g/control03.ctl
lrwx------ 1 oracle dba 64 Dec 26 23:20 18 -> /opt/app/oracle/oradata/ora10g/system01.dbf
lrwx------ 1 oracle dba 64 Dec 26 23:20 19 -> /opt/app/oracle/oradata/ora10g/undotbs01.dbf
lr-x------ 1 oracle dba 64 Dec 26 23:20 2 -> /dev/null
lrwx------ 1 oracle dba 64 Dec 26 23:20 20 -> /opt/app/oracle/oradata/ora10g/sysaux01.dbf
lrwx------ 1 oracle dba 64 Dec 26 23:20 21 -> /opt/app/oracle/oradata/ora10g/users01.dbf (deleted)
lrwx------ 1 oracle dba 64 Dec 26 23:20 22 -> /opt/app/oracle/oradata/ora10g/temp01.dbf
lr-x------ 1 oracle dba 64 Dec 26 23:20 23 -> /opt/app/oracle/product/10.2.0/rdbms/mesg/oraus.msb
lr-x------ 1 oracle dba 64 Dec 26 23:20 3 -> /dev/null
lr-x------ 1 oracle dba 64 Dec 26 23:20 4 -> /dev/null
l-wx------ 1 oracle dba 64 Dec 26 23:20 5 -> /opt/app/oracle/admin/ora10g/udump/ora10g_ora_3384.trc
l-wx------ 1 oracle dba 64 Dec 26 23:20 6 -> /opt/app/oracle/admin/ora10g/bdump/alert_ora10g.log
l-wx------ 1 oracle dba 64 Dec 26 23:20 8 -> /opt/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle dba 64 Dec 26 23:20 9 -> /opt/app/oracle/product/10.2.0/dbs/hc_ora10g.dat

直接cp該控制程式碼檔名到資料檔案原位置
[root@report fd]# cp 21 /opt/app/oracle/oradata/ora10g/users01.dbf

SYS SQL> alter database datafile 4 offline;
Database altered.
SYS SQL> recover datafile 4;
Media recovery complete.
SYS SQL> alter database datafile 4 online;
Database altered.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7490392/viewspace-1059516/,如需轉載,請註明出處,否則將追究法律責任。

相關文章