Linux下使用extundelete恢复ext3误删除数据文件

文件系统是ext3,操作系统是rhel5.5

数据库正常关闭后,oradata/orcl104/*被全部删除,未做任何动作,然后卸载了文件系统。

[root@db9 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       38G   32G  4.0G  90% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 2.2G     0  2.2G   0% /dev/shm

使用工具恢复数据文件

[root@db9 ~]# extundelete /dev/sdf1 --restore-all
Loading filesystem metadata ... 80 groups loaded.
Loading journal descriptors ... 358 descriptors loaded.
Writing output to directory RECOVERED_FILES/
Searching for recoverable inodes in directory / ... 
13 recoverable inodes found.
Looking through the directory structure for deleted files ... 
Restored inode 49153 to file RECOVERED_FILES/control01.ctl
Restored inode 49154 to file RECOVERED_FILES/control02.ctl
Restored inode 49155 to file RECOVERED_FILES/control03.ctl
Restored inode 49156 to file RECOVERED_FILES/mytbs1.dbf.2
Restored inode 49157 to file RECOVERED_FILES/redo01.log
Restored inode 49158 to file RECOVERED_FILES/redo02.log
Restored inode 49159 to file RECOVERED_FILES/redo03.log
Restored inode 49160 to file RECOVERED_FILES/sysaux01.dbf
Restored inode 49161 to file RECOVERED_FILES/system01.dbf
Restored inode 49162 to file RECOVERED_FILES/temp01.dbf
Restored inode 49163 to file RECOVERED_FILES/undotbs01.dbf
Restored inode 49164 to file RECOVERED_FILES/users01.dbf
Restored inode 49165 to file RECOVERED_FILES/mydbs1_01.dbf
0 recoverable inodes still lost.
[root@db9 ~]#

[root@db9 orcl104]# ll
total 1136052
-rw-r--r-- 1 oracle dba   7061504 Sep  6 20:31 control01.ctl
-rw-r--r-- 1 oracle dba   7061504 Sep  6 20:31 control02.ctl
-rw-r--r-- 1 oracle dba   7061504 Sep  6 20:31 control03.ctl
-rw-r--r-- 1 oracle dba 104865792 Sep  6 20:31 mydbs1_01.dbf
-rw-r--r-- 1 oracle dba  20979712 Sep  6 20:31 mytbs1.dbf.2
-rw-r--r-- 1 oracle dba  52429312 Sep  6 20:31 redo01.log
-rw-r--r-- 1 oracle dba  52429312 Sep  6 20:31 redo02.log
-rw-r--r-- 1 oracle dba  52429312 Sep  6 20:31 redo03.log
-rw-r--r-- 1 oracle dba 272637952 Sep  6 20:31 sysaux01.dbf
-rw-r--r-- 1 oracle dba 503324672 Sep  6 20:31 system01.dbf
-rw-r--r-- 1 oracle dba  20979712 Sep  6 20:31 temp01.dbf
-rw-r--r-- 1 oracle dba  73408512 Sep  6 20:31 undotbs01.dbf
-rw-r--r-- 1 oracle dba   7872512 Sep  6 20:31 users01.dbf

复制到数据文件夹下,可正常打开数据库

[oracle@db9 ~]$ sqlplus  / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on  20:33:13 2012

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  897581056 bytes
Fixed Size                  2076848 bytes
Variable Size             239079248 bytes
Database Buffers          650117120 bytes
Redo Buffers                6307840 bytes
Database mounted.
Database opened.

 

同样测试2如下:

在数据库打开的时候,有事务运行的情况下,删除undotbs1表空间,然后实例报错

Thu Sep  6 21:58:23 2012
Errors in file /u01/app/oracle/admin/orcl104/bdump/orcl104_smon_28552.trc:
ORA-00376: file 2 cannot be read at this time
ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl104/undotbs01.dbf'
Thu Sep  6 21:58:24 2012
Errors in file /u01/app/oracle/admin/orcl104/bdump/orcl104_smon_28552.trc:
ORA-00604: error occurred at recursive SQL level 1
ORA-00376: file 2 cannot be read at this time
ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl104/undotbs01.dbf'

通过lsof也无法找到文件,故只有杀掉smon进程。然后恢复了undo数据文件

[root@db9 ~]# extundelete /dev/sdf1 --restore-all
Loading filesystem metadata ... 80 groups loaded.
Loading journal descriptors ... 1826 descriptors loaded.
Writing output to directory RECOVERED_FILES/
Searching for recoverable inodes in directory / ... 
15 recoverable inodes found.
Looking through the directory structure for deleted files ... 
Restored inode 19 to file RECOVERED_FILES/undotbs01.dbf
Restored inode 49164 to file RECOVERED_FILES/undotbs01.dbf.v1
Restored inode 49165 to file RECOVERED_FILES/users01.dbf
12 recoverable inodes still lost.
Failed to restore inode 11 to file RECOVERED_FILES/file.11:Inode does not correspond to a regular file.
Unable to restore inode 49153 (file.49153): Space has been reallocated.
Unable to restore inode 49154 (file.49154): Space has been reallocated.
Unable to restore inode 49155 (file.49155): Space has been reallocated.
Unable to restore inode 49156 (file.49156): Space has been reallocated.
Unable to restore inode 49157 (file.49157): Space has been reallocated.
Restored inode 49158 to file RECOVERED_FILES/file.49158
Restored inode 49159 to file RECOVERED_FILES/file.49159
Restored inode 49160 to file RECOVERED_FILES/file.49160
Restored inode 49161 to file RECOVERED_FILES/file.49161
Restored inode 49162 to file RECOVERED_FILES/file.49162
Restored inode 49163 to file RECOVERED_FILES/file.49163

重启后undo表空间是离线的,故报错如下

Completed: alter database open
Thu Sep  6 22:02:57 2012
Errors in file /u01/app/oracle/admin/orcl104/bdump/orcl104_j002_32251.trc:
ORA-12012: error on auto execute of job 8912
ORA-00376: file ORA-00376: file 2 cannot be read at this time
ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl104/undotbs01.dbf'
ORA-06512: at "SYS.PRVT_ADVISOR", line 1624
ORA-06512: at "SYS.DBMS_ADVISOR", line 186
ORA-06512: at "SYS.DBMS_SPACE", line 1347
ORA-06512: at "SYS.DBMS_SPACE", line 1566
 cannot be read at this time
Thu Sep  6 22:03:01 2012
GATHER_STATS_JOB encountered errors.  Check the trace file.
Thu Sep  6 22:03:01 2012
Errors in file /u01/app/oracle/admin/orcl104/bdump/orcl104_j001_32249.trc:
ORA-00376: file 2 cannot be read at this time
ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl104/undotbs01.dbf'

SQL> col name format a460
SQL> col name format a60
SQL> r
  1* select name,STATUS from v$datafile

NAME                                                         STATUS
------------------------------------------------------------ --------------
/u01/app/oracle/oradata/orcl104/system01.dbf                 SYSTEM
/u01/app/oracle/oradata/orcl104/undotbs01.dbf                RECOVER
/u01/app/oracle/oradata/orcl104/sysaux01.dbf                 ONLINE
/u01/app/oracle/oradata/orcl104/users01.dbf                  ONLINE
/u01/app/oracle/oradata/orcl104/mydbs1_01.dbf                ONLINE

SQL> select file#, name,STATUS from v$datafile;

     FILE# NAME                                                         STATUS
---------- ------------------------------------------------------------ --------------
         1 /u01/app/oracle/oradata/orcl104/system01.dbf                 SYSTEM
         2 /u01/app/oracle/oradata/orcl104/undotbs01.dbf                RECOVER
         3 /u01/app/oracle/oradata/orcl104/sysaux01.dbf                 ONLINE
         4 /u01/app/oracle/oradata/orcl104/users01.dbf                  ONLINE
         5 /u01/app/oracle/oradata/orcl104/mydbs1_01.dbf                ONLINE

SQL> recover datafile 2;
ORA-00279: change 940995 generated at 09/06/2012 21:46:08 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_33_649507406.dbf
ORA-00280: change 940995 for thread 1 is in sequence #33


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 944108 generated at 09/06/2012 21:47:11 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_34_649507406.dbf
ORA-00280: change 944108 for thread 1 is in sequence #34
ORA-00278: log file '/u01/app/oracle/arch/1_33_649507406.dbf' no longer needed for this recovery


Log applied.
Media recovery complete.
SQL> select file#, name,STATUS from v$datafile;

     FILE# NAME                                                         STATUS
---------- ------------------------------------------------------------ --------------
         1 /u01/app/oracle/oradata/orcl104/system01.dbf                 SYSTEM
         2 /u01/app/oracle/oradata/orcl104/undotbs01.dbf                OFFLINE
         3 /u01/app/oracle/oradata/orcl104/sysaux01.dbf                 ONLINE
         4 /u01/app/oracle/oradata/orcl104/users01.dbf                  ONLINE
         5 /u01/app/oracle/oradata/orcl104/mydbs1_01.dbf                ONLINE

SQL> select count(*) from t4;
select count(*) from t4
*
ERROR at line 1:
ORA-00376: file 2 cannot be read at this time
ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl104/undotbs01.dbf'


SQL> select file#, name,STATUS from v$datafile;

     FILE# NAME                                                         STATUS
---------- ------------------------------------------------------------ --------------
         1 /u01/app/oracle/oradata/orcl104/system01.dbf                 SYSTEM
         2 /u01/app/oracle/oradata/orcl104/undotbs01.dbf                OFFLINE
         3 /u01/app/oracle/oradata/orcl104/sysaux01.dbf                 ONLINE
         4 /u01/app/oracle/oradata/orcl104/users01.dbf                  ONLINE
         5 /u01/app/oracle/oradata/orcl104/mydbs1_01.dbf                ONLINE

SQL> recover datafile 2;
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required


SQL> recover datafile 2;
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required


SQL> alter database datafile 2 online;

Database altered.

SQL> alter tablespace undotbs1 online;

Tablespace altered.

SQL> select file#, name,STATUS from v$datafile;

     FILE# NAME                                                         STATUS
---------- ------------------------------------------------------------ --------------
         1 /u01/app/oracle/oradata/orcl104/system01.dbf                 SYSTEM
         2 /u01/app/oracle/oradata/orcl104/undotbs01.dbf                ONLINE
         3 /u01/app/oracle/oradata/orcl104/sysaux01.dbf                 ONLINE
         4 /u01/app/oracle/oradata/orcl104/users01.dbf                  ONLINE
         5 /u01/app/oracle/oradata/orcl104/mydbs1_01.dbf                ONLINE

SQL> select count(*) from t4;

  COUNT(*)
----------
    199340

SQL> select count(*) from t1;

  COUNT(*)
----------
    199328

SQL> select count(*) from t2;

  COUNT(*)
----------
    199332

SQL> select count(*) from t3;

  COUNT(*)
----------
    199336

SQL> select count(*) from t4;

  COUNT(*)
----------
    199340

SQL>

你可能感兴趣的:(Oracle)