Restore accidentally deleted files in CentOS

Source: Internet
Author: User

Restore accidentally deleted files in CentOS

In CentOS, if a file is accidentally deleted, perform the following steps to restore the file.

1. Disable all services

When a file is accidentally deleted, in order to restore data as much as possible, you must first disable all ongoing services and do not write data. Otherwise, the probability of recovery is lower. We can directly

# Killall process name

Or

# Kill-9 pid

Then, re-mount the partition where the deleted file is located to read-only

# Mount-o ro/dev/sdb/data/

2. Install the extundelete Tool

# Yum install-y e2fsprogs * // install the dependency package

# Wgethttp: // response

# Tar-jxvf extundelete-0.2.4.tar.bz2

# Cd extundelete-0.2.4

#./Configure -- prefix =/usr/local/extundelete
# Make & make install

3. verify whether the installation is successful

# Cd/usr/local/extundelete/bin
#./Extundelete-v
---------------------
Extundelete version 0.2.4
Libext2fs version 1.41.12
Processor is little endian.
---------------------

4. Restore data

Example: If we accidentally delete the file test.txt, the partition is/dev/sdb.
1) scan files
#/Usr/local/extundelete/bin/extundelete/dev/sdb -- inode 2 // scan which files are deleted
2) Restore Files

#/Usr/local/extundelete/bin/extundelete -- restore-file test.txt/dev/sdb

3) view files
The recovered files are stored in the RECOVERED_FILES/directory of the current directory.
# Ls./RECOVERED_FILES/

You can see the test.txt file.

Note:

To restore files in the entire partition, run the following command:
#/Usr/local/extundelete/bin/extundelete -- restore-all/dev/sdb
The recovered files are also in the./RECOVERED_FILES/directory.

5. Follow-up work

1) Remount the partition to writable.
2) Back up important data.
3) overwrite the recovered data.
4) restart the server to restore services that have been previously disabled.

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.