1.安裝軟體(extundelete依賴於系統的e2fsprogs三個軟體包)
[root@redhat1 home]# mkdir /mnt/cdrom --建立光碟片掛載目錄
[root@redhat1 home]# mount /dev/cdrom /mnt/cdrom --掛載光碟片
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@redhat1 home]# vim /etc/yum.repos.d/base.repo --配置系統的本地源
[base]
name=base
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-REDHAT-6
[root@redhat1 home]# yum install e2fs* --安裝extundelete軟體的依賴包
[root@redhat1 home]# rpm -aq |grep e2fs --檢查軟體包是否安裝
e2fsprogs-devel-1.41.12-14.el6.i686
e2fsprogs-libs-1.41.12-14.el6.i686
e2fsprogs-1.41.12-14.el6.i686
[root@redhat1 home]#wgethttp://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2--下載extundelete軟體包
[root@redhat1 home]# tar xvf extundelete-0.2.4.tar.bz2 --解壓軟體包
[root@redhat1 home]# cd extundelete-0.2.4 --進入軟體包
[root@redhat1 ext3grep-0.10.2]# ./configure --prefix=/usr/local/extundelete && make && make install --安裝軟體
[root@redhat1 ext3grep-0.10.2]# ll /usr/local/ |grep ext --查看軟體安裝成功
drwxr-xr-x. 3 root root 4096 Dec 2 17:24 extundelete
[root@redhat1 ext3grep-0.10.2]#
2.建立塊裝置並掛載系統
[root@redhat1 home]# dd if=/dev/zero of=123 bs=1M count=100 --在home目錄下建立一個塊裝置123
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.634943 s, 165 MB/s
[root@redhat1 home]# mkfs.ext4 123 --格式化塊裝置
mke2fs 1.41.12 (17-May-2010)
123 is not a block special device.
Proceed anyway? (y,n) y --輸入y確定
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@redhat1 home]#mkdir /mnt/123 --建立塊裝置掛載的目錄
[root@redhat1 home]# mount 123 /mnt/123 -o loop --將塊裝置123掛載到/mnt/123中
[root@redhat1 home]# df -TH --查看目錄是否掛載
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
ext4 20G 3.8G 16G 20% /
tmpfs tmpfs 262M 0 262M 0% /dev/shm
/dev/sda1 ext4 508M 32M 451M 7% /boot
df: `/mnt/cdrom': No such file or directory
/dev/sr0 iso9660 3.2G 3.2G 0 100% /mnt
/home/123 ext4 102M 5.8M 91M 7% /mnt/123 --裝置已掛載
3.添加和刪除檔案
[root@redhat1 home]# cp -a /etc/passwd /etc/shadow /etc/group /mnt/123/ --將檔案移動到裝置中
[root@redhat1 ~]# ll /mnt/123/ --查看是否有檔案
total 19
-rw-r--r--. 1 root root 712 Dec 2 14:39 group
drwx------. 2 root root 12288 Dec 4 14:07 lost+found
-rw-r--r--. 1 root root 1509 Dec 2 14:39 passwd
----------. 1 root root 976 Dec 2 14:39 shadow
[root@redhat1 home]# sync --檔案同步一下
[root@redhat1 home]# rm -rf /mnt/123/passwd /mnt/123/shadow --刪除檔案
[root@redhat1 home]# sync --檔案同步一下
[root@redhat1 home]# umount /mnt/123 --卸載裝置
4.恢複剛才刪除的檔案
cd /usr/local/extundelete/bin --進入軟體目錄
[root@redhat1 bin]# ./extundelete --ls --inode 2 /home/123 --查看塊裝置/home/123的檔案詳細資料
./extundelete: unrecognized option '--ls'
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 13 groups loaded.
Group: 0
Contents of inode 2:
0000 | ed 41 00 00 00 04 00 00 fe c6 9e 52 58 c7 9e 52 | .A.........RX..R
0010 | 58 c7 9e 52 00 00 00 00 00 00 03 00 02 00 00 00 | X..R............
0020 | 00 00 00 00 05 00 00 00 10 01 00 00 00 00 00 00 | ................
0030 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0040 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0050 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0060 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0070 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
Inode is Allocated
File mode: 16877
Low 16 bits of Owner Uid: 0
Size in bytes: 1024
Access time: 1386137342
Creation time: 1386137432
Modification time: 1386137432
Deletion Time: 0
Low 16 bits of Group Id: 0
Links count: 3
Blocks count: 2
File flags: 0
File version (for NFS): 0
File ACL: 0
Directory ACL: 0
Fragment address: 0
Direct blocks: 272, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Indirect block: 0
Double indirect block: 0
Triple indirect block: 0
File name | Inode number | Deleted status
. 2
.. 2
lost+found 11
passwd 12 Deleted --Delete就是我們剛才刪除的檔案
shadow 13 Deleted
group 14
[root@redhat1 bin]# ./extundelete --restore-file passwd /home/123 --用檔案名稱來恢複檔案
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 13 groups loaded.
Loading journal descriptors ... 27 descriptors loaded.
Successfully restored file passwd --恢複成功
[root@redhat1 bin]# ./extundelete --restore-inode 13 /home/123 --用節點號來恢複檔案
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 13 groups loaded.
Loading journal descriptors ... 27 descriptors loaded.
[root@redhat1 bin]# ./extundelete --restore-all /home/123 --恢複所有刪除的檔案
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 13 groups loaded.
Loading journal descriptors ... 27 descriptors loaded.
Searching for recoverable inodes in directory / ...
2 recoverable inodes found.
Looking through the directory structure for deleted files ...
0 recoverable inodes still lost.
[root@redhat1 bin]# ll RECOVERED_FILES/ --查看所有恢複的檔案
total 20
drwxr-xr-x. 2 root root 4096 Dec 3 16:21 123
-rw-r--r--. 1 root root 976 Dec 4 14:18 file.13
-rw-r--r--. 1 root root 1509 Dec 4 14:16 passwd
-rw-r--r--. 1 root root 1509 Dec 4 14:20 passwd.v1
-rw-r--r--. 1 root root 976 Dec 4 14:20 shadow
[root@redhat1 bin]#
!!!!!!好了大功告成,也祝大家成功