共計(jì) 4099 個(gè)字符,預(yù)計(jì)需要花費(fèi) 11 分鐘才能閱讀完成。
自動(dòng)寫代碼機(jī)器人,免費(fèi)開(kāi)通
丸趣 TV 小編給大家分享一下 linux 下如何恢復(fù)被 rm 意外刪除數(shù)據(jù)文件,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
恢復(fù)被 rm 意外刪除數(shù)據(jù)文件
一. 模擬數(shù)據(jù)文件刪除
[oracle@node1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Dec 31 22:00:52 2011
Copyright (c) 1982, 2011, Oracle. All rights reserved.
– 數(shù)據(jù)庫(kù)版本
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
– 所有數(shù)據(jù)文件
SQL select name from v$datafile;
NAME
——————————————————————————–
/opt/oracle/oradata/ora11g/system01.dbf
/opt/oracle/oradata/ora11g/sysaux01.dbf
/opt/oracle/oradata/ora11g/undotbs01.dbf
/opt/oracle/oradata/ora11g/users01.dbf
/opt/oracle/oradata/ora11g/example01.dbf
– 刪除 example01.dbf 數(shù)據(jù)文件
SQL !rm /opt/oracle/oradata/ora11g/example01.dbf
SQL !ls -l /opt/oracle/oradata/ora11g/example01.dbf
ls: /opt/oracle/oradata/ora11g/example01.dbf: 沒(méi)有那個(gè)文件或目錄
– 因?yàn)閿?shù)據(jù)文件被刪除,創(chuàng)建表失敗
SQL create table t_xifenfei tablespace example
2 as select * from dba_tables;
as select * from dba_tables
*
ERROR at line 2:
ORA-01116: error in opening database file 5
ORA-01110: data file 5: /opt/oracle/oradata/ora11g/example01.dbf
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
二. 找回?cái)?shù)據(jù)文件
– 查找 dbw 進(jìn)程 spid
[oracle@node1 ~]$ ps -ef|grep dbw|grep -v grep
oracle 18387 1 0 Dec22 ? 00:00:12 ora_dbw0_ora11g
– 查看該進(jìn)程所有文件句柄
[oracle@node1 ~]$ ll /proc/18387/fd
總計(jì) 0
lr-x—— 1 oracle oinstall 64 12-31 22:03 0 – /dev/null
l-wx—— 1 oracle oinstall 64 12-31 22:03 1 – /dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 10 – /dev/zero
lr-x—— 1 oracle oinstall 64 12-31 22:03 11 – /dev/zero
lr-x—— 1 oracle oinstall 64 12-31 22:03 12 – /opt/oracle/product/11.2.0/db_1/rdbms/mesg/orazhs.msb
lrwx—— 1 oracle oinstall 64 12-31 22:03 13 – /opt/oracle/product/11.2.0/db_1/dbs/hc_ora11g.dat
lr-x—— 1 oracle oinstall 64 12-31 22:03 14 – /proc/18387/fd
lr-x—— 1 oracle oinstall 64 12-31 22:03 15 – /dev/zero
lr-x—— 1 oracle oinstall 64 12-31 22:03 16 – /opt/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lrwx—— 1 oracle oinstall 64 12-31 22:03 17 – /opt/oracle/product/11.2.0/db_1/dbs/hc_ora11g.dat
lrwx—— 1 oracle oinstall 64 12-31 22:03 18 – /opt/oracle/product/11.2.0/db_1/dbs/lkORA11G
lr-x—— 1 oracle oinstall 64 12-31 22:03 19 – /opt/oracle/product/11.2.0/db_1/rdbms/mesg/orazhs.msb
l-wx—— 1 oracle oinstall 64 12-31 22:03 2 – /dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 20 – /opt/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lrwx—— 1 oracle oinstall 64 12-31 22:03 21 – socket:[441562]
lrwx—— 1 oracle oinstall 64 12-31 22:03 256 – /opt/oracle/oradata/ora11g/control01.ctl
lrwx—— 1 oracle oinstall 64 12-31 22:03 257 – /opt/oracle/oradata/ora11g/system01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 258 – /opt/oracle/oradata/ora11g/sysaux01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 259 – /opt/oracle/oradata/ora11g/undotbs01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 260 – /opt/oracle/oradata/ora11g/users01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 261 – /opt/oracle/oradata/ora11g/example01.dbf (deleted)
lrwx—— 1 oracle oinstall 64 12-31 22:03 262 – /opt/oracle/oradata/ora11g/temp01.dbf
lr-x—— 1 oracle oinstall 64 12-31 22:03 3 – /dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 4 – /dev/null
lrwx—— 1 oracle oinstall 64 12-31 22:03 5 – /opt/oracle/product/11.2.0/db_1/dbs/hc_ora11g.dat
lr-x—— 1 oracle oinstall 64 12-31 22:03 6 – /dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 7 – /dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 8 – /dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 9 – /dev/null
– 通過(guò)句柄恢復(fù)數(shù)據(jù)文件 [被刪除數(shù)據(jù)文件會(huì)被標(biāo)示(deleted)]
[oracle@node1 ~]$ cp /proc/18387/fd/261 /opt/oracle/oradata/ora11g/example01.dbf
– 確認(rèn)該數(shù)據(jù)文件已經(jīng)恢復(fù)成功
[oracle@node1 ~]$ ll /opt/oracle/oradata/ora11g/example01.dbf
-rw-r—– 1 oracle oinstall 362422272 12-31 22:05 /opt/oracle/oradata/ora11g/example01.dbf
三. 數(shù)據(jù)文件 online
SQL alter database datafile 5 offline;
Database altered.
SQL recover datafile 5;
Media recovery complete.
SQL alter database datafile 5 online;
Database altered.
SQL create table t_xifenfei tablespace example
2 as select * from dba_tables;
Table created.
四. 補(bǔ)充說(shuō)明
在意外使用 os 命令刪除掉數(shù)據(jù)文件時(shí),千萬(wàn)不要慌張重啟數(shù)據(jù)庫(kù)或者操作系統(tǒng),可以通過(guò) dbwn 進(jìn)程相關(guān)句柄找回?cái)?shù)據(jù)文件
以上是“l(fā)inux 下如何恢復(fù)被 rm 意外刪除數(shù)據(jù)文件”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注丸趣 TV 行業(yè)資訊頻道!
向 AI 問(wèn)一下細(xì)節(jié)
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!