zoukankan      html  css  js  c++  java
  • Linux 文件恢复

    可以恢复,使用系统自还工具debugfs来还原删除的文件

    步骤详解

    1、 查看一下当前系统版本号,及文件系统格式

    [root@localhost ~]# df -T 
    Filesystem Type 1K-blocks Used Available Use% Mounted on 
    /dev/mapper/VolGroup-lv_root 
    ext4 51475068 22730068 26123560 47% / 
    tmpfs tmpfs 3966808 68 3966740 1% /dev/shm 
    /dev/sda2 ext4 487652 42534 419518 10% /boot 
    /dev/mapper/VolGroup-lv_home 
    ext4 901188872 20070036 835334364 3% /home

    2、新建一个文件夹及文件my.txt,然后删除

    [root@localhost local]# mkdir test 
    [root@localhost local]# cd test 
    [root@localhost test]# touch my.txt 
    [root@localhost test]# ll 
    总用量 0 
    -rw-r–r–. 1 root root 0 1月 4 15:22 my.txt 
    [root@localhost test]# rm -f my.txt 
    [root@localhost test]# ll 
    总用量 0

    3、运用,系统自还工具debugfs来修复 打开,刚刚被删除文件所在的分区,用ls 加-d参数显示刚刚删除文件所在的目录

    [root@localhost test]# debugfs 
    debugfs 1.41.12 (17-May-2010) 
    debugfs: open /dev/mapper/VolGroup-lv_root 
    debugfs: ls -d /usr/local/test/ 
    2378807 (12) . 2098175 (4084) .. <2378808> (4072) my.txt

    4、显示有<>尖括号的就是我们要找的文件Inode 号 执行logdump –i <2378808>,然后输入“quit”退出debugfs

    debugfs: logdump -i <2378808> 
    Inode 2378808 is at group 290, block 9438337, offset 2944 
    Journal starts at block 16826, transaction 2237277 
    No magic number at block 30648: end of journal. 
    debugfs: quit

    5、执行以下命令,进行恢复,bs与skip的值分别取自:block 9438337, offset 2944

    dd if=/dev/mapper/VolGroup-lv_root of=/usr/local/test/my.txt bs=2944 count=1 skip=9438337

    bs对应上面的offset后面的值,skip对应block后面的值

    debugfs: quit 
    [root@localhost test]# dd if=/dev/mapper/VolGroup-lv_root of=/usr/local/test/my.txt bs=2944 count=1 skip=9438337 
    记录了1+0 的读入 
    记录了1+0 的写出 
    2944字节(2.9 kB)已复制,0.00989032 秒,298 kB/秒 
    [root@localhost test]# ls 
    my.txt

    至此,刚删除的数据已恢复

  • 相关阅读:
    java.lang.NoClassDefFoundError异常处理
    CMS之promotion failed&concurrent mode failure
    jvm 内存,线程,gc分析
    spring 参数校验
    常用的正则表达式
    《深入理解java虚拟机-高效并发》读书笔记
    ConcurrentHashMap源码分析
    web前端性能调优(二)
    由自动装箱和拆箱引发我看Integer源码
    阅读《effective java-第17条》遇到的问题解决与分享
  • 原文地址:https://www.cnblogs.com/wanghaiyang1930/p/10496128.html
Copyright © 2011-2022 走看看