设为首页 收藏本站
查看: 608|回复: 0

[经验分享] centos rm文件删除恢复

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-6-9 09:00:16 | 显示全部楼层 |阅读模式
系统是centos 6.5 x64位系统
rm文件删除之后,恢复比较麻烦。
可以使用extundelete进行恢复
目前最新版本是0.2.4
extundelete 主页:http://extundelete.sourceforge.net/
下载软件
wget http://fossies.org/linux/misc/extundelete-0.2.4.tar.gz
安装组件
yum install -y e2fsprogs e2fsprogs-devel e2fsprogs-libs
安装extundelete

tar zxvf extundelete-0.2.4.tar.gz -C /usr/src/
cd /usr/src/extundelete-0.2.4/
./configure
make
make install

恢复的时候,需要卸载分区。如果你需要的恢复的文件在根分区,那么需要在另外一台服务器进行恢复。
所以我挂载了一个测试分区
[iyunv@localhost ~]# df -hT
Filesystem                   Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4    29G  1.2G   26G   5% /
tmpfs                        tmpfs  246M     0  246M   0% /dev/shm
/dev/sda1                    ext4   485M   33M  427M   8% /boot
/dev/sdb1                    ext4  1008M   18M  940M   2% /test

写入文件,内容是111

[iyunv@localhost ~]# vi /test/1.txt
删除文件
[iyunv@localhost ~]# rm -rf /test/*


结束使用某分区的进程树

[iyunv@localhost ~]# fuser -k /test

卸载分区
[iyunv@localhost ~]# umount /test/
使用extundelete查看分区上存在的文件
--inode 为查找某i节点中的内容,使用2则说明为搜索,如果需要进入目录搜索,只须要指定目录I节点即可

[iyunv@localhost ~]# extundelete --inode 2 /dev/sdb1
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 8 groups loaded.
Group: 0
Contents of inode 2:
0000 | ed 41 00 00 00 10 00 00 a9 bf 75 55 a8 bf 75 55 | .A........uU..uU
0010 | a8 bf 75 55 00 00 00 00 00 00 02 00 08 00 00 00 | ..uU............
0020 | 00 00 00 00 09 00 00 00 49 00 00 00 00 00 00 00 | ........I.......
0030 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0040 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0050 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0060 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0070 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0080 | 1c 00 00 00 28 6d b5 65 28 6d b5 65 78 80 59 bf | ....(m.e(m.ex.Y.
0090 | 6c bf 75 55 00 00 00 00 00 00 00 00 00 00 00 00 | l.uU............
00a0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00b0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00c0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00d0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00e0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00f0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................

Inode is Allocated
File mode: 16877
Low 16 bits of Owner Uid: 0
Size in bytes: 4096
Access time: 1433780137
Creation time: 1433780136
Modification time: 1433780136
Deletion Time: 0
Low 16 bits of Group Id: 0
Links count: 2
Blocks count: 8
File flags: 0
File version (for NFS): 0
File ACL: 0
Directory ACL: 0
Fragment address: 0
Direct blocks: 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Indirect block: 0
Double indirect block: 0
Triple indirect block: 0

File name                                       | Inode number | Deleted status
.                                                 2
..                                                2
lost+found                                        11             Deleted
.1.txt.swp                                        12             Deleted
1.txt                                             13             Deleted

从以上信息,可以看出,需要恢复的文件1.txt的I节点为13

恢复文件
--restore-inode 恢复指定的I节点文件,默认全将恢复出来的文件放在当前路径 RECOVERED_FILES/ 目录下,文件名为 file.I节点号

[iyunv@localhost ~]# extundelete --restore-inode 13 /dev/sdb1
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 8 groups loaded.
Loading journal descriptors ... 23 descriptors loaded.
查看目录是否有文件
[iyunv@localhost ~]# ll RECOVERED_FILES/
total 4
-rw-r--r-- 1 root root 4 Jun  9 00:33 file.13
查看文件内容

[iyunv@localhost ~]# cat RECOVERED_FILES/file.13
111
重新挂载分区,恢复文件,查看文件内容

[iyunv@localhost ~]# mount /dev/sdb1 /test/
[iyunv@localhost ~]# mv RECOVERED_FILES/file.13 /test/1.txt
[iyunv@localhost ~]# cat /test/1.txt
111



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-75327-1-1.html 上篇帖子: linux samba 配置 tag 下篇帖子: Restful Web Service - Http应用层的协议
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表