Recover files that were mistakenly deleted under Linux (note)

Source: Internet
Author: User

Recover files that were mistakenly deleted under Linux

[Email protected] ~]# mount/dev/cdrom/mnt/

Divided into a district: sda4

Search: Extundelete

Divided into a district: sda4

[Email protected] ~]# MKDIR/TMP/SDA4

[email protected] ~]# mkfs.ext4/dev/sda4 Formatting

[[email protected] desktop]# echo $?

0

[Email protected] ~]# mount/dev/sda4/tmp/sda4/

[email protected] ~]# df-th # View disk-related information

[Email protected] desktop]# MOUNT/DEV/SDA4/TMP/SDA4

[Email protected] desktop]# df-h

Filesystem Size used Avail use% mounted on

/dev/sda2 9.7G 3.8G 5.5G 41%/

Tmpfs 569M 264K 569M 1%/DEV/SHM

/DEV/SDA1 194M 28M 157M 15%/boot

/dev/sr0 3.4G 3.4G 0 100%/mnt

/DEV/SDA4 1012M 34M 928M 4%/tmp/sda4

Copy some of the files used to test the deletion:

[Email protected] ~]# cp/etc/passwd/tmp/sda4/

[Email protected] ~]# cp/etc/hosts/tmp/sda4/

[email protected] ~]# vim/tmp/sda4/a.txt #vim Edit A.txt Write some data casually.

[Email protected] ~]# mkdir-p/tmp/sda4/a/b/c

[Email protected] ~]# cp/tmp/sda4/a.txt/tmp/sda4/a

[Email protected] ~]# cp/tmp/sda4/a.txt/tmp/sda4/a/b/

Delete:

[Email protected] ~]# Mkdir/tmp/back

[Email protected] ~]# cp-r/tmp/sda4/*/tmp/back

[Email protected] ~]# cd/tmp/sda4/

[Email protected] ~]# RM-RF passwd hosts a a.txt

[Email protected] ~]# ls/tmp/sda4/

Lost+found

Unmount the partition where the file needs to be recovered: Inode

[[Email protected] sda4]# CD

[Email protected] ~]# umount/tmp/sda4/

Installing the Software Extundelete

[Email protected] ~]# tar jxvf extundelete-0.2.4.tar.bz2

[Email protected] ~]# CD extundelete-0.2.4

[Email protected] extundelete-0.2.4]#./configure

Configuring Extundelete 0.2.4

Configure:error:Can ' t find ext2fs Library # Error

[Email protected] ~]# mount/dev/cdrom/mnt/

[Email protected] extundelete-0.2.4]# rpm-ivh/mnt/packages/e2fsprogs-devel-1.41.12-11.el6.x86_64.rpm

[Email protected] extundelete-0.2.4]#

[[email protected] extundelete-0.2.4]#./configure # Check the installation environment and generate makefile

[[email protected] extundelete-0.2.4]# make # compiling

[[email protected] extundelete-0.2.4]# make install # installation

Find a blog: http://www.cnblogs.com/jjzd/p/5785851.html

Installing e2fsprogs-devel-1.41.12-14.el6.x86_64.rpm

Start recovery:

Method 1:

To view the deleted file name through the Inode node:

[Email protected] ~]# mkdir test

[Email protected] ~]# CD test/

[Email protected] ~]# EXTUNDELETE/DEV/SDA4--inode 2

。。。

Lost+found 11

passwd Deleted

Hosts Deleted

A 8193 Deleted

A.txt Deleted

To recover from an inode node:

[Email protected] ~]# EXTUNDELETE/DEV/SDA4--restore-inode 12

notice:extended attributes is not restored.

Loading FileSystem metadata ... Groups loaded.

Loading Journal Descriptors ... Descriptors loaded.

[[email protected] ~]# ls recovered_files/# Recovery Success

file.12

[Email protected] test]# diff/etc/passwd/root/test/recovered_files/file.12

Method Two, restore by file name

Method Two, restore by file name

To recover a file:

[Email protected] test]# RM-RF recovered_files/

[Email protected] ~]# extundelete/dev/sda4--restore-file passwd

Restore a directory , such as all files under directory A:

[email protected] ~]# extundelete/dev/sda4--restore-directory a # Recover Directory A, no

Recover all the files

[Email protected] ~]# extundelete/dev/sda4--restore-all

Usage Experience:

An empty directory or an empty file recovery was unsuccessful.

Restore deleted files under Linux (note)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.