避免誤刪檔案:Linux資源回收筒機制

來源:互聯網
上載者:User


避免誤刪檔案:Linux資源回收筒機制 昨日淩晨精神恍惚,誤刪了在虛擬機器中寫的程式檔案,Google度娘資料恢複方法失敗,使昨天的工作功虧一簣,幸好程式改動不多。現準備在所有伺服器用機制來解決誤刪問題。這樣總比花時間恢複付出的代價小得多把。1、編寫資源回收筒指令碼程式[root@SlaveA data]# cat /bin/rm.sh  #!/bin/sh # Author steven # Modify 20120709 dirpath=/data/Recycle # 選擇資源回收筒所在的分區目錄now=`date +%Y%m%d_%H_%M_%S_`  filename=${now}$1   # 給已經刪除的檔案加一個時間首碼來標識刪除時的精準時間if [ ! -d ${dirpath} ];then         /bin/mkdir -p ${dirpath} fi   www.2cto.com  /bin/mv $1 ${dirpath}/${filename} 
 2、其他步驟chmod 755 /bin/rm.shecho "alias rm='/bin/rm.sh'" >> /etc/bashrc 3、刪除檔案測試rm  /root/text.txt此時,text.txt檔案就會被mv 到 資源回收筒目錄 /data/Recycle4、刪除資源回收筒檔案/bin/rm -rf /data/Recycle/text.txt5、資源回收筒機制是為瞭解決不小心誤刪問題,如果確定某個檔案永久刪除則直接刪除/bin/rm -rf  filename
 6、為防止資源回收筒目錄遺留檔案過多而佔用太多的硬碟資源,使用crontab定時刪除曆史檔案a、編寫定時刪除資源回收筒檔案程式指令碼[root@SlaveA ~]# cat clean_recycle.sh  #!/bin/sh   www.2cto.com  # AUthor steven # Modify 20120709 dirpath=/data/Recycle/ /bin/find ${dirpath} -mtime +30  -exec /bin/rm -rf {} \;   # 30 天#注意:此處是 /bin/rm -rfb、添加計劃任務crontab -e1 5 * * 0 sh /root/clean_recycle.sh7、失誤是無法避免的,我們猜不到失誤會在何時,何地,何種情況下發生。既然有這種因素存在,能用機制解決就用機制解決把。  作者 jie737421

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.