|簡體中文

比思論壇

 找回密碼
 按這成為會員
搜索



查看: 1364|回復: 4
打印 上一主題 下一主題

linux rm误删除数据库文件的恢复方法

[複製鏈接]

989

主題

1

好友

5296

積分

教授

Rank: 8Rank: 8

  • TA的每日心情

    2024-11-3 15:50
  • 簽到天數: 1258 天

    [LV.10]以壇為家III

    推廣值
    2
    貢獻值
    378
    金錢
    1528
    威望
    5296
    主題
    989

    回文勇士 文明人 中學生 高中生 簽到勳章 簽到達人 男生勳章 大學生 文章勇士 附件高人 附件達人 文章達人 教授

    樓主
    發表於 2013-7-28 17:45:49
    1.首先测试rm 误删除数据库文件

    [oracle@primary dbwdn]$ ll
    total 2153164
    -rw-r----- 1 oracle dba 8536064 Nov 27 21:50 control01.ctl
    -rw-r----- 1 oracle dba 8536064 Nov 27 21:50 control02.ctl
    -rw-r----- 1 oracle dba 8536064 Nov 27 21:50 control03.ctl
    -rw-r----- 1 oracle dba 104865792 Nov 27 21:32 ggs01.dbf
    -rw-r----- 1 oracle dba 525344768 Nov 27 21:32 perfstat.dbf
    -rw-r----- 1 oracle dba 52429312 Nov 27 21:10 redo01.log
    -rw-r----- 1 oracle dba 52429312 Nov 27 21:49 redo02.log
    -rw-r----- 1 oracle dba 52429312 Nov 27 21:10 redo03.log
    -rw-r----- 1 oracle dba 10493952 Nov 27 21:32 shkz_data_01.dbf
    -rw-r----- 1 oracle dba 524296192 Nov 27 21:49 sysaux01.dbf
    -rw-r----- 1 oracle dba 524296192 Nov 27 21:49 system01.dbf
    -rw-r----- 1 oracle dba 209723392 Nov 18 10:54 temp01.dbf
    -rw-r----- 1 oracle dba 52436992 Nov 27 21:32 test01.dbf
    -rw-r----- 1 oracle dba 251666432 Nov 27 21:49 undotbs01.dbf
    -rw-r----- 1 oracle dba 26222592 Nov 27 21:32 users01.dbf
    [oracle@primary dbwdn]$ rm test01.dbf

    2.找到数据库后台进程dbw0

    oracle 3493 1 0 21:10 ? 00:00:00 ora_dbw0_dbwdn
    进程号3493

    3.找到被误删除的数据库文件

    [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 21:52 10 -> /dev/zero
    lr-x------ 1 oracle oinstall 64 Nov 27 21:52 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 21:52 15 -> /u01/app/oracle/oradata/dbwdn/control01.ctl
    lrwx------ 1 oracle oinstall 64 Nov 27 21:52 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
    误删除之后,数据库没有重启,系统也没用重启

    4.拷贝数据库文件

    [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
    数据库文件找回来了。

    5.恢复数据库文件

    [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, 2010, Oracle. All Rights Reserved.

    Connected to:
    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>

    成功恢复数据库

    注:如果数据库重启之后,还能恢复吗,测试一下:

    [oracle@primary dbwdn]$ rm users01.dbf[oracle@primary dbwdn]$ ps -ef |grep dbw0
    oracle 3798 1 0 21:56 ? 00:00:00 ora_dbw0_dbwdn
    oracle 4147 3439 0 22:07 pts/1 00:00:00 grep dbw0
    [oracle@primary dbwdn]$ ll /proc/3798/fd
    total 0
    lr-x------ 1 oracle oinstall 64 Nov 27 22:07 0 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Nov 27 22:07 1 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Nov 27 22:07 10 -> /dev/zero
    lr-x------ 1 oracle oinstall 64 Nov 27 22:07 11 -> /dev/zero
    lr-x------ 1 oracle oinstall 64 Nov 27 22:07 12 -> /u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 13 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_dbwdn.dat
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 14 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkDBWDN
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 15 -> /u01/app/oracle/oradata/dbwdn/control01.ctl
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 16 -> /u01/app/oracle/oradata/dbwdn/control02.ctl
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 17 -> /u01/app/oracle/oradata/dbwdn/control03.ctl
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 18 -> /u01/app/oracle/oradata/dbwdn/system01.dbf
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 19 -> /u01/app/oracle/oradata/dbwdn/undotbs01.dbf
    lr-x------ 1 oracle oinstall 64 Nov 27 22:07 2 -> /dev/null
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 20 -> /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 22:07 22 -> /u01/app/oracle/oradata/dbwdn/test01.dbf
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 23 -> /u01/app/oracle/oradata/dbwdn/ggs01.dbf
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 24 -> /u01/app/oracle/oradata/dbwdn/perfstat.dbf
    lrwx------ 1 oracle oinstall 64 Nov 27 22:07 25 -> /u01/app/oracle/oradata/dbwdn/shkz_data_01.dbf

    数据库没有重启,这个数据文件还能恢复,如果我重启数据库之后,还能看见这个数据文件吗?

    [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, 2010, Oracle. All Rights Reserved.

    Connected to:
    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, 2010, 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 22:08 ? 00:00:00 ora_dbw0_dbwdn
    oracle 4193 3439 0 22:09 pts/1 00:00:00 grep dbw0
    [oracle@primary dbwdn]$ ll /proc/4160/fd
    total 0
    lr-x------ 1 oracle oinstall 64 Nov 27 22:09 0 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Nov 27 22:09 1 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Nov 27 22:09 10 -> /dev/zero
    lr-x------ 1 oracle oinstall 64 Nov 27 22:09 11 -> /dev/zero
    lr-x------ 1 oracle oinstall 64 Nov 27 22:09 12 -> /u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb
    lrwx------ 1 oracle oinstall 64 Nov 27 22:09 13 -> /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 22:09 15 -> /u01/app/oracle/oradata/dbwdn/control01.ctl
    lrwx------ 1 oracle oinstall 64 Nov 27 22:09 16 -> /u01/app/oracle/oradata/dbwdn/control02.ctl
    lrwx------ 1 oracle oinstall 64 Nov 27 22:09 17 -> /u01/app/oracle/oradata/dbwdn/control03.ctl
    l-wx------ 1 oracle oinstall 64 Nov 27 22:09 2 -> /u01/app/oracle/admin/dbwdn/bdump/dbwdn_dbw0_4160.trc
    lr-x------ 1 oracle oinstall 64 Nov 27 22:09 3 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Nov 27 22:09 4 -> /dev/null
    l-wx------ 1 oracle oinstall 64 Nov 27 22:09 5 -> /u01/app/oracle/admin/dbwdn/udump/dbwdn_ora_4152.trc
    l-wx------ 1 oracle oinstall 64 Nov 27 22:09 6 -> /u01/app/oracle/admin/dbwdn/bdump/alert_dbwdn.log
    lrwx------ 1 oracle oinstall 64 Nov 27 22:09 7 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_dbwdn.dat
    l-wx------ 1 oracle oinstall 64 Nov 27 22:09 8 -> /u01/app/oracle/admin/dbwdn/bdump/alert_dbwdn.log
    lrwx------ 1 oracle oinstall 64 Nov 27 22:09 9 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstdbwdn (deleted)
    [oracle@primary dbwdn]$

    已经没法恢复了。
    说明需要注意的是,rm误删除文件之后,千万不要慌张,稳住神,不要重启数据库,不要重启动系统。
    AIX系统,我没有测试过。
    使用备份集恢复上面的数据库文件:

    [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, 2007, 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_1_1.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>

    Windows下数据恢复(把回收站清空后的恢复方法):

    步骤:
    1、单击“开始——运行,然后输入regedit (打开注册表)
    2、依次展开:HEKEY——LOCAL——MACHIME/SOFTWARE/microsoft/WINDOWS/ CURRENTVERSION/EXPLORER/DESKTOP/NAMESPACE 在左边空白外点击“新建”
    ,选择:“主键”,把它命名为“645FFO40——5081——101B——9F08——00AA002F954E”
    再把右边的“默认”的主键的键值设为“回收站”,然后退出注册表。就OK啦。
    3、要重启计算机。
    只要机器没有运行过磁盘整理。系统完好.任何时候的文件都可以找回来。

    2

    主題

    0

    好友

    916

    積分

    高中生

    Rank: 4

  • TA的每日心情
    難過
    2024-11-7 21:09
  • 簽到天數: 718 天

    [LV.9]以壇為家II

    推廣值
    0
    貢獻值
    0
    金錢
    30
    威望
    916
    主題
    2
    沙發
    發表於 2013-11-24 16:28:34
    好是好,但是是不是太他妈复杂了。

    24

    主題

    0

    好友

    356

    積分

    中學生

    Rank: 3Rank: 3

  • TA的每日心情
    慵懶
    2024-6-12 08:54
  • 簽到天數: 137 天

    [LV.7]常住居民III

    推廣值
    0
    貢獻值
    0
    金錢
    48
    威望
    356
    主題
    24
    板凳
    發表於 2013-12-10 14:11:46
    这个超级有用,试试
    重要聲明:本論壇是以即時上載留言的方式運作,比思論壇對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,讀者及用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,讀者及用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本論壇受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者及用戶發現有留言出現問題,請聯絡我們比思論壇有權刪除任何留言及拒絕任何人士上載留言 (刪除前或不會作事先警告及通知 ),同時亦有不刪除留言的權利,如有任何爭議,管理員擁有最終的詮釋權。用戶切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。

    手機版| 廣告聯繫

    GMT+8, 2024-11-16 11:12 , Processed in 0.014151 second(s), 16 queries , Gzip On, Memcache On.

    Powered by Discuz! X2.5

    © 2001-2012 Comsenz Inc.

    回頂部