Linuxで消したファイルを復活

間違えてファイル消しちゃいました。

rm -fr file* とやるはずが、rm -fr file * とスペースを入れたのが敗因……

あわてて調べて、消したファイルを復活。
消してしまったファイルは /home/xi/work/ 以下のファイル群。

手順


$ df -T
Filesystem    Type   1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/vg_centos664bit-lv_root
              ext4    26391624   6428564  18622440  26% /
tmpfs        tmpfs      510244         0    510244   0% /dev/shm
/dev/sda1     ext4      495844     74185    396059  16% /boot

# コンパイルに足りないファイルがあるようなのでインストール
$ sudo yum install -y gcc-c++ e2fsprogs-devel

# 証明書で怒られるので --no-check-certificate をつける
$ wget --no-check-certificate http://sourceforge.net/projects/extundelete/files/extundelete/0.2.4/extundelete-0.2.4.tar.bz2/download

$ tar jxvf extundelete-0.2.4.tar.bz2
$ cd extundelete-0.2.4
$ ./configure
Configuring extundelete 0.2.4
Writing generated files to disk
$ make
make -s all-recursive
Making all in src
extundelete.cc:571: 警告: unused parameter ‘flags’

# src の下に extundelete が出来ている

$ cd src

# 14:40 以降に消えたファイルを復活
$ sudo ./extundelete --restore-all --after `date -d "14:40" +%s` /dev/mapper/vg_centos664bit-lv_root
Only show and process deleted entries if they are deleted on or after 1456897200 and before 9223372036854775807.
NOTICE: Extended attributes are not restored.
WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set.
The partition should be unmounted to undelete any files without further data loss.
If the partition is not currently mounted, this message indicates
it was improperly unmounted, and you should run fsck before continuing.
If you decide to continue, extundelete may overwrite some of the deleted
files and make recovering those files impossible.  You should unmount the
file system and check it with fsck before using extundelete.
Would you like to continue? (y/n)

あわてていたのでそのまま実行してしまったが、ディスクをいったんReadOnlyでマウントし直すのが常識のよう。

後で分かったのだけど、目的のディレクトリーやファイルが分かっているならば --restore-directory や --restore-file というオプションが良さそう。

戻る