講師專欄

“giis” Get it is iSay –「很簡單就救回來的說」
Ext2/3檔案系統救援工具
?在LINUX操作的過程中,不小心殺掉不該殺的檔案該怎麼辦?幾乎每個使用者都有類似的問題發生過,隨著LINU核心及檔案系統的進步,很多過去使用的救援方式都已經不能援用,本文介紹的工具僅能恢復該軟體安裝之後才被刪除的檔案,但比起其他救援的方法來說,較容易為一般使用者所接受,而相對的,一般對於回復檔案的限制使用者也必須要遵守,假如檔案刪除後還有其他程序寫入的動作而造成資料區塊被覆蓋,檔案當然也就救不回來了。

Giis網址是http://sourceforge.net/projects/giis 作者是德國人,所以他寫的英文語氣就有點德國腔,原名叫「giis-gET iT i sAY」所以筆者就粗翻為「很簡單就救回來的說」,希望可以望文生義,不要以訛傳訛的說。


點選網頁下方的DOWNLOAD連結,進入下載頁面,我們要下載的是二進位執行格式。


下載之後將檔案儲存到管理員家目錄,進行安裝過程:

1.在家目錄中可以看到一個叫作giis-bin.zip的檔案,用unzip指令可將其解壓縮。

[root@localhost ~]# ls
anaconda-ks.cfg? giis-bin.zip? install.log.syslog? Mail
Desktop????????? install.log?? ks.cfg
[root@localhost ~]# unzip giis-bin.zip
Archive:? giis-bin.zip
inflating: giis-bin/copying ???????
inflating: giis-bin/giis??????????
inflating: giis-bin/hai???????????
inflating: giis-bin/quotes????????
inflating: giis-bin/raq???????????

? inflating: giis-bin/readme ??

2.進入giis-bin目錄,將giis檔案之權限改為777,並將其移動到/usr/bin目錄。

[root@localhost ~]# cd giis-bin
[root@localhost giis-bin]# ls
copying? giis? hai? quotes? raq? readme
[root@localhost giis-bin]# chmod 777 giis
[root@localhost giis-bin]# ls
copying? giis? hai? quotes? raq? readme
[root@localhost giis-bin]# mv giis /usr/bin

3.giis每隔一小時會更新一次檔案記錄資料庫,為了讓軟體自行進行更新工作,我們要在工作排程中加上更新的指令,相對的,如果你希望檔案資料的更新能夠更頻繁些,你可以在排程的時間上自行修改成你喜歡的時間間隔。

[root@localhost giis-bin]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab


下圖就是在vi畫面中輸入排程的範例,意思是每小時的20分執行giis –u 指令。

4.安裝giis ,安裝指令就是giis –i

[root@localhost giis-bin]# giis -i

Searching for file system....found.
Detected file system /dev/sda1

Searching for Superblock....found.
Super block is at 1024.

Gathering informations....... recorded...proceed...
Group Descriptor found.

?Creating files....
/giis created...
/giis/sys created...
/giis/got_it created...
/giis/sys/dir created...
/giis/sys/file created...
/giis/sys/sind created...
/giis/sys/dind created...
/giis/sys/sample created...
/giis/unrecovered created...

All files are Initialized...
Files at? Directory Level 1 are updated......
Files at? Directory Level 2 are updated......
Files at? Directory Level 3 are updated......
Files at? Directory Level 4 are updated......
Files at? Directory Level 5 are updated......
Files at? Directory Level 6 are updated......
Files at? Directory Level 7 are updated......
Files at? Directory Level 8 are updated......
Files at? Directory Level 9 are updated......
Files at? Directory Level 10 are updated......
Files at? Directory Level 11 are updated......

??????????????? giis - Installtion completed...

5. 安裝完成之後,複製hai,quotes兩個檔案至/giis目錄,安裝過程就已經結束,我們可以看一下安裝完成的目錄,其中got_it目錄就是稍後我們取回復原檔案的地方,若有一些檔案無法被復原,就會在unrecovered目錄中出現。

[root@localhost giis-bin]# cp hai quotes /giis
[root@localhost giis-bin]# cd /giis
[root@localhost giis]# ll
drwxr-xr-x 2 root root 4096? 8??15 19:05 got_it
-rw-r--r-- 1 root root? 786? 8??15 19:06 hai
-rw-r--r-- 1 root root 2636? 8??15 19:06 quotes
drwxr-xr-x 2 root root 4096? 8??15 19:05 sys

drwxr-xr-x 2 root root 4096? 8??15 19:05 unrecovered

giis 基本操作
此工具操作簡易,但要在此再提醒您,giis檔案恢復的範圍僅限於使用者及管理員家目錄中的檔案,也就是/home 及/root之下的子目錄,giis只是檔案救援工具,不是檔案備份工具,作者不去復原其他的目錄及檔案系統,其原因也是在此,而且,只有管理員才能執行這個工作。

1.啟動giis表單

只要以管理員身份執行giis指令,即可進入選單,按0可以安裝giis到系統中,這個我們已經執行過了,按1可以手動要求giis更新檔案資料庫,按2則是進行還原工作,按5則進行移除安裝的工作。

在此我們選2之後,程式就接著問說,你希望復原什麼樣的檔案?按0我們可以復原所有的使用者(包括root)所刪除的檔案,按1則復原特定使用者所刪除的檔案,程式稍後會要求你輸入使用者名稱,按2則要求giis盡量將可以復原的檔案資訊列出,但不一定會成功復原,按3則會要求你輸入檔案格式,依副檔名如*.jpg/*.gif進行復原。

在此例中我們選0,恢復的檔案會在/giis/got_it目錄中出現,管理員在恢復其權限之後,移動到該檔該去的目錄中即可。

[root@localhost got_it]# giis
===================================================
gET iT i sAY. giis - Ext3/Ext2 File Undelete Tool
===================================================

??????? Press 0 : Install
Press 1 : Update Now
Press 2 : File Recovery
Press 3 : Your File System Details
Press 4 : giis File Details
Press 5 : Uninstall
Press 6 : About giis
Press 7 : Quotes
Press 8 : Exit

Enter Your choice : 2

???????????????

Searching for file system....found.
Detected file system /dev/sda1

Searching for Superblock....found.
Super block is at 1024.

Gathering informations....... recorded...proceed...
Group Descriptor found.

All files are Initialized...

How do you want to recover files?


Press 0 : Get All User files
Press 1 : Get Specific User files
Press 2 : force giis - giis dump
Press 3 : Get By File Format

? Enter Your Choice : 0

??????????????
........ giis analyser : Begins ........
Unable to Detect File Type - Found Data :

??????? ........Ends ........

?giis process Completed...
Recovered files?? : /giis/got_it
Unrecovered files : /giis/unrecovered
[root@localhost got_it]#

1.指令模式操作

為了讓高階使用者更便於操作giis,作者更歡迎你進行指令模式的操作。

[root@localhost got_it]# giis -h

Usage: giis [OPTION]

Possible options available with giis :
-a???????????? Info. about the author.
-d???????????? Displays your file system informations.
-f???????????? Displays giis system files.
-g?? ??????????Recovers the Given or all deleted files.
-h???????????? Prints this menu.
-i???????????? Will perform installation of giis.
-m???????????? Menu based user interaction.
-q???????????? Exit giis
-t???????????? Some quotes and thoughts.
-u???????????? Updates giis to reflect current status.
-U???????????? Uninstalls giis.

Report bugs to <lakshmipathi.g@gmail.com>

我們下面就用兩個主要參數進行恢復檔案的範例,-u 可以更新檔案資料庫,而 -g 可以實際進行復原。

在此我們先把data1目錄移動至管理員家目錄中,接著進入data1目錄,看到裡面有三個檔案,httpd-2.2.3-6.el5.i386.rpm? httpd-manual-2.2.3-6.el5.i386.rpm? test.cfg

[root@localhost /]# mv data1 ~
[root@localhost /]# cd
[root@localhost ~]# ls
anaconda-ks.cfg? Desktop?? giis-bin.zip? giis.tar???? install.log.syslog? Mail
data1??????????? giis-bin? giis-doc????? install.log? ks.cfg
[root@localhost ~]# cd data1
[root@localhost data1]# ls

httpd-2.2.3-6.el5.i386.rpm? httpd-manual-2.2.3-6.el5.i386.rpm? test.cfg

因為檔案是新來的,所以giis資料庫中沒有它們的記錄,我們又等不及那每個小時一次的更新到來,所以我們就用手動的方式更新資料庫:

[root@localhost got_it]# giis -u

Searching for file system....found.
Detected file system /dev/sda1

Searching for Superblock....found.
Super block is at 1024.

Gathering informations....... recorded...proceed...
Group Descriptor found.

All files are Initialized...

???????????? ???? giis updated...

接著,我們刪除其中一個檔案:

[root@localhost data1]# rm test.cfg

rm:是否移除普通檔案‘test.cfg’? y

然後,實際進行復原,請注意復原成功的檔案會放在/giis/got_it目錄中:

[root@localhost got_it]# giis -g

Searching for file system....found.
Detected file system /dev/sda1

Searching for Superblock....found.
Super block is at 1024.

Gathering informations....... recorded...proceed...
Group Descriptor found.

All files are Initialized...

How do you want to recover files?
Press 0 : Get All User files
Press 1 : Get Specific User files
Press 2 : force giis - giis dump
Press 3 : Get By File Format

??????????????? Enter Your Choice : 0

??????? ........ giis analyser : Begins ........
Unable to Detect File Type - Found Data :
#platform=x86, AMD64? Intel
........Ends ........

?giis process Completed...
Recovered files?? : /giis/got_it

???????? Unrecovered files : /giis/unrecovered

我們來看看檔案是否有被救回來:

[root@localhost got_it]# ll
總計 2072
---------- 1 root root?? 20480? 8月 15 21:50 giis.tar
---------- 1 root root??? 1367? 8月 15 22:01 k2.cfg
-rw-r--r-- 1 root root??? 1367? 8月 15 21:55 ks.cfg
---------- 1 root root???? 675? 8月 15 22:07 README
---------- 1 root root??? 1367? 8 15 22:14 test.cfg
---------- 1 root root????? 10? 8月 15 22:04 ttt
---------x 1 root root 2076303? 8月 15 22:07 vmlinuz


你可以看到救援成功的檔案之權限都是000,所以管理員要注意其原始權限為何,依其原始路徑將檔案複製回去即可。