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.