1. 程式人生 > >centos6上誤刪除了文件怎樣恢復?

centos6上誤刪除了文件怎樣恢復?

extundelete

centos6上誤刪除了文件怎樣恢復?

  • 創建一個新磁盤 /dev/sdb,創建分區 /dev/sdb1,格式化,掛載到 /tmp/sdb1上

  • 模擬環境
mkdir /tmp/sdb1
cp /etc/passwd /tmp/sdb1/
cp /etc/hosts /tmp/sdb1/
mkdir -p /tmp/sdb1/a/b/c
echo aaa > /tmp/sdb1/a.txt
echo bbb > /tmp/sdb1/a/b/b.txt
touch /tmp/sdb1/a/b/kong.txt
cd /tmp/sdb1/
rm -rf a a.txt hosts passwd
  • 安裝 extundelete
yum install e2fsprogs-devel -y
cd /usr/local/src/
wget https://sourceforge.net/projects/extundelete/files/latest/download/extundelete-0.2.4.tar.bz2
tar jxvf extundelete-0.2.4.tar.bz2
cd extundelete-0.2.4
yum install gcc-c++ -y
./configure --prefix=/usr/local/extundelete && make && make install
  • 卸載 /tmp/sdb1
umount /tmp/sdb1/
  • 查看刪除掉的文件
/usr/local/extundelete/bin/extundelete /dev/sdb1/ --inode 2
  • 恢復所有
/usr/local/extundelete/bin/extundelete /dev/sdb1 --restore-all

常用選項

/usr/local/extundelete/bin/extundelete /dev/sdb1 --restore-inode 12
/usr/local/extundelete/bin/extundelete /dev/sdb1 --restore-file passwd
/usr/local/extundelete/bin/extundelete /dev/sdb1 --restore-directory a

查看 extundelete 的幫助信息

/usr/local/extundelete/bin/extundelete -h

centos6上誤刪除了文件怎樣恢復?