Hướng dẫn khôi phục file bị xóa trên Linux/Unix


Nếu bạn nhỡ tay chạy lệnh xóa file trên Linux/Unix thì đừng quá lo lắng. Bạn vẫn có thể khôi phục được nếu như ổ đĩa khu vực chứa file chưa bị ghi đè. Các cách sau đây sẽ giúp bạn khôi phục lại file một cách dễ dàng.

Cách 1: Khôi phục file bị xóa sử dụng phần mềm Foremost

Giới thiệu Foremost

Foremost là phần mềm tìm kiếm và khôi phục file bị xóa dựa vào phần header, footerdata structure của file.

Cài đặt Foremost

Foremost có sẵn trong Linux Mint, Debian và Ubuntu và bạn có thể cài đặt dễ dàng bằng command sau:

[admin@vinasupport.com]$ sudo apt-get install foremost

Với các bản phần phối CentOS/RHEL

[admin@vinasupport.com]$ cd /tmp
[admin@vinasupport.com]$ wget https://forensics.cert.org/centos/cert/7/x86_64//foremost-1.5.7-13.1.el7.x86_64.rpm
[admin@vinasupport.com]$ sudo rpm -ivh foremost-1.5.7-13.1.el7.x86_64.rpm

Với các bản phần phối Linux/ Unix khác thì tìm kiếm ở đây: https://pkgs.org/download/foremost

Sử dụng Foremost

Đầu tiên mình thực xóa 1 file bất kỳ

Sau đó dùng Foremost khôi phục file xóa bằng command sau:

[admin@vinasupport.com]$ mkdir /tmp/restored
[admin@vinasupport.com]$ foremost -i /dev/sda2 -t jpg -o /tmp/restored

Cuối cùng kiểm tra file đã khôi phục

Cách 2: Sử dụng debugfs

Thử tự khôi phục file bị xóa với debugfs như sau:

Bước 1: Sử dụng debugfs để kiểm tra filesystems log

[admin@vinasupport.com]$  debugfs -w /dev/mapper/centos-root

Bước 2: Ở debugfs console chạy command sau:

debugfs: lsdel
Inode Owner Mode Size Blocks Time deleted
23601299 0 120777 3 1/ 1 Tue Mar 13 16:17:30 2012
7536655 0 120777 3 1/ 1 Tue May 1 06:21:22 2012
2 deleted inodes found.

Bước 3: Get thông tin file đã xóa

debugfs: logdump -i <7536655>
...
...
....
output truncated
Fast_link_dest: bin
Blocks: (0+1): 7235938
FS block 7536642 logged at sequence 38402086, journal block 26711
(inode block for inode 7536655):
Inode: 7536655 Type: symlink Mode: 0777 Flags: 0x0 Generation: 3532221116
User: 0 Group: 0 Size: 3
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 0
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x4f9fc732 -- Tue May 1 06:21:22 2012
atime: 0x4f9fc730 -- Tue May 1 06:21:20 2012
mtime: 0x4f9fc72f -- Tue May 1 06:21:19 2012
dtime: 0x4f9fc732 -- Tue May 1 06:21:22 2012
Fast_link_dest: bin
Blocks: (0+1): 7235938
No magic number at block 28053: end of journal.

Bước 4: Khôi phục file đã xóa bằng command sau:

[admin@vinasupport.com]$  dd if=/dev/mapper/wks01-root of=recovered.file.001 bs=4096 count=1 skip=7235938
# file recovered.file.001
file: ASCII text, with very long lines

File khôi phục là: recovered.file.001

Sau khi xóa file, hãy thực hiện khôi phục lại càng sớm càng tốt, sẽ tăng khả năng lấy lại dữ liệu đã mất.

 

 

 

             
SHARE

Bài viết liên quan

mode_edit Bình luận của bạn

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

account_circle
web