OS 刪除oracle資料檔案恢復過程
非常幸運的是,在資料檔案刪除的情況下,資料庫沒有重啟,使得這次的恢復變的較為簡單,基於這次的恢復,我在我得實驗裝置上進行了重演,記錄了完整的資料檔案刪除和恢復的完整步驟,如下:
一、準備測試環境,建立新的表空間及資料檔案:
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
SQL>create tablespace test1 datafile '/app/oracle11g/oradata/uporcl/testdata02.dbf' size 1g autoextend on;
Tablespace created.
SQL> select name from v$dbfile;
NAME
--------------------------------------------------------------------------------
/app/oracle11g/oradata/uporcl/system01.dbf
/app/oracle11g/oradata/uporcl/undotbs01.dbf
/app/oracle11g/oradata/uporcl/sysaux01.dbf
/app/oracle11g/oradata/uporcl/users01.dbf
/app/oracle11g/oradata/uporcl/testdata01.dbf
/app/oracle11g/oradata/uporcl/testdata02.dbf
6 rows selected.
二、模擬故障,在系統級別刪除資料檔案:
SQL> !rm -rf /app/oracle11g/oradata/uporcl/testdata02.dbf
三、檢查資料庫狀態,並且建立測試資料
SQL> !tail -f 300 /app/oracle11g/diag/rdbms/uporcl/uporcl/trace/alert*
tail: cannot open `300' for reading: No such file or directory
==> /app/oracle11g/diag/rdbms/uporcl/uporcl/trace/alert_uporcl.log <==
Current log# 1 seq# 235 mem# 0: /app/oracle11g/oradata/uporcl/redo01.log
Thu Aug 27 13:47:36 2015
Errors in file /app/oracle11g/diag/rdbms/uporcl/uporcl/trace/uporcl_m001_27005.trc:
ORA-01116: error in opening database file 6
ORA-01110: data file 6: '/app/oracle11g/oradata/uporcl/testdata02.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Thu Aug 27 13:47:37 2015
Checker run found 1 new persistent data failures
#在這裡我們可以看到資料檔案在系統層面被刪除之後資料庫並沒產生告警。
我們新增一個表,發現已經報錯了。
SQL> create table test tablespace test1 as select * from dba_tables;
create table test tablespace test1 as select * from dba_tables
*
ERROR at line 1:
ORA-01116: error in opening database file 6
ORA-01110: data file 6: '/app/oracle11g/oradata/uporcl/testdata02.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
#在資料庫層面,我們需要往這個刪除的檔案中寫入資料的時候才發現資料檔案被刪除了。
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
uporcl OPEN #即便資料庫已經知道了資料庫檔案丟失,因為不是系統表空間的資料檔案,所以資料庫的執行並沒有收到影響。
四、查詢資料檔案
因為資料庫並沒有停止執行,這個時候我們可以透過dbwr寫資料檔案程式來找到程式控制程式碼號,進入該控制程式碼號就可以找到該程式鎖定的相關資料檔案了。
SQL> !ps -ef|grep dbw
oracle 21705 1 0 Aug26 ? 00:00:03 ora_dbw0_uporcl
oracle 27137 26986 0 14:01 pts/1 00:00:00 /bin/bash -c ps -ef|grep dbw
#我們可以看到程式的ID為21705,透過程式ID查詢到程式下鎖定的所有檔案
SQL> !ls -rtl /proc/21705/fd
total 0
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 9 -> /app/oracle11g/product/11.2.0/dbhome_1/dbs/hc_uporcl.dat
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 8 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 7 -> /proc/21705/fd
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 6 -> /app/oracle11g/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 5 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 3 -> /dev/null
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 265 -> /app/oracle11g/oradata/uporcl/temp01.dbf
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 264 -> /app/oracle11g/oradata/uporcl/testdata02.dbf (deleted)我們找到了這個檔案,處於deleted
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 263 -> /app/oracle11g/oradata/uporcl/testdata01.dbf
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 262 -> /app/oracle11g/oradata/uporcl/users01.dbf
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 261 -> /app/oracle11g/oradata/uporcl/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 260 -> /app/oracle11g/oradata/uporcl/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 259 -> /app/oracle11g/oradata/uporcl/system01.dbf
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 258 -> /app/oracle11g/oradata/uporcl/control03.ctl
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 257 -> /app/oracle11g/oradata/uporcl/control02.ctl
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 256 -> /app/oracle11g/oradata/uporcl/control01.ctl
l-wx------ 1 oracle oinstall 64 Aug 27 14:02 2 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 11 -> /app/oracle11g/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb
lrwx------ 1 oracle oinstall 64 Aug 27 14:02 10 -> /app/oracle11g/product/11.2.0/dbhome_1/dbs/lkUPORCL
l-wx------ 1 oracle oinstall 64 Aug 27 14:02 1 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 27 14:02 0 -> /dev/null
五、將該檔案控制程式碼複製到原檔案位置:
- SQL>!cp /proc/21705/fd/264 /app/oracle11g/oradata/uporcl/testdata02.dbf
六、對複製回來的檔案執行常規的資料恢復操作,實際上也就是更新下資料檔案頭部的scn號:
SQL> col name format a44
SQL> select file#,status,name from v$datafile;
FILE# STATUS NAME
---------- ------- --------------------------------------------
1 SYSTEM /app/oracle11g/oradata/uporcl/system01.dbf
2 ONLINE /app/oracle11g/oradata/uporcl/undotbs01.dbf
3 ONLINE /app/oracle11g/oradata/uporcl/sysaux01.dbf
4 ONLINE /app/oracle11g/oradata/uporcl/users01.dbf
5 ONLINE /app/oracle11g/oradata/uporcl/testdata01.dbf
6 ONLINE /app/oracle11g/oradata/uporcl/testdata02.dbf #我們可以看到這個時候該資料檔案是ONLINE狀態
6 rows selected.
#由於這是一套線上庫,且有其它業務,不可隨意停機,所以這個時候將需要恢復的資料檔案offline,就可以直接線上執行恢復了。
注意:在offline資料檔案時,如果是在非歸檔模式下需要offlien tablespace .如果直接offline 資料檔案會報錯
SQL> alter database datafile 6 offline;
alter database datafile 6 offline
*
ERROR at line 1:
ORA-01145: offline immediate disallowed unless media recovery enabled
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 233
Current log sequence 235
SQL> alter tablespace test1 offline;
Tablespace altered.
SQL> select file#,status,name from v$datafile;
FILE# STATUS NAME
---------- ------- --------------------------------------------
1 SYSTEM /app/oracle11g/oradata/uporcl/system01.dbf
2 ONLINE /app/oracle11g/oradata/uporcl/undotbs01.dbf
3 ONLINE /app/oracle11g/oradata/uporcl/sysaux01.dbf
4 ONLINE /app/oracle11g/oradata/uporcl/users01.dbf
5 ONLINE /app/oracle11g/oradata/uporcl/testdata01.dbf
6 OFFLINE /app/oracle11g/oradata/uporcl/testdata02.dbf. #在對資料檔案進行操作,觸發了該檔案,發現檔案頭部的scn不一致,提示需要進行恢復。
6 rows selected
執行線上恢復並且online該資料檔案。
SQL>recover datafile 6;
Media recovery complete.
SQL>alter database datafile 8 online;
Database altered.
七、驗證資料檔案恢復後是否可以正常使用
SQL> select file#,status,name from v$datafile;
FILE# STATUS NAME
---------- ------- --------------------------------------------
1 SYSTEM /app/oracle11g/oradata/uporcl/system01.dbf
2 ONLINE /app/oracle11g/oradata/uporcl/undotbs01.dbf
3 ONLINE /app/oracle11g/oradata/uporcl/sysaux01.dbf
4 ONLINE /app/oracle11g/oradata/uporcl/users01.dbf
5 ONLINE /app/oracle11g/oradata/uporcl/testdata01.dbf
6 ONLINE /app/oracle11g/oradata/uporcl/testdata02.dbf
SQL>create table test tablespace test1 as select * from dba_users;
Table created.
八、至此完成該資料檔案的恢復
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12798004/viewspace-1784093/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux下恢復誤刪除oracle的資料檔案LinuxOracle
- Oracle 檔案意外刪除恢復(Linux)OracleLinux
- 【北亞資料恢復】誤刪除oracle表和誤刪除oracle表資料的資料恢復方法資料恢復Oracle
- 【資料庫資料恢復】透過恢復NDF檔案修復資料庫的資料恢復過程資料庫資料恢復
- Git恢復刪除的檔案Git
- [Oracle]Oracle資料庫資料被修改或者刪除恢復資料Oracle資料庫
- 電腦裡刪除的檔案怎麼恢復,資料恢復方法大全資料恢復
- EMC UNITY 400儲存卷刪除資料恢復操作過程Unity資料恢復
- 行動硬碟刪除的檔案能恢復嗎,怎麼恢復硬碟刪除的檔案硬碟
- 【伺服器資料恢復】NetApp儲存中lun被誤刪除的資料恢復過程伺服器資料恢復APP
- Oracle 業務資料unload恢復過程Oracle
- oracle徹底刪除資料檔案Oracle
- 恢復Oracle資料庫誤刪除資料的語句Oracle資料庫
- 【伺服器資料恢復】Zfs檔案系統下誤刪除怎麼恢復資料伺服器資料恢復
- 【資料庫資料恢復】Sql Server資料庫檔案丟失的資料恢復過程資料庫資料恢復SQLServer
- Oracle恢復誤刪資料Oracle
- 虛擬機器vmdk檔案刪除後如何恢復資料虛擬機
- NetApp FAS2240-4儲存刪除檔案資料恢復APP資料恢復
- sd卡中的資料夾刪除了怎麼恢復,SD卡刪除的檔案如何恢復SD卡
- 【北亞資料恢復】zfs檔案系統的伺服器誤刪除的資料恢復資料恢復伺服器
- 【資料庫資料恢復】LINUX環境下ORACLE資料庫誤刪除的資料恢復資料庫資料恢復LinuxOracle
- sd卡刪除的檔案如何恢復SD卡
- Shift + Delete刪除的檔案如何恢復?delete
- Oracle10g刪除資料檔案Oracle
- 檔案刪除如何恢復?推薦幾款超實用的資料恢復軟體資料恢復
- Linux 恢復rm -rf命令所刪除的達夢資料檔案Linux
- 【伺服器資料恢復】StorNext檔案系統下raid5資料恢復過程伺服器資料恢復AI
- 360粉碎檔案可以恢復嗎,如何恢復360強力刪除的檔案
- oracle使用小記、刪除恢復Oracle
- 【oracle資料庫資料恢復】誤操作導致的資料庫誤刪除的資料恢復案例Oracle資料庫資料恢復
- 【資料庫資料恢復】HP-UX系統ORACLE資料庫被誤刪除的資料恢復資料庫資料恢復UXOracle
- 如何使用 testdisk 恢復已刪除的檔案
- rm -rf 刪除檔案還能恢復嗎?
- 【虛擬機器資料恢復】誤刪除VMware虛擬機器vmdk檔案的資料恢復案例虛擬機資料恢復
- Sybase ASE資料庫恢復,Sybase資料恢復,資料誤刪除恢復工具READSYBDEVICE資料庫資料恢復dev
- mysql 5.7 刪除ibdata1 、ib_logfile 檔案的資料恢復MySql資料恢復
- 資料恢復新姿勢——通過ibd和frm檔案恢復資料資料恢復
- 資料庫恢復過程資料庫
- 隨身碟被刪除的檔案如何恢復?