• centOS6.4 extundelete工具恢复rm -rf 删除的目录[转]


    原文:http://www.cnblogs.com/patf/p/3368765.html

    PS:补充下,我在fedora 19上运行的时候遇到的一个问题:

    1 [root@localhost extundelete-0.2.4]# ./configure
    2 Configuring extundelete 0.2.4
    3 configure: error: in `/usr/local/src/extundelete-0.2.4':
    4 configure: error: C++ compiler cannot create executables
    5 See `config.log' for more details

    查看了下config.log文件发现与gcc-c++有关。所以运行yum -y install gcc-c++这个库后问题解决

    复制代码
     1 总计                                            988 kB/s | 8.2 MB     00:08     
     2 Running transaction check
     3 Running transaction test
     4 Transaction test succeeded
     5 Running transaction
     6   正在安装    : libstdc++-devel-4.8.1-1.fc19.i686                           1/2 
     7   正在安装    : gcc-c++-4.8.1-1.fc19.i686                                   2/2 
     8   验证中      : libstdc++-devel-4.8.1-1.fc19.i686                           1/2 
     9   验证中      : gcc-c++-4.8.1-1.fc19.i686                                   2/2 
    10 
    11 已安装:
    12   gcc-c++.i686 0:4.8.1-1.fc19                                                   
    13 
    14 作为依赖被安装:
    15   libstdc++-devel.i686 0:4.8.1-1.fc19                                           
    16 
    17 完毕!
    18 [root@localhost extundelete-0.2.4]# ./configure 
    19 Configuring extundelete 0.2.4
    20 Writing generated files to disk
    21 [root@localhost extundelete-0.2.4]# yum install gcc-c++
    复制代码

    首先。Linux下很多人都喜欢用rm -rf去删除目录。但是rm --help提示这是一个非常危险的命令、谨慎用之。

    这里公司一台服务器。同事在操作的过程中误删掉一个目录。而且是非常重要的。

    尝试恢复cat /etc/redhat-release 查看为rhel4版本。很老了这就有一个问题出现yum无法用。

    先用一个ext3grep 工具恢复。但是该工具--help 提示没有针对目录恢复的参数 只有一个all 我尝试用时间戳恢复当时时间段的数据效果不理想、

    而且跟要命的是当我查看分区的时候df -aT发现这个删除的目录进入奇迹般的划分在了与/一个分区。0 0这意味着我挂载为只读分区时要杀掉一

    切与/根分区有关的进程;所有反复思索后决定一个好的办法:

    USB移动硬盘安装一个便携Linux系统,并在其上面安装extundelete工具因为这个工具需要几个包的支持。而rhel4的系统现在yum已经无法使用

    安装支持包都很困难。索性放弃。

    关于USB移动硬盘系统。与我们用的stat 硬盘安装系统一样。可以用光盘镜像安装选择USB设备为安装设备。或者用虚拟机安装都可以。这里我就

    不多说推荐虚拟机Virtual BoxVMware(优点是你有镜像但无法刻盘)。

    好了进入centOS6.4后

    下载extundelete:wget http://pkgs.fedoraproject.org/repo/pkgs/extundelete/extundelete-0.2.4.tar.bz2/77e626ad31433680c0a222069295d2ca/extundelete-0.2.4.tar.bz2

    1 [root@vbok src]# wget http://pkgs.fedoraproject.org/repo/pkgs/extundelete/extundelete-0.2.4.tar.bz2/77e626ad31433680c0a222069295d2ca/extundelete-0.2.4.tar.bz2
    1 [root@vbok src]# tar jxvf extundelete-0.2.4.tar.bz2

    直接./configure make make install 但我运行./configure时报错:

    1 [root@vbok src]# cd extundelete-0.2.4
    2 [root@vbok extundelete-0.2.4]# ./configure 
    3 Configuring extundelete 0.2.4
    4 configure: error: Can't find ext2fs library

    提示 ext2fs library 少几个包的支持

    1 [root@vbok extundelete-0.2.4]# yum -y install ext2fs

    OK 在运行make三部曲

    [root@vbok extundelete-0.2.4]# ./configure 
    Configuring extundelete 0.2.4
    Writing generated files to disk

    当然如果你make完后就可以使用这个工具的

    1 [root@vbok extundelete-0.2.4]# make
    2 make -s all-recursive
    3 Making all in src
    4 extundelete.cc:571: 警告:未使用的参数‘flags’

    直接在~/src/extundelete --help

    [root@vbok extundelete-0.2.4]# src/extundelete --help

    或者在运行 make install 这时会安装到/usr/local/bin/extundelete 下

    我还是推荐make完就成了。因为假如你要恢复的目录正好是/usr 那你就还需要在./configure下加参数。浪费时间效果一样

    OK来演示下恢复吧

    复制代码
     1 [root@vbok /]# df -h
     2 文件系统              容量  已用  可用 已用%% 挂载点
     3 /dev/mapper/vg_vbok-gen
     4                        25G  541M   23G   3% /
     5 tmpfs                 943M  232K  943M   1% /dev/shm
     6 /dev/sdb1             485M   36M  424M   8% /boot
     7 /dev/mapper/vg_vbok-home
     8                        20G  172M   19G   1% /home
     9 /dev/mapper/vg_vbok-opt
    10                        11G  156M  9.9G   2% /opt
    11 /dev/mapper/vg_vbok-usr
    12                        39G  3.2G   34G   9% /usr
    13 /dev/sdb3              51G   16K   51G   1% /vfat
    复制代码

    我在/opt下创建了个目录 “1“ 下面有多个子目录和文件。然后我将其删除。

    (看看现在的时间)并回到extundelete 安装目录下将opt目录挂载为只读为了保护数据防止重写。

    复制代码
     1 root@vbok /]# cd opt/
     2 [root@vbok opt]# ls
     3 1  lost+found  rh
     4 [root@vbok opt]# date
     5 2013年 10月 14日 星期一 16:44:55 CST
     6 [root@vbok opt]# rm -rf 1
     7 [root@vbok opt]# ls
     8 lost+found  rh
     9 [root@vbok opt]# cd /usr/local/src/extundelete-0.2.4
    10 [root@vbok extundelete-0.2.4]# mount -o remount,ro /dev/mapper/vg_vbok-opt
    复制代码

    这里说下我要用到的参数 src/extundelete --help

    1 --restore-directory 'path'
    2                          Will restore directory 'path'. 'path' is relative to the
    3 --restore-all          Attempts to restore everything.
    4  --after dtime          Only process entries deleted on or after 'dtime'.
    5   --before dtime         Only process entries deleted before 'dtime'.

    第一个是 恢复目录 path为路径后面跟要恢复那个目录的路径

    第二个是 恢复所有

    第三个是 恢复dtime这个时间戳以后删除的文件 

    第四个是恢复这个时间戳以前删除的文件  (这里说下,卡时间恢复是非常好用的参数。你可以指定恢复那个时间到那个时间之间的数据)

    基本这几个选项就够恢复了,当然还有--restore-files 参数来恢复单个文件。

    OK开始

    我上面在删除的时间date了下系统时间所以我就来生成下 删除前和删除后的时间戳用来定位我要恢复的目录,然后利用工具恢复删除的目录

    [root@vbok extundelete-0.2.4]# date -d "2013-10-14 16:43" +%s
    1381740180
    [root@vbok extundelete-0.2.4]# date -d "2013-10-14 16:58" +%s  
    1381741080
    [root@vbok extundelete-0.2.4]# src/extundelete /dev/mapper/vg_vbok-opt --after /1381740180 --before 1381741080 --restore-directory 1

    OK恢复完成,这里要注意的是在用恢复目录选项的时候,后面接的目录是以opt后的目录。也就是说 /dev/mapper/vg-vbox-opt 已经代表了/opt这个目录我们只需要接着写 opt后面的目录 例如要恢复/opt/1/2/3 这个目录 我们后面的路径为 1/2/3 就可以恢复3这个目录了 当然有时间戳指定时间段后就可以用--restore-all恢复这个时间段删除的所有数据了。OK

    复制代码
     1 NOTICE: Extended attributes are not restored.
     2 Loading filesystem metadata ... 86 groups loaded.
     3 Loading journal descriptors ... 91 descriptors loaded.
     4 Searching for recoverable inodes in directory 1 ... 
     5 9 recoverable inodes found.
     6 Looking through the directory structure for deleted files ... 
     7 1 recoverable inodes still lost.
     8 [root@vbok extundelete-0.2.4]# cd RECOVERED_FILES/
     9 [root@vbok RECOVERED_FILES]# LS
    10 -bash: LS: command not found
    11 [root@vbok RECOVERED_FILES]# ls
    12 1
    13 [root@vbok RECOVERED_FILES]# cd 1
    14 [root@vbok 1]# ls
    15 11  22
    16 [root@vbok 1]# cd 11/
    17 [root@vbok 11]# ls
    18 2  a
    19 [root@vbok 11]# cd ../22/c 
    20 -bash: cd: ../22/c: 不是目录
    21 [root@vbok 11]# cd ../22/c 
    复制代码

    数据 完好无损。

    在讲/opt这个分区挂载回读写的,不会的可以reboot重启下也可以

  • 相关阅读:
    C语言---堆的实现
    python的matplotlib---雷达图
    python的matplotlib饼状图
    python的matplotlib折线图
    python的matplotlib散点图学习
    python的matplotlib散点图
    C语言---队列(链表实现)
    hadoop集群启动与关闭需要输入密码
    hadoop集群启动时需要输入密码
    C语言---堆栈(链表实现)
  • 原文地址:https://www.cnblogs.com/lanqie/p/7698313.html
Copyright © 2020-2023  润新知