Linuxで消したファイルを復活させるには・・・?

我が家のネットワークでは、debian上でsambaをファイルサーバーとしているが、誤ってファイルを削除してしまうことがある。

そう言った事態に備えて、定期的にミラーリングバックアップを自動で撮るようにしているが、しかし、それは一部のディレクトリであり、テレビ録画や、動画などの大容量ファイルは対象としていない。

ところが、動画編集の際、エンコードが終わったと思って元ファイルを削除したが、ファイル名をつけ誤り、それが元で、エンコード前の別の元ファイルを削除してしまった・・・。

こうなってしまっては、LinuxにはWindowsのようなゴミ箱昨日は無いので、ファイル復旧は出来ない、ということになっている。

こういった事態に備えるために、Sambaサーバーでゴミ箱機能を提供していたりするが、このサーバーでは導入していない。

そこまで重要なファイルでは無かったものの、これが超重要なファイルだったりすると一大事!

そう言った事態に備え、近亜紀ファイル復元にチャレンジしてみた。結論から言うと成功したので、備忘録として残しておこうと思う。

ファイル復元の方法は、extundeleteというツール。参考としたのは、こことか、ここなど。

このサーバーのファイルシステムはext3なので、このツールが使える。

まずは速攻で、対象ファイルのあるドライブをアンマウント。

# mount -o remount,ro /mnt/sdb1

そして、synapticsからextundeleteをインストールしようとしたが、対応していないらしい。仕方がないので、ソースファイルをダウンロードし、インストールすることにした。

手順としては、こんな感じ。

# cd /tem
# mkdir a
# cd a

$ tar -jxvf extundelete-0.2.4.tar.bz2
$ cd extundelete-0.2.4
$ ./configure

すると、こんなメッセージが。

Configuring extundelete 0.2.4
configure: error: Can't find ext2fs library

ext2fs libraryがインストールされていないらしい。これはsynapticsに対応していたので、そちらからインストール。

そして再び、

$ ./configure

Configuring extundelete 0.2.4
Writing generated files to disk

OKみたい。続けて、

$ make
$ su -
# make install

Making install in src
  /usr/bin/install -c extundelete '/usr/local/bin'

こんなメッセージでインストール完了。

そして、extundeleteコマンドを入力。

# /tmp/a/extundelete-0.2.4# extundelete --restore-all --after `date -d "2014/05/11 00:00" +%s` /dev/sdb1

対象ドライブはsdb1のみ、かつ、2014/05/11 00:00以降に削除されたファイルとした。そして待つこと、約10分ほどで、次のメッセージが。

Only show and process deleted entries if they are deleted on or after 1399734000 and before 2147483647.
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 14905 groups loaded.
Loading journal descriptors ... 30537 descriptors loaded.
Searching for recoverable inodes in directory / ...
32 recoverable inodes found.
Looking through the directory structure for deleted files ...
Unable to restore inode 59351048 (share/Picture/140510/DSC_3717.jpg~RF28bee4b7.TMP): No undeleted copies found in the journal.
Unable to restore inode 56270865 (share/temp/動画編集/Aviutl/新しいフォルダー): No undeleted copies found in the journal.
Unable to restore inode 94502941 (regza/M51681234201405070015b7338642.dtv): No undeleted copies found in the journal.
Unable to restore inode 94503055 (regza/M51681241201405100015b7338642.dtv.rat): No undeleted copies found in the journal.
Unable to restore inode 94503001 (regza/M5168123f201405090015b7338642.dtv.rec): No undeleted copies found in the journal.
Unable to restore inode 94503052 (regza/M516811e7201404110015b7338642.dtv.rat): No undeleted copies found in the journal.
Unable to restore inode 56270863 (video/mp4/新しいフォルダー): No undeleted copies found in the journal.
Unable to restore inode 56270857 (video/MOV/140510/1405010 ******/MVI_5369.MOV): Space has been reallocated.
Block 235438594 is allocated.
11 recoverable inodes still lost.
Unable to restore inode 56270862 (file.56270862): No undeleted copies found in the journal.
Unable to restore inode 56270864 (file.56270864): No undeleted copies found in the journal.
Unable to restore inode 56270875 (file.56270875): No undeleted copies found in the journal.
Unable to restore inode 56270878 (file.56270878): No undeleted copies found in the journal.
Unable to restore inode 59351051 (file.59351051): No undeleted copies found in the journal.
Unable to restore inode 94502933 (file.94502933): No undeleted copies found in the journal.
Unable to restore inode 94503053 (file.94503053): No undeleted copies found in the journal.
Unable to restore inode 94503054 (file.94503054): No undeleted copies found in the journal.
Unable to restore inode 99647543 (file.99647543): No undeleted copies found in the journal.

コマンドを実行したカレントディレクトリに、RECOVERED_FILESというディレクトリができており、その中身を確認すると・・・。

なんと、消えたファイルがディレクトリごと、丸々復元されておりました!

ということで、無事ファイルを復旧できましたので、忘れずにリードオンリーとしたsdb1を戻しておきます。

# mount -o remount,rw /mnt/sdb1

めでたし、めでたし。

コメント

このブログの人気の投稿

Canon EF 28-105mm F3.5-4.5 II USMをGet!

回転計なしで、RCヘリのローター回転数(rpm)を計測する方法