Recovery Methods for accidental File Deletion in Linux and Windows

Source: Internet
Author: User

In Linux Redhat 5.4, the recovery process for RM accidental deletion of database files is as follows:
(Found online, tested OK)
1. First, test RM's accidental deletion of database files.

[Oracle @ primary dbwdn] $ LL
Total 2153164
-RW-r ----- 1 Oracle DBA 8536064 Nov 27 control01.ctl
-RW-r ----- 1 Oracle DBA 8536064 Nov 27 control02.ctl
-RW-r ----- 1 Oracle DBA 8536064 Nov 27 control03.ctl
-RW-r ----- 1 Oracle DBA 104865792 Nov 27 ggs01.dbf
-RW-r ----- 1 Oracle DBA 525344768 Nov 27 perfstat. DBF
-RW-r ----- 1 Oracle DBA 52429312 Nov 27 redo01.log
-RW-r ----- 1 Oracle DBA 52429312 Nov 27 redo02.log
-RW-r ----- 1 Oracle DBA 52429312 Nov 27 redo03.log
-RW-r ----- 1 Oracle DBA 10493952 Nov 27 shkz_data_01.dbf
-RW-r ----- 1 Oracle DBA 524296192 Nov 27 sysaux01.dbf
-RW-r ----- 1 Oracle DBA 524296192 Nov 27 system01.dbf
-RW-r ----- 1 Oracle DBA 209723392 Nov 18 temp01.dbf
-RW-r ----- 1 Oracle DBA 52436992 Nov 27 test01.dbf

-RW-r ----- 1 Oracle DBA 251666432 Nov 27 undotbs01.dbf
-RW-r ----- 1 Oracle DBA 26222592 Nov 27 users01.dbf
[Oracle @ primary dbwdn] $ RM test01.dbf

2. Find the database background process dbw0

Oracle 3493 1 0? 00:00:00 ora_dbw0_dbwdn

Process 3493

3. Find the database file that was accidentally deleted

[Oracle @ primary dbwdn] $ ll/proc/3493/FD
Total 0
LR-x ------ 1 Oracle oinstall 64 Nov 27 21:52 0->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27 21:52 1->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27 10->/dev/zero
LR-x ------ 1 Oracle oinstall 64 Nov 27 11->/dev/zero
LR-x ------ 1 Oracle oinstall 64 Nov 27 21:52 12->/u01/APP/Oracle/product/10.2.0/db_1/rdbms/mesg/oraus. MSB
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 13->/u01/APP/Oracle/product/10.2.0/db_1/dbs/hc_dbwdn.dat
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 14->/u01/APP/Oracle/product/10.2.0/db_1/dbs/lkdbwdn
Lrwx ------ 1 Oracle oinstall 64 Nov 27 15->/u01/APP/Oracle/oradata/dbwdn/control01.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27 16->/u01/APP/Oracle/oradata/dbwdn/control02.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 17->/u01/APP/Oracle/oradata/dbwdn/control03.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 18->/u01/APP/Oracle/oradata/dbwdn/system01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 19->/u01/APP/Oracle/oradata/dbwdn/undotbs01.dbf
LR-x ------ 1 Oracle oinstall 64 Nov 27 21:52 2->/dev/null
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 20->/u01/APP/Oracle/oradata/dbwdn/sysaux01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 21->/u01/APP/Oracle/oradata/dbwdn/users01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 22->/u01/APP/Oracle/oradata/dbwdn/test01.dbf (Deleted)

Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 23->/u01/APP/Oracle/oradata/dbwdn/ggs01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21: 52 24->/u01/APP/Oracle/oradata/dbwdn/perfstat. DBF
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 25->/u01/APP/Oracle/oradata/dbwdn/shkz_data_01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21: 52 26->/u01/APP/Oracle/oradata/dbwdn/temp01.dbf
LR-x ------ 1 Oracle oinstall 64 Nov 27 21:52 27->/u01/APP/Oracle/product/10.2.0/db_1/rdbms/mesg/oraus. MSB
LR-x ------ 1 Oracle oinstall 64 Nov 27 21:52 3->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27 21:52 4->/dev/null
L-WX ------ 1 Oracle oinstall 64 Nov 27 21:52 5->/u01/APP/Oracle/admin/dbwdn/udump/dbwdn_ora_3485.trc
L-WX ------ 1 Oracle oinstall 64 Nov 27 21:52 6->/u01/APP/Oracle/admin/dbwdn/bdump/alert_dbwdn.log
Lrwx ------ 1 Oracle oinstall 64 Nov 27 21:52 7->/u01/APP/Oracle/product/10.2.0/db_1/dbs/hc_dbwdn.dat
L-WX ------ 1 Oracle oinstall 64 Nov 27 21:52 8->/u01/APP/Oracle/admin/dbwdn/bdump/alert_dbwdn.log

After deletion by mistake, the database is not restarted, and the system is not restarted.

5. Copy database files

[Oracle @ primary ~] $ CP/proc/3493/FD/22/u01/APP/Oracle/oradata/dbwdn/test01.dbf

[Oracle @ primary ~] $ CD/u01/APP/Oracle/oradata/dbwdn
[Oracle @ primary dbwdn] $ ls
Control01.ctl control03.ctl perfstat. DBF redo02.log shkz_data_01.dbf system01.dbf test01.dbf users01.dbf
Control02.ctl ggs01.dbf redo01.log redo03.log sysaux01.dbf temp01.dbf undotbs01.dbf

The database file is retrieved.

6. Restore database files

[Oracle @ primary dbwdn] $ sqlplus "/As sysdba"

SQL * Plus: Release 10.2.0.5.0-production on TUE Nov 27 21:55:15 2012

Copyright (c) 1982,201 0, Oracle. All rights reserved.

Connected:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0-Production
With the partitioning, OLAP, data mining and real application testing options

SQL> alter database datafile 5 offline;

Database altered.

SQL> recover datafile 5;
Media recovery complete.
SQL> alter database datafile 5 online;

Database altered.

SQL> shutdown immediate;
Database closed.
Database dismounted.
Oracle instance shut down.
SQL> startup
Oracle instance started.

Total system global area 285212672 bytes
Fixed size 1273276 bytes
Variable Size 130024004 bytes
Database buffers 150994944 bytes
Redo buffers 2920448 bytes
Database mounted.
Database opened.
SQL>

Database restored

Note: If the database can be restored after it is restarted, test it:

[Oracle @ primary dbwdn] $ RM users01.dbf [Oracle @ primary dbwdn] $ PS-Ef | grep dbw0
Oracle 3798 1 0? 00:00:00 ora_dbw0_dbwdn
Oracle 4147 3439 0 00:00:00 pts/1 grep dbw0
[Oracle @ primary dbwdn] $ ll/proc/3798/FD
Total 0
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27 1->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/zero
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/zero
LR-x ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/product/10.2.0/db_1/rdbms/mesg/oraus. MSB
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/product/10.2.0/db_1/dbs/hc_dbwdn.dat
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/product/10.2.0/db_1/dbs/lkdbwdn
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/control01.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/control02.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/control03.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/system01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27 19->/u01/APP/Oracle/oradata/dbwdn/undotbs01.dbf
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/null
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/sysaux01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27 22: 07 21->/u01/APP/Oracle/oradata/dbwdn/users01.dbf (Deleted) lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/test01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/ggs01.dbf
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/perfstat. DBF
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/shkz_data_01.dbf

The database has not been restarted, and this data file can be recovered. If I restart the database, can I still see this data file?

[Oracle @ primary dbwdn] $ sqlplus "/As sysdba"

SQL * Plus: Release 10.2.0.5.0-production on TUE Nov 27 22:08:01 2012

Copyright (c) 1982,201 0, Oracle. All rights reserved.

Connected:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0-Production
With the partitioning, OLAP, data mining and real application testing options

SQL> shutdown immediate;
ORA-01116: Error in opening database file 4
ORA-01110: data file 4: '/u01/APP/Oracle/oradata/dbwdn/users01.dbf'
ORA-27041: Unable to open file
Linux error: 2: no such file or directory
Additional information: 3
SQL> shutdown abort; Oracle instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0-Production
With the partitioning, OLAP, data mining and real application testing options
[Oracle @ primary dbwdn] $ sqlplus "/As sysdba"

SQL * Plus: Release 10.2.0.5.0-production on TUE Nov 27 22:08:19 2012

Copyright (c) 1982,201 0, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
Oracle instance started.

Total system global area 285212672 bytes
Fixed size 1273276 bytes
Variable Size 130024004 bytes
Database buffers 150994944 bytes
Redo buffers 2920448 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4-see dbwr trace file
ORA-01110: data file 4: '/u01/APP/Oracle/oradata/dbwdn/users01.dbf'

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0-Production
With the partitioning, OLAP, data mining and real application testing options
[Oracle @ primary dbwdn] $ ll/proc/3798/FD
Ls:/proc/3798/FD: no such file or directory
[Oracle @ primary dbwdn] $ PS-Ef | grep dbw0
Oracle 4160 1 0? 00:00:00 ora_dbw0_dbwdn
Oracle 4193 3439 0 00:00:00 pts/1 grep dbw0
[Oracle @ primary dbwdn] $ ll/proc/4160/FD
Total 0
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27 1->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/zero
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/zero
LR-x ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/product/10.2.0/db_1/rdbms/mesg/oraus. MSB
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/product/10.2.0/db_1/dbs/hc_dbwdn.dat
Lrwx ------ 1 Oracle oinstall 64 Nov 27 22: 09 14->/u01/APP/Oracle/product/10.2.0/db_1/dbs/lkdbwdn
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/control01.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/control02.ctl
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/oradata/dbwdn/control03.ctl
L-WX ------ 1 Oracle oinstall 64 Nov 27 2->/u01/APP/Oracle/admin/dbwdn/bdump/dbwdn_dbw0_4160.trc
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/null
LR-x ------ 1 Oracle oinstall 64 Nov 27->/dev/null
L-WX ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/admin/dbwdn/udump/dbwdn_ora_1122.trc
L-WX ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/admin/dbwdn/bdump/alert_dbwdn.log
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/product/10.2.0/db_1/dbs/hc_dbwdn.dat
L-WX ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/admin/dbwdn/bdump/alert_dbwdn.log
Lrwx ------ 1 Oracle oinstall 64 Nov 27->/u01/APP/Oracle/product/10.2.0/db_1/dbs/lkinstdbwdn (Deleted)
[Oracle @ primary dbwdn] $

It cannot be recovered.

Note that after RM accidentally deletes a file, do not be confused, hold on to it, do not restart the database, or restart the system.

I have not tested the AIX system.

Use a backup set to restore the above database files:

[Oracle @ primary dbwdn] $ RMAN target/

Recovery Manager: Release 10.2.0.5.0-production on TUE Nov 27 22:13:45 2012

Copyright (c) 1982,200 7, Oracle. All rights reserved.

Connected to target database (not started)

RMAN> startup nomount;

Oracle instance started

Total system global area 285212672 bytes

Fixed size 1273276 bytes
Variable Size 130024004 bytes
Database buffers 150994944 bytes
Redo buffers 2920448 bytes

RMAN> alter database Mount;

Using target database control file instead of recovery catalog
Database mounted

RMAN> RUN
2> {
3> allocate channel T1 type to disk;

RMAN-00571: ========================================================== ==============================
RMAN-00569: ==================== error message stack follows ==========================
RMAN-00571: ========================================================== ==============================
RMAN-00558: Error encountered while parsing input commands
RMAN-01009: syntax error: Found "to": expecting one of: "double-quoted-string, disk, equal, identifier, single-quoted-string"
RMAN-01007: At Line 3 column 26 file: Standard Input

RMAN> RUN
2> {
3> allocate channel T1 device type disk;
4> restore datafile 4;
5> recover datafile 4;
6> release channel T1;
7>}

Allocated channel: T1
Channel T1: SID = 156 devtype = Disk

Starting restore at 27-nov-2012 22:16:26

Channel T1: Starting datafile backupset restore
Channel T1: specifying datafile (s) to restore from backup set
Restoring datafile 00004 to/u01/APP/Oracle/oradata/dbwdn/users01.dbf
Channel T1: reading from backup piece/u01/bak/03nrctnp_1_1.bak
Channel T1: restored backup piece 1
Piece handle =/u01/bak/03nrctnp_1121.bak tag = tag20121127t213241
Channel T1: restore complete, elapsed time: 00:00:04
Finished restore at 27-nov-2012 22:16:30

Starting recover at 27-nov-2012 22:16:30

Starting media recovery
Media recovery complete, elapsed time: 00:00:01

Finished recover at 27-nov-2012 22:16:31

Released channel: T1

RMAN> alter database open;

Database opened

RMAN>

Recover data in Windows (recovery method after clearing the recycle bin ):
Steps:

1. Click start -- run, and then enter Regedit (open registry)

2, expand in turn: HEKEY--LOCAL--MACHIME/software/Microsoft/Windows/CurrentVersion/Explorer/desktop/namespace on the left blank and click "new"

Select "primary key" and name it "645ffo40--5081--101b--9f08--00aa002f954e"

Set the key value of the "default" primary key on the right to "recycle bin" and exit the registry. OK.

3. restart the computer.

As long as the machine has not run Disk sorting. The system is in good condition. files can be retrieved at any time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.