如何恢复被删除的文件LINUX文件

linux恢复 rm -rf 删除的文件:extundelete - zhengdl126 - ITeye博客
博客分类:
http://blog.csdn.net/pang/article/details/7947011
extundelete需要依赖两个包----e2fsprogs下载地址:http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs/1.41.14/e2fsprogs-1.41.14.tar.gz/download----e2fsprogs-libs下载地址:http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs/1.41.14/e2fsprogs-libs-1.41.14.tar.gz/download ----官网:http://www.sourceforge.net/
extundelete下载地址:http://sourceforge.net/projects/extundelete/files/extundelete/0.2.0/extundelete-0.2.0.tar.bz2/downloadtar -xjf extundelete-0.2.0.tar.bz2按e2fsprogs -- e2fsprogs-libs -- extundelete的顺序逐一编译安装:./configuremakemake install 必须先umount要恢复文件的分区或者把分区改为只读模式,命令:mount –o remout,ro 分区(例如:dev/hda1)或者mount -n -r -o remount /db
最好尽快将所在分区修改为只读方式,防止数据被覆盖使用。# df -h文件系统
可用 已用%% 挂载点/dev/sda3
71% /tmpfs
1% /dev/shm/dev/sda1
27% /boot/dev/sdb1
32% /var/www假如有个分区/dev/sdb1,我把它挂载在/var/www。cd /var/www--------------恢复分区所有被删除的文件:/usr/local/bin/extundelete /dev/sdb1 --restore-all所以恢复的文件都会储存在当前目录下的一个名为RECOVERED_FILES目录下。
--------------根据时间:假如删除的时间大概是 14:30date -d "Jul 26 14:30" +%s得出秒数 恢复此时间后删除的所有文件/usr/local/bin/extundelete /dev/sdb1 --after
--restore-all--------------根据文件名:/usr/local/bin/extundelete /dev/sdb1 --restore-file '1'--------------根据inode恢复文件。查看文件inode:ls -i/usr/local/bin/extundelete /dev/hda3 --restore-inode 222--------------恢复多个文件:创建一个文档,在文档输入文件的路径和名字,一个一行。如restore的内容为:/test/a/test2/bc/usr/local/bin/extundelete /dev/hda3 --restore-files 'restore'
--------------恢复一个被误删除的文件
extundelete /dev/sda3 --restore-file /an/important/file
--------------恢复一个被误删除的文件夹
extundelete /dev/sda3 --restore-directory /an/important
==================================usr/local/bin/extundelete --helpUsage: /usr/local/bin/extundelete [options] [--] device-fileOptions:
--version, -[vV]
Print version and exit successfully.
Print this help and exit successfully.
--superblock
Print contents of superblock in addition to the rest.
If no action is specified then this option is implied.
Show content of journal.
--after dtime
Only process entries deleted on or after 'dtime'.
--before dtime
Only process entries deleted before 'dtime'.Actions:
--inode ino
Show info on inode 'ino'.
--block blk
Show info on block 'blk'.
--restore-inode ino[,ino,...]
Restore the file(s) with known inode number 'ino'.
The restored files are created in ./RESTORED_FILES
with their inode number as extension (ie, file.12345).
--restore-file 'path'
Will restore file 'path'. 'path' is relative to root
of the partition and does not start with a '/' (it
must be one of the paths returned by --dump-names).
The restored file is created in the current
directory as 'RECOVERED_FILES/path'.
--restore-files 'path' Will restore files which are listed in the file 'path'.
Each filename should be in the same format as an option
to --restore-file, and there should be one per line.
--restore-all
Attempts to restore everything.
-j journal
Reads an external journal from the named file.
-b blocknumber
Uses the backup superblock at blocknumber when opening
the file system.
-B blocksize
Uses blocksize as the block size when opening the file
The number should be the number of bytes.You have new mail in /var/spool/mail/root
zhengdl126
浏览: 1657688 次
来自: 深圳
原文的书在哪里
你好,请问个问题,从master同步数据到slave的时候,s ...
你好,看了你的文章,我想请教个问题, 我在用 redis的时候 ...
写得非常好
写得非常好小木虫 --- 600万学术达人喜爱的学术科研平台
热门搜索:
&&查看话题
【求助】如何恢复LINUX系统下删除的文件
在做VASP计算时
不小心把刚算完的文件夹给删了
能不能恢复呢???改怎么恢复呢???
救命啊~~~:cry::cry::cry:
对,据我所知,目前的Linux文件恢复工具都是在windows下运行的。如果不在同一个机器上,可以把Linux的硬盘拆下来,装到windows机器上——这种方法对pc还可以用,cluster基本是不可能了。
说起文件恢复工具,我要大骂诺顿一辈子。当年我由于误删了文件,装了诺顿2000。没想到这个蠢货把每个分区都写了它自己的文件,并且把以前的信息彻底清除,换软件也没法恢复了。我老板积累几十年的实验数据就这么彻底没了。
Linux下有很多软件也有恢复功能,不过需要些技巧。
其实从理论上说,任何支持读写硬盘的16位字符编辑器都能用来恢复非日志文件系统的硬盘上的文件数据如FAT 、EXT2
学术必备与600万学术达人在线互动!
扫描下载送金币用户名:学神讲师MK
文章数:58
评论数:171
访问量:46537
注册日期:
阅读量:1297
阅读量:3317
阅读量:441699
阅读量:1127911
51CTO推荐博文
&Linux基本文件管理本节所讲内容:Linux系统目录结构相对/绝对路径创建/复制/删除文件rm -rf / 意外事故查看文件内容xfs文件系统的备份和恢复extundelete恢复ext4文件系统中误删的文件&Linux系统目录结构/&& 通常称为根分区。所有的文件和目录皆由此开始。只有root用户对此目录拥有写权限。---/etc& 配置文件& 包含所有应用程序的配置文件,也包含启动、关闭某个特定程序的脚本,例如,/etc/passwd,/etc/init.d/network等。---/boot存放Linux系统启动时需要加载的文件。 (一般在另外一个磁盘分区里面保存) Kernel、grub等文件都存放在此。---/var& 是一个可增长的目录,包含很经常变的文件。例如,/var/log(系统日志)、/var/lib (包文件) 、---/root& 管理员所有数据。& root用户的家目录---/tmp& 临时文件存储位置---/usr& usr表示的是unix software source&&&& ---/bin& 命令& 此目录包含二进制可执行文件。---/sbin& 系统命令 ,此目录中的命令主要供系统管理员使用,以进行系统维护。例如,iptables、reboot、fdisk等。/mnt- 挂载目录& 挂载点,系统管理员可用于临时挂载文件系统。&&&& /media---/dev& 包含设备文件。在Linux中,一切都被看做文件。终端设备、USB、磁盘等等都被看做文件,如/dev/sda。---/home& 普通用户所有数据存放在这个目录下& ---/proc  这个目录是一个虚拟的目录,它是系统内存的映射,我们可以通过直接访问这个目录来获取系统信息。也就是说,这个目录的内容不在硬盘上而是在内存里。---/lib  这个目录里存放着系统最基本的动态链接共享库,其作用类似于Windows里的.。几乎所有的应用程序都须要用到这些共享库。绝对路径/相对路径:[root@xuegod163etc]# cd /boot/[root@xuegod163boot]# cd grub/& 表示当前目录创建/查看/复制/删除 文件和文件夹&创建文件和文件夹touch 作用:常用来创建空文件语法: touch 文件名[root@xuegod163 ~]# touch momo&mkdir作用:创建目录语法:mkdir 目录名[root@xuegod163~]# mkdir sljz[root@xuegod163~]# mkdir -p& sljz/syex/xbk-p连同父目录一起创建&[root@xuegod163 ~]# touch a[root@xuegod163 ~]# mkdir amkdir: cannot create directory`a': File exists&查看文件方法:cat作用:查看文件内容语法:cat 文件名&more  查看文件名字例:more& /etc/passwd按下回车刷新一行,按下空格刷新一屏q 退出&less  查看文件名字q 退出使用光标键可以向上翻页linux中more与less的区别more:不支持后退,但几乎不需要加参数,空格键是向下翻页,Enter键是向下翻一行,在不需要后退的情况下比较方便。less:支持前后翻滚,既可以向上翻页(pageup按键),也可以向下翻页(pagedown按键)。,空格键是向下翻页,Enter键是向下翻一行&&head 从第一行开始,查看文件,默认显示前10行&-n 数字&&&显示多少行[root@xuegod163 ~]# head -3/etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologin&tail& 从第后一行开始,查看文件,默认显示最后10行-n& 显示多少行-f& 动态显示数据(不关闭)  常用来查看日志[root@xuegod163~]# tail -f /var/log/messages Nov26 01:59:46 xuegod163 dbus[918]: [system] Activating via systemd: servicename='net.reactivated.Fprint' unit='fprintd.service'Nov26 01:59:46 xuegod163 systemd: Starting Fingerprint Authentication Daemon...Nov26 01:59:46 xuegod163 dbus-daemon: dbus[918]: [system] Successfully activatedservice 'net.reactivated.Fprint'&显示文件的第五行[root@xuegod163~]# head -5 /etc/passwd& | tail -1lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin&复制文件:cp作用:复制文件语法:cp 源文件&目标文件[root@xuegod163~]# cp /etc/passwd& /root/-r 包含子目录和文件& 。[root@xuegod163 ~]# cp& -r /boot/grub/&& /opt/删除文件和文件夹rm&作用:删除文件或目录语法: rm -rf& 文件或目录名-r& 递归删除(可以删除目录和目录里面的东西)-f& 强行删除[root@xuegod163~]# rm -rf passwd&重命名:mv& 语法:mv 源:文件或目录名&&& 目标:文件或目录名[root@xuegod163 ~]# mvpasswd& xiaochuan&&实战:xfs文件系统的备份和恢复&XFS提供了 xfsdump 和 xfsrestore 工具协助备份XFS文件系统中的数据。xfsdump 按顺序备份一个XFS文件系统。与传统的UNIX文件系统不同,XFS不需要在dump前被卸载;对使用中的XFS文件系统做dump就可以保证镜像的一致性。这与XFS对快照的实现不同,XFS的dump和restore的过程是可以被中断然后继续的,无须冻结文件系统。xfsdump 甚至提供了高性能的多线程备份操作――它把一次dump拆分成多个数据流,每个数据流可以被发往不同的目的地。&首先准备测试文件[root@xuegod163 ~]#cp/etc/passwd& /sda3[root@xuegod163 ~]#mkdir/sda3/test&1)对整个分区进行备份[root@xuegod163 ~]#xfsdump& -f /opt/dump_sda3& /sda3注意:备份的设备这里不能写成/sda3/xfsdump: using filedump (drive_simple) strategyxfsdump: version 3.1.4(dump format 3.0) - type ^C for status and control&&============================= dump labeldialog ==============================&please enter label forthis dump session (timeout in 300 sec)&-& dump_sda3#指定备份标签session label entered:"dump_sda3"&&--------------------------------- end dialog---------------------------------&xfsdump: level 0 :/sda3xfsdump: dump date: TueNov 10 21:29:47 2015xfsdump: session id:df2e3d9c-3217-4fba-858c-dxfsdump: session label:"dump_sda3"xfsdump: ino map phase1: constructing initial dump listxfsdump: ino map phase2: skipping (no pruning necessary)xfsdump: ino map phase3: skipping (only one dump stream)xfsdump: ino mapconstruction completexfsdump: estimated dumpsize: 25536 bytesxfsdump:/var/lib/xfsdump/inventory created&&============================= media labeldialog =============================&please enter label formedia in drive 0 (timeout in 300 sec)&-& media0#指定设备标签media label entered:"media0"&&--------------------------------- end dialog---------------------------------&xfsdump: creating dumpsession media file 0 (media 0, file 0)xfsdump: dumping inomapxfsdump: dumpingdirectoriesxfsdump: dumpingnon-directory filesxfsdump: ending mediafilexfsdump: media filesize 23720 bytesxfsdump: dump size(non-dir files) : 2080 bytesxfsdump: dump complete:12 seconds elapsedxfsdump: Dump Summary:xfsdump:&& stream 0 /opt/dump_sda3 OK (success)xfsdump: Dump Status:SUCCESS&&非交互式进行备份[root@xuegod163 ~]#xfsdump -f /opt/dump_sda3 /sda3& -Ldump_sda3 -M media0&针对指定文件或目录进行备份[root@xuegod163~]# xfsdump -f /opt/dump_sda3_a -s& test/sda3& -L dump_sda3_a -M media1注意:a& /sda3中间有空格,前后都不能加“/”&查看备份文件是否生成[root@xuegod163 ~]# ls/opt/dump_sda3& dump_sda3_test& rh&克隆目录到另外一个目录[root@xuegod163 ~]#mkdir /data[root@xuegod163 ~]#xfsdump - /sda3& | xfsrestore& - /data/克隆指定的目录[root@xuegod163~]# xfsdump --s test /sda3 |xfsrestore - /data&查看备份信息[root@xuegod163data]# xfsdump -Ifile system 0:&&&&&& fs id:&&&&&&&&&&&&& 4df2c5b9-98c2-48c0-895f-227c9b816f68&&&&&& session 0:&&&&&&&&&&&&& mount :/sda3&&&&&&&&&&&&& device:&&&&&&&&&& :/dev/sda3&&&&&&&&&&&&& time:&&&&&&&&&&&& Tue Nov 10 21:29:47 2015&&&&&&&&&&&&& session label:"dump_sda3"&&&&&&&&&&&&& session id:&&&& df2e3d9c-3217-4fba-858c-d&&&&&&&&&&&&& level:&&&&&&&&&&&& 0&&&&&&&&&&&&& resumed:&&&&&& NO&&&&&&&&&&&&& subtree:& NO&&&&&&&&&&&&& streams:1&&&&&&&&&&&&& stream 0:&&&&&&&&&&&&&&&&&&&& pathname:&&&& /opt/dump_sda3&&&&&&&&&&&&&&&&&&&& start:&&&&&&&&&&&& ino 131 offset 0&&&&&&&&&&&&&&&&&&&& end:&&&&&&& ino 132 offset 0&&&&&&&&&&&&&&&&&&&& interrupted:&& NO&&&&&&&&&&&&&&&&&&&& media files:&& 1&&&&&&&&&&&&&&&&&&&& media file 0:&&&&&&&&&&&&&&&&&&&&&&&&&&& mfile index:&& 0&&&&&&&&&&&&&&&&&&&&&&&&&&& mfile type:&&&& data&&&&&&&&&&&&&&&&&&&&&&&&&&& mfile size:&&&&& 23720&&&&&&&&&&&&&&&&&&&&&&&&&&& mfile start:&&& ino 131 offset 0&&&&&&&&&&&&&&&&&&&&&&&&&&& mfile end:&&&&& ino 132 offset 0&&&&&&&&&&&&&&&&&&&&&&&&&&& media label:& "media0"&&&&&&&&&&&&&&&&&&&&&&&&&&& media id:&&&&&& 2f7dd88f-1aca-bab8ea799b&文件系统恢复首先,模拟数据被删除[root@xuegod163~]# rm -rf /sda3/*恢复[root@xuegod163~]# xfsrestore -f /opt/dump_sda3 /sda3/只恢复单个的目录或文件[root@xuegod163 ~]#xfsrestore -f /opt/dump_sda3_test -s test /sda3&恢复之前查看备份文件的内容[root@xuegod163~]# xfsrestore& -f /opt/dump_sda3 Ct&&没有基础的同学了解【redhat6.5】实战:恢复误删除的文件exetundelete首先、上传软件包用xshell进行上传[root@xuegod163 ~]# rpm -ihv/mnt/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm warning: /mnt/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm:Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEYPreparing...&&&&&&&&&&&&&&&########################################### [100%]&&&&&& package lrzsz-0.12.20-27.1.el6.x86_64 is already installed&rz上传sz下载&安装extundelete软件包[root@xuegod163 ~]# tar jxvfextundelete-0.2.4.tar.bz2&&&&&&&&&&&&&&&&&&&& #解压[root@xuegod163 ~]# cdextundelete-0.2.4[root@xuegod163extundelete-0.2.4]# ./configure Configuring extundelete 0.2.4configure: error: Can't find ext2fslibrary&解决办法[root@xuegod163extundelete-0.2.4]# uname -r2.6.32-431.el6.x86_64[root@xuegod163extundelete-0.2.4]# rpm Cihv&&& /mnt/Packages/e2fsprogs-devel-1.41.12-18.el6.x86_64.rpm&[root@xuegod163extundelete-0.2.4]# ./configure&&&&&&&&&&&&&&&&&&&&&&&&&&&& #配置[root@xuegod163extundelete-0.2.4]# make &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& #编译make -s all-recursiveMaking all in srcextundelete.cc:571: warning:unused parameter ‘flags’[root@xuegod163extundelete-0.2.4]# make install&&&&&&&&&&&&&&&&&&&&&&&&&& #安装Making install in src& /usr/bin/install -c extundelete'/usr/local/bin'&准备测试分区[root@xuegod163 ~]# fdisk/dev/sda&WARNING: DOS-compatible modeis deprecated. It's strongly recommended toswitch off the mode (command'c') and change display units tosectors (command 'u').&Command (m for help): nCommand actione&& extendedp&& primary partition (1-4)pSelected partition 4First cylinder (,default 1428):& Using default value 1428Last cylinder, +cylinders or+size{K,M,G} (, default 2610): +1G&Command (m for help): p&Disk /dev/sda: 21.5 GB, bytes255 heads, 63 sectors/track,2610 cylindersUnits = cylinders of 1 = 8225280 bytesSector size(logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal):512 bytes / 512 bytesDisk identifier: 0x0000fff2&&& Device Boot&&&&& Start&&&&&&&& End&&&&& Blocks&&Id& System/dev/sda1&& *&&&&&&&&&&1&&&&&&&&& 26&&&&& & LinuxPartition 1 does not end oncylinder boundary./dev/sda2&&&&&&&&&&&&& 26&&&&&&& 1301&&&&& 83& Linux/dev/sda3&&&&&&&&&&& 1301&&&&&&& 1428&&&&1024000&& 82& Linux swap / Solaris/dev/sda4&&&&&&&&&&& 1428&&&&&&& 1559&&&&1052843+& 83& Linux&Command (m for help): wThe partition table has beenaltered!&Calling ioctl() to re-readpartition table.&WARNING: Re-reading the partitiontable failed with error 16: Device or resource busy.The kernel still uses the oldtable. The new table will be used atthe next reboot or after yourun partprobe(8) or kpartx(8)Syncing disks.&&reboot重启系统[root@xuegod163 ~]#mkfs.ext4& /dev/sda4&&&&&&&&&&&&&&&&&&&&&&&&&&&&& #格式化分区[root@xuegod163 ~]# mkdir/sda4&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& #创建挂载点[root@xuegod163 ~]# mount/dev/sda4 /sda4/&&&&&&&&&&&&&&&&&&&&&&&& #挂载分区[root@xuegod163 ~]# df Ch&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& #查看挂载状况FilesystemSize& Used Avail Use% Mounted on/dev/sda2&&&&&& 9.7G&3.8G& 5.4G& 42% /tmpfs&&&&&&&&&& 2.0G&224K& 2.0G&& 1% /dev/shm/dev/sda1&&&&&& 194M&&34M& 151M& 19% /boot/dev/sr0&&&&&&& 3.6G&3.6G&&&& 0 100% /mnt/dev/sda4&&&&& 1012M&&34M& 928M&& 4% /sda4&准备测试文件[root@xuegod163 ~]# cp/etc/passwd& /sda4/[root@xuegod163 ~]# cp/etc/hosts&& /sda4/[root@xuegod163 ~]# mkdir -p/sda4/a/b/c[root@xuegod163 ~]# cp/etc/passwd& /sda4/a/[root@xuegod163 ~]# touch/sda4/a/b/kong.txt&删除文件[root@xuegod163 ~]# cd& /sda4/[root@xuegod163 sda4]# lsa& hostslost+foundpasswd[root@xuegod163 sda4]# rm -rfa hosts& passwd&卸载要恢复的分区或者以只读的方式进行挂载[root@xuegod163 ~]# umount/dev/sda4&恢复文件查看要恢复分区的文件删除状态信息[root@xuegod163 ~]#extundelete /dev/sda4 --inode 2………………File name&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& | Inodenumber | Deleted status.&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&2..&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&2lost+found&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 11passwd&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&12&&&&&&&&&&&& Deletedhosts&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&13&&&&&&&&&&&& Deleteda&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7313&&&&&&&&&& Deleteda.txt&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&17&&&&&&&&&&&& Deleted&方法一:通过inode进行恢复[root@xuegod163 test]#extundelete /dev/sda4& --restore-inode 12[root@xuegod163 test]# lsRECOVERED_FILES/file.12[root@xuegod163 test]# diff/etc/passwd RECOVERED_FILES/file.12&方法二:通过文件名进行恢复[root@xuegod163 test]#extundelete /dev/sda4&--restore-file& passwd&方法三:通过目录进行恢复[root@xuegod163 test]#extundelete /dev/sda4&--restore-directory& a&方法四:恢复所有文件[root@xuegod163 test]#extundelete /dev/sda4& --restore-all&通过extundelete命令不能恢复空文件和空目录&&学习过程中如果问题,请留言。更多内容请加:学神IT-linux讲师-RM老师QQ: 学神IT-戚老师QQ: 学神IT-旭斌QQ:学神IT教育RHEL7交流群:本文出自 “” 博客,转载请与作者联系!
了这篇文章
类别:未分类┆阅读(0)┆评论(0)
23:17:24 23:34:24 08:26:23 08:32:03 23:46:01 15:00:59

我要回帖

更多关于 文件被删除怎么恢复 的文章

 

随机推荐