2011-01-23
Linuxでうっかりrm -rfしちゃったけど復活出来たよー\(^o^)/
サーバのファイル整理作業をしていたところ…、
間違えてrm -rfしてしまった!
ぎゃーバックアップもねー!
長いこと生きてたらこんな経験の1度や2度はありますよね?
えぇ、ついさっきやらかしちゃいましたwwオワタwww
速攻「rm 復活」とかでググッたねw、したらmcってプログラムのUndelete機能使えばよいって情報が出てくるが、どうやらこれext2じゃないと使えないっぽいぞ…、うちext4だ。
混乱。以下ターミナルのヒストリーより実況。
## こーいうときはまずあれだ、現場保存! ## まずは今いるパーティションを確認 # df -hT Filesystem Type サイズ 使用 残り 使用% マウント位置 /dev/sdb2 ext4 193G 6.9G 176G 4% / /dev/sdb1 ext3 194M 22M 163M 12% /boot /dev/sdb5 ext4 1.2T 752G 371G 67% /home ←イマココ tmpfs tmpfs 999M 0 999M 0% /dev/shm ## とりあえず読み込み専用にしておこう! # mount -o remount,ro /dev/sdb5 # touch /home/hoge touch: cannot touch `/home/hoge': 読み込み専用ファイルシステムです ## うし、ちゃんとリードオンリーになったな ## あと何だ?とりあえず時間メモ! # date 2011年 1月 23日 日曜日 18:15:22 JST ## ふぅ、さてひとまずこれでいいだろう、あとはext4の復元方法をググりまくるぞー…。 ## どうやら extundelete ってのがext3/ext4対応の復活プログラムらしい。 ## 藁にもすがる思いでインストール。とりあえず/tmpでいいや。 # cd /tmp # mkdir a # cd a # wget "http://downloads.sourceforge.net/project/extundelete/extundelete/0.2.0/extundelete-0.2.0.tar.bz2?r=http%3A%2F%2Fextundelete.sourceforge.net%2F&ts=1295777113&use_mirror=jaist" # ls extundelete-0.2.0.tar.bz2 # tar xfj extundelete-0.2.0.tar.bz2 # extundelete-0.2.0 # ./configure --prefix=/tmp/a && make && make install ## ビルド待ち…、うしっなんか出来たっぽい! ## んー何々…? # /tmp/a/bin/extundelete No action specified; implying --superblock. Usage: /tmp/a/bin/extundelete [options] [--] device-file Options: --version, -[vV] Print version and exit successfully. --help, Print this help and exit successfully. --superblock Print contents of superblock in addition to the rest. If no action is specified then this option is implied. --journal Show content of journal. --after dtime Only process entries deleted on or after 'dtime'. --before dtime Only process entries deleted before 'dtime'. Actions: --inode ino Show info on inode 'ino'. --block blk Show info on block 'blk'. --restore-inode ino[,ino,...] Restore the file(s) with known inode number 'ino'. The restored files are created in ./RESTORED_FILES with their inode number as extension (ie, file.12345). --restore-file 'path' Will restore file 'path'. 'path' is relative to root of the partition and does not start with a '/' (it must be one of the paths returned by --dump-names). The restored file is created in the current directory as 'RECOVERED_FILES/path'. --restore-files 'path' Will restore files which are listed in the file 'path'. Each filename should be in the same format as an option to --restore-file, and there should be one per line. --restore-all Attempts to restore everything. -j journal Reads an external journal from the named file. -b blocknumber Uses the backup superblock at blocknumber when opening the file system. -B blocksize Uses blocksize as the block size when opening the file system. The number should be the number of bytes. Error parsing command-line options. ## ふむ、どうやらパーティション&時間指定で復元できるっぽいな? ## dtime って何だろ…、helpだと分からんかったのでサイトのマニュアル読む… ## エポック秒で指定すればいいんだな。 ## 取ってて良かった時間メモ、18:15ってことは18:00以降くらいでいいだろ。 # date -d "18:00" 2011年 1月 23日 日曜日 18:00:00 JST ## うむ、じゃエポックは…、と # date -d "18:00" +%s 1295773200 ## うし、じゃこんな感じかな? # /tmp/a/bin/extundelete --after 1295773200 --restore-all /dev/sdb5 Only show and process deleted entries if they are deleted on or after 1295773200 and before 2147483647. WARNING: Extended attributes are not restored. Loading filesystem metadata ... 9607 groups loaded. Loading journal descriptors ... 28902 descriptors loaded. Writing output to directory RECOVERED_FILES/ Searching for recoverable inodes in directory / ... 327 recoverable inodes found. Looking through the directory structure for deleted files ... Restored inode 3373 to file RECOVERED_FILES/share/家中共有/読み聞かせ/こころ441p.WAV Restored inode 3374 to file RECOVERED_FILES/share/家中共有/読み聞かせ/お侍をだましたキツネ.WAV Restored inode 3376 to file RECOVERED_FILES/share/家中共有/読み聞かせ/金色の馬.WAV Restored inode 3377 to file RECOVERED_FILES/share/家中共有/読み聞かせ/梨の実 小山内薫.WAV Restored inode 3378 to file RECOVERED_FILES/share/家中共有/読み聞かせ/カメとイノシシ.WAV Restored inode 3379 to file RECOVERED_FILES/share/家中共有/読み聞かせ/こころ474P.WAV Restored inode 3380 to file RECOVERED_FILES/share/家中共有/読み聞かせ/長者になりそこねた欲張り.WAV Restored inode 3381 to file RECOVERED_FILES/share/家中共有/読み聞かせ/こころ515P.WAV Restored inode 3382 to file RECOVERED_FILES/share/家中共有/読み聞かせ/大きな玉のサルと、ネコと、犬と、ニワトリ.WAV Restored inode 3385 to file RECOVERED_FILES/share/家中共有/読み聞かせ/トカトントン 太宰治.WAV Restored inode 3384 to file RECOVERED_FILES/share/家中共有/読み聞かせ/トビの鳴き声.WAV Restored inode 3396 to file RECOVERED_FILES/share/家中共有/読み聞かせ/狢 芥川龍之介.WAV Restored inode 3399 to file RECOVERED_FILES/share/家中共有/読み聞かせ/車 宮沢賢治.WAV Restored inode 3400 to file RECOVERED_FILES/share/家中共有/読み聞かせ/カエルの泳ぎ自慢.WAV Restored inode 3409 to file RECOVERED_FILES/share/家中共有/読み聞かせ/栗拾い.WAV :
おぉおおおおお!?ls、find、内容チェック…、やったー復活出来てるっぽい!
というわけでコマンド実行したカレントディレクトリに RECOVERED_FILES/ ってディレクトリが出来てその中に、なんとファイル名やディレクトリ構造までそのままに復元できました!
ファイルの内容についてはお気になさらずw数年前から何となく毎日寝る前に1話ずつ、昔話とか青空文庫とかを朗読してiPhoneで録音して貯めてたデータが今回の事故対象。絵も文章もかけないし歌とかも微妙なのであんまし見たことないコンテンツってことで朗読はじめてみたんだが。蓄積で多分数百時間は溜まってたから駄ファイルだとしても消えるとショックだったので復活できて良かった(^-^)
ext4のファイル復活に付いてぐぐってたら、extundeleteの日本語情報無いっぽかったので、またやりそうな自分の為にもメモメモ。
ふぅ、焦ったー(^^;
追記:ブコメで何件か、rm -rf / とかやっちゃった場合は?てあるけど、多分そういう場合は別OS(別PCやKnoppix起動)からextundeleteすれば良いと思うよ。
トラックバック - http://d.hatena.ne.jp/y-kawaz/20110123/1295779916
リンク元
- 1586 http://b.hatena.ne.jp/
- 676 http://b.hatena.ne.jp/hotentry
- 611 http://twitter.com/
- 464 http://www.ig.gmodules.com/gadgets/ifr?exp_rpc_js=1&exp_track_js=1&url=http://www.hatena.ne.jp/tools/gadget/bookmark/bookmark_gadget.xml&container=ig&view=default&lang=ja&country=JP&sanitize=0&v=42aed849ad8d0db8&parent=http://www.google.co.j
- 347 http://reader.livedoor.com/reader/
- 275 http://b.hatena.ne.jp/hotentry/it
- 209 http://longurl.org
- 204 http://blog.livedoor.jp/antenna22/archives/51579351.html
- 200 http://www.sleipnirstart.com/
- 175 http://www.google.com/reader/view/