LoginSignup
122
117

More than 5 years have passed since last update.

Linuxにて削除(rm)してしまったファイルを復元する【CentOS】

Last updated at Posted at 2015-01-21

まぁたまにありますよね。
AWSのEC2にてCentOSなサーバーで実行しました。

extundeleteをインストールする

# cd /tmp
# mkdir extundelete
# curl -L http://sourceforge.net/projects/extundelete/files/extundelete/0.2.4/extundelete-0.2.4.tar.bz2/download | tar xj
# cd extundelete-0.2.4
# ./configure --prefix=/tmp/a && make && make install

インストール時のエラーあれこれ

1

Configuring extundelete 0.2.4
configure: error: in `/tmp/extundelete/extundelete-0.2.4':
configure: error: C++ compiler cannot create executables
See `config.log' for more details

→gcc-c++をインストールする

# yum install gcc-c++

2

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

→e2fsprogs-develをインストールする

# yum -y install e2fsprogs-devel

それぞれを実行してから

./configure --prefix=/tmp/a && make && make install

をしたらインストールできました

ファイルを復元する

まずは自分のファイルシステムを確認

$ df -hT
ファイルシス   タイプ   サイズ  使用  残り 使用% マウント位置
/dev/xvda1     ext4       9.8G  4.1G  5.6G   43% /
devtmpfs       devtmpfs   491M   56K  491M    1% /dev
tmpfs          tmpfs      499M     0  499M    0% /dev/shm

(AWSのEC2でCentOSだとみんな/dev/xvda1だった気がする)

下のコマンドで1時間前までに削除してしまったファイルを全て復元する

# /tmp/a/bin/extundelete --restore-all --after $(date +%s -d '1 hour ago') /dev/xvda1

(ちゃんと調べてないからわからないけど2時間前だったら'2 hour ago'にすればいいんじゃないかな)

そうすると実行した階層にRECOVERED_FILESというディレクトリができているので、その中に削除してしまったファイルが復元されてます。

今度は間違えないようにcpやらmvやらしてあげてくださいねー!

122
117
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
122
117