Restore accidentally deleted files in CentOS

Source: Internet
Author: User
In CentOS, if a file is accidentally deleted, perform the following steps to restore the file. 1. disable all services. when files are deleted by mistake, in order to restore data as much as possible, you must first disable all ongoing services and avoid data writing, otherwise, the probability of recovery is lower. We can directly # killall process name or # kill-9pid and then remount the partition where The accidentally deleted file is located

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

# Wget http://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2

# 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.