This article has been authorized by the author Zhao Xudong netease cloud community.

Welcome to visit netease Cloud Community to learn more about Netease’s technical product operation experience.



If the database is deleted by the RM command, as long as the main process of the database has not quit, the file can be recovered from the file handle and finally recover the loss. The following uses the Oracle database as an example to describe how to restore files:

1. Simulated deletion library (including data files, control files and online log files)

sys@GLOBAL>col NAME for a100;
sys@GLOBAL>select FILE#,NAME from v$datafile;
     FILE# NAME-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1 /home/oracle/app/oradata/global/system01.dbf 2 /home/oracle/app/oradata/global/sysaux01.dbf 3 /home/oracle/app/oradata/global/undotbs01.dbf 4 /home/oracle/app/oradata/global/users01.dbf 5 /home/oracle/app/oradata/global/GLOBAL_ORDER01.dbf 6 /home/oracle/app/oradata/global/TS_DCIS_WMS01.dbf 7 /home/oracle/app/oradata/global/TS_DCIS_WMS02.dbf 7 rows selected. sys@GLOBAL>! rm-f /home/oracle/app/oradata/global/*
sys@GLOBAL>create table t tablespace users as select * from dual;
create table t tablespace users as select * from dual
                                                 *
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/home/oracle/app/oradata/global/users01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3Copy the code

The database and control files as well as the online log files have been deleted. Oracle failed to open the database file when attempting to create a table.

2. Check the PROCESS PID of LGWR

[oracle@ol6-a ~]$ ps -ef | grep lgwr | grep -v grep
oracle     3804      1  0 Dec02 ?        00:01:40 ora_lgwr_globalCopy the code

3. LGWR opens handles to all data files, online log files, and control files. It can be found in the proc directory, where the name is process PID and fd represents the file descriptor.

[oracle@ol6-a~] $cd /proc/3804/fd
[oracle@ol6-a fd]$ ls -ltotal 0 lr-x------. 1 oracle oinstall 64 Dec 7 03:49 0 -> /dev/null l-wx------. 1 oracle oinstall 64 Dec 7 03:49 1 -> / dev/null LRWX -- -- -- -- -- -. 1 oracle oinstall 64 Dec 7 03:49 10 - > / home/oracle/app/product / 11.2.0 db_1 / DBS/lkGLOBAL Lr - x -- -- -- -- -- -. 1 oracle oinstall 64 Dec 7 03:49 13 - > / home/oracle/app/product / 11.2.0 db_1 / RDBMS/mesg/oraus MSB l - wx -- -- -- -- -- -.  1 oracle oinstall 64 Dec 7 03:49 2 -> /dev/null lrwx------. 1 oracle oinstall 64 Dec 7 03:49 256 -> /home/oracle/app/oradata/global/control01.ctl (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 257 -> /home/oracle/app/fast_recovery_area/global/control02.ctl lrwx------. 1 oracle oinstall 64 Dec 7 03:49 258 -> /home/oracle/app/oradata/global/redo01.log (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 259 -> /home/oracle/app/oradata/global/redo02.log (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 260 -> /home/oracle/app/oradata/global/redo03.log (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 261 -> /home/oracle/app/oradata/global/system01.dbf (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 262 -> /home/oracle/app/oradata/global/sysaux01.dbf (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 263 -> /home/oracle/app/oradata/global/undotbs01.dbf (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 264 -> /home/oracle/app/oradata/global/users01.dbf (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 265 -> /home/oracle/app/oradata/global/GLOBAL_ORDER01.dbf (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 266 -> /home/oracle/app/oradata/global/TS_DCIS_WMS01.dbf (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 267 -> /home/oracle/app/oradata/global/TS_DCIS_WMS02.dbf (deleted) lrwx------. 1 oracle oinstall 64 Dec 7 03:49 268 -> /home/oracle/app/oradata/global/temp01.dbf (deleted) lr-x------. 1 oracle oinstall 64 Dec 7 03:49 3 -> /dev/null lr-x------. 1 oracle oinstall 64 Dec 7 03:49 4 -> /dev/null lr-x------. 1 oracle oinstall 64 Dec 7 03:49 5 -> /dev/null Lr - x -- -- -- -- -- -. 1 oracle oinstall 64 Dec 7 03:49 6 - > / home/oracle/app/product / 11.2.0 db_1 / RDBMS/mesg/oraus MSB lr - x -- -- -- -- -- -. 1 oracle oinstall 64 Dec 7 03:49 7 -> /proc/3804/fd lr-x------. 1 oracle oinstall 64 Dec 7 03:49 8 -> /dev/zero LRWX -- -- -- -- -- -. 1 oracle oinstall 64 Dec 7 03:49 9 - > / home/oracle/app/product / 11.2.0 / db_1 / DBS/hc_global datCopy the code

4. Cp the file names of these handles to the original positions.

[oracle@ol6-a fd]$ cp 256 /home/oracle/app/oradata/global/control01.ctl
[oracle@ol6-a fd]$ cp 258 /home/oracle/app/oradata/global/redo01.log
[oracle@ol6-a fd]$ cp 259 /home/oracle/app/oradata/global/redo02.log
[oracle@ol6-a fd]$ cp 260 /home/oracle/app/oradata/global/redo03.log
[oracle@ol6-a fd]$ cp 261 /home/oracle/app/oradata/global/system01.dbf
[oracle@ol6-a fd]$ cp 262 /home/oracle/app/oradata/global/sysaux01.dbf
[oracle@ol6-a fd]$ cp 263 /home/oracle/app/oradata/global/undotbs01.dbf
[oracle@ol6-a fd]$ cp 264 /home/oracle/app/oradata/global/users01.dbf
[oracle@ol6-a fd]$ cp 265 /home/oracle/app/oradata/global/GLOBAL_ORDER01.dbf
[oracle@ol6-a fd]$ cp 266 /home/oracle/app/oradata/global/TS_DCIS_WMS01.dbf
[oracle@ol6-a fd]$ cp 267 /home/oracle/app/oradata/global/TS_DCIS_WMS02.dbf
[oracle@ol6-a fd]$ cp 268 /home/oracle/app/oradata/global/temp01.dbfCopy the code

5. Check whether the database is available:

[oracle@ol6-afd]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 7 03:47:39 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11G Enterprise Edition Release 11.2.0.4.0-64bit Production With the Partitioning Oracle Label Security, OLAP, Data Mining and Real Application Testing options sys@GLOBAL>create table t tablespace users as select * from dual; Table created.Copy the code

The data file is restored.

6. If the database is unavailable, data files may be recovered. Run the following command to restore data files:

alter database datafile 1 offline;
recover datafile 1;
alter database datafile 1 online;Copy the code


How to recover: On Linux, if a file is dropped from the operating system level by RM, the process that opened the file before still holds the corresponding file handle, the file pointing to is still readable and writable, and the file descriptor for the file can be obtained from the /proc directory. However, it should be noted that if the database is closed at this time, the handle will disappear, and there is no other method except scanning disks for file recovery. Therefore, when the database has problems, do not close the database without confirming the complexity of the situation. Restarting a database is often meaningless or even fatal.

If the database is shut down and the handle is lost, you can restore the database files using a recovery tool (as long as the data has not been overwritten on disk and there is enough disk space for the files to be recovered), such as TestDisk and ExtunDelete.

Using testDisk as an example, use Filesystem Utils of Testdisk to restore deleted files to a specified directory.

1. Select the media where the files are deleted



2. Use Filesystem Utils

3. Select the file that you want to restore to the specified directory.




Free access to verification code, content security, SMS, live on demand experience package and cloud server packages

For more information about netease’s technology, products and operating experience, please click here.


Design and implementation of NOS Cross-zone DISASTER recovery