新聞中心
Linux操作系統(tǒng)被眾多程序員和服務(wù)器管理員視為最強的開源系統(tǒng)。但是,任何系統(tǒng)都不是完美無缺的。在Linux系統(tǒng)上,誤刪數(shù)據(jù)是一個普遍存在的問題。雖然有很多方法可以防止誤刪,但是如果數(shù)據(jù)已經(jīng)被刪除,該怎么辦?

專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)沂南免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了近1000家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
在Linux系統(tǒng)中,ifind是一個非常有用的命令,可以幫助你找回誤刪除的文件。ifind的作用是搜索已刪除的文件,找到相關(guān)的inode,并將其恢復(fù)為可用狀態(tài)。
ifind命令原理
首先需要明確,當(dāng)在Linux系統(tǒng)中刪除一個文件時,只是將inode表中的相關(guān)信息標(biāo)記為“已刪除”,而實際數(shù)據(jù)仍然駐留在磁盤上。這就是ifind命令的原理所在。ifind命令將使用類似于grep的方式搜索已經(jīng)刪除的inode,并將其恢復(fù)為可用狀態(tài)。因此,如果在刪除文件后馬上執(zhí)行ifind命令,則可能會找到丟失的文件并恢復(fù)它。
ifind的使用
在Linux系統(tǒng)中,ifind命令的使用非常簡單。在開始之前,請確定您有sudo權(quán)限。
要使用ifind命令來尋找誤刪除的文件,請按照以下步驟操作:
1. 在終端中輸入命令:sudo ifind。這將顯示可以恢復(fù)的 inode 的整個列表。
2. 找到您要恢復(fù)的文件的 inode,并將其寫入文件。
3. 使用istat查找inode的詳細(xì)信息。
4. 如果您已經(jīng)找到了需要的文件,請使用命令sudo icat 。這將輸出文本到屏幕上。將其保存到文件中,然后將文件的擴展名更改為正確的擴展名。
需要注意的是,如果您發(fā)現(xiàn)使用ifind命令后找不到您要找的文件,則可能是由于它已經(jīng)完全被覆蓋或者過早地被刪除。在這種情況下,恢復(fù)文件變得非常困難。
如何避免誤刪數(shù)據(jù)?
雖然ifind是恢復(fù)誤刪數(shù)據(jù)的極好方法,但是仍然建議您采取措施避免數(shù)據(jù)丟失。以下是一些常用的方法:
1. 創(chuàng)建備份:在Linux系統(tǒng)上,備份數(shù)據(jù)是非常重要的。將所有關(guān)鍵數(shù)據(jù)備份到本地或遠程服務(wù)器中以確保可以恢復(fù)所有丟失的數(shù)據(jù)。
2. 慎用rm:在刪除文件之前,更好仔細(xì)檢查文件名和文件路徑,以確保不會刪除不必要的文件。建議使用rm -i命令,該命令會在刪除之前提示確認(rèn)。
3. 限制訪問權(quán)限:通過設(shè)置適當(dāng)?shù)奈募湍夸洐?quán)限來限制文件的訪問。這可以幫助防止不必要的文件訪問和誤刪除數(shù)據(jù)。
相關(guān)問題拓展閱讀:
- 如何解決SELinux問題
- 如何解決 artdot indi.mail system
如何解決SELinux問題
首先需要確認(rèn)SELinux處于激活狀態(tài),可以使用getenforce命令:
兄凳 shell> getenforce
Enforcing
或者使用sestatus命令:
shell> sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file:enforcing
Policy version: 24
Policy from config file:targeted
注:關(guān)于SELinux的基礎(chǔ)知識介紹請參考鳥哥的Linux私房菜中相關(guān)的介紹。
我們還需要確認(rèn)系統(tǒng)已經(jīng)安裝并啟動了Apache,沒有的話就YUM裝一個,這很簡單,就不多說了,接著在root目錄創(chuàng)建一個測試文件test.html,如下:
shell> cat /root/test.html
hello, world.
然后把這個測試文件拷貝到Apache的DocumentRoot目錄,我的Apache是通過YUM安裝的話,缺省是/var/www/html目錄,如下:
shell> cp /root/test.html /var/www/html
接著瀏覽一下,如果沒出什么幺蛾子,應(yīng)該一切都在意料之中,如下:
shell> curl
hello, world.
看到這,你可能覺得我廢話連篇,別著急,下面就是見證奇跡的時候了:
同樣還是那個測試文件test.html,不過這次不再是拷貝,而是移動,如下:
shell> mv /root/test.html /var/www/html
接著瀏覽一下,怎么樣,結(jié)果很出人意料吧,竟然提示權(quán)限錯誤,如下:
shell> curl
403 Forbidden
Forbidden
You don’t have permission to access /test.html
on this server.
當(dāng)然,我們現(xiàn)在知道這個問題是由于SELinux引起的,但還不知其所以然,實際上問題的原因此時已經(jīng)被螞鄭audit進程記錄到了相應(yīng)的日志里,可以這羨物旅樣查看:
shell> audit2why yum install setroubleshoot
它本身是一個GUI套件,不過其中包含的一個sealert命令對我們命令行用戶很有用:
shell> sealert -a /var/log/audit/audit.log
Summary:
SELinux is preventing /usr/in/httpd “getattr” access to
/var/www/html/test.html.
Detailed Description:
SELinux denied access requested by httpd. /var/www/html/test.html may be a
mislabeled. /var/www/html/test.html default SELinux type is httpd_sys_content_t,
but its current type is admin_home_t. Changing this file back to the default
type, may fix your problem.
File contexts can be assigned to a file in the following ways.
* Files created in a directory receive the file context of the parent
directory by default.
* The SELinux policy might override the default label inherited from the
parent directory by specifying a process running in context A which creates
a file in a directory labeled B will instead create the file with label C.
An example of this would be the dhcp client running with the dhclient_t type
and creating a file in the directory /etc. This file would normally receive
the etc_t type due to parental inheritance but instead the file is labeled
with the net_conf_t type because the SELinux policy specifies this.
* Users can change the file context on a file using tools such as chcon, or
restorecon.
This file could have been mislabeled either by user error, or if an normally
confined application was run under the wrong domain.
However, this might also indicate a bug in SELinux because the file should not
have been labeled with this type.
If you believe this is a bug, please file a bug report against this package.
Allowing Access:
You can restore the default system context to this file by executing the
restorecon command. restorecon ‘/var/www/html/test.html’, if this file is a
directory, you can recursively restore using restorecon -R
‘/var/www/html/test.html’.
Fix Command:
/in/restorecon ‘/var/www/html/test.html’
這次應(yīng)該看懂了吧!原因是說Apache下文件上下文類型應(yīng)該是httpd_sys_content_t,但是現(xiàn)在是admin_home_t,所以權(quán)限錯誤,并且在結(jié)尾處給出了修復(fù)命令。
可httpd_sys_content_t,admin_home_t都怎么看?。亢芎唵?,借助ls命令的-Z參數(shù)即可:
shell> ls -Z /path
回到問題的開始,拷貝之所以沒出現(xiàn)問題,是因為cp自動修改上下文屬性,而移動之所以出現(xiàn)問題是因為mv保留原文件的上下文屬性。
注:關(guān)于SELinux和Apache的詳細(xì)介紹,可以參考『man httpd_selinux』。
知道了如何解決SELinux問題,以后如果遇到類似的情況不要急著武斷的關(guān)閉SELinux。
有碰到即使是permissive也不行的,最后是改成disabled后重啟機器才可以。
上面有個小錯,應(yīng)該是echo “0” > /selinux/enforce (少了>)selinux如果有開很容易雀塵造成ifind問題,參看下面系統(tǒng)日志Aug 2 20:52:06 cc-lnx-imglib setroubleshoot: SELinux is preventing /opt/simpana/iDataAgent/ifind “execstack”梁歲枯 access to . For complete SELinux messages. run sealert -l 4a0b3993-b18f-4c72-9e1d-4f5d8175ad41Jul 31 00:30:09 cc-lnx-imglib setroubleshoot: SELinux is preventing /橡洞bin/hostname access to a leaked /tmp/.gxsetup/cvpkglo g.pipe.26262 file descriptor. For complete SELinux messages. run sealert -l e675a6a6-efc9-461f-bc0fd2d308
別一種查看SElinux方法:# sestatusSELinux status: disabled
如何解決 artdot indi.mail system
上面陪神有個小錯,應(yīng)該是echo “0” > /selinux/enforce (少了>)selinux如果有開很容易造成ifind問題,參看下面系統(tǒng)日志兆亂鄭Aug 2 20:52:06 cc-lnx-imglib setroubleshoot: SELinux is preventing /opt/simpana/iDataAgent/族頌ifind “execstack” access to . For complete SELinux messages. run sealert -l 4a0b3993-b18f-4c72-9e1d-4f5d8175ad41Jul 31 00:30:09 cc-lnx-imglib setroubleshoot: SELinux is preventing /bin/hostname access to a leaked /tmp/.gxsetup/cvpkglo g.pipe.26262 file descriptor. For complete SELinux messages. run sealert -l e675a6a6-efc9-461f-bc0fd2d308
設(shè)置-兼容性視圖設(shè)置-添加此網(wǎng)站(將需打開的郵箱網(wǎng)址增加進去)ok
關(guān)于linux ifind的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
成都網(wǎng)站推廣找創(chuàng)新互聯(lián),老牌網(wǎng)站營銷公司
成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)(www.cdcxhl.com)專注高端網(wǎng)站建設(shè),網(wǎng)頁設(shè)計制作,網(wǎng)站維護,網(wǎng)絡(luò)營銷,SEO優(yōu)化推廣,快速提升企業(yè)網(wǎng)站排名等一站式服務(wù)。IDC基礎(chǔ)服務(wù):云服務(wù)器、虛擬主機、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗、服務(wù)器租用、服務(wù)器托管提供四川、成都、綿陽、雅安、重慶、貴州、昆明、鄭州、湖北十堰機房互聯(lián)網(wǎng)數(shù)據(jù)中心業(yè)務(wù)。
當(dāng)前題目:Linux ifind命令:找回誤刪文件! (linux ifind)
網(wǎng)站URL:http://fisionsoft.com.cn/article/djeggid.html


咨詢
建站咨詢
