Avoid accidental deletion of Files: the Linux recycle bin mechanism was so anxious yesterday morning that the Program Files written in the virtual machine were accidentally deleted. Google's data recovery method failed, making yesterday's work a loss of money. Fortunately, there were not many program changes. Now we are going to use mechanisms on all servers to solve the problem of accidental deletion. This is much less costly than taking the time to recover. 1. Write the recycle bin script [root @ SlaveA data] # cat/bin/rm. sh #! /Bin/sh # Author steven # Modify 20120709 dirpath =/data/Recycle # select the partition directory of the Recycle bin now = 'date + % Y % m % d _ % H _ % M _ % S _ 'filename =$ {now} $1 # Add a time prefix to the deleted object to identify the precise time when the object is deleted. if [! -D $ {dirpath}]; then/bin/mkdir-p $ {dirpath} fi www.2cto.com/bin/mv $1 $ {dirpath}/$ {filename}
2. Other steps: chmod 755/bin/rm. shecho "alias rm = '/bin/rm. sh '">/etc/bashrc 3. delete the file and test rm/root/text.txt.pdf. Then, the text.txt file will be mv to the recycle bin directory/data/Recycle4 and deleted from the recycle bin/rm- rf/data/Recycle/text.txt 5. the Recycle bin mechanism is used to solve the accidental deletion problem, if you confirm that a file is permanently deleted, delete/bin/rm-rf filename directly.
6. To prevent the recycle bin directory from occupying too many hard disk resources due to too many files, use crontab to regularly Delete historical files a and write the script for regularly deleting recycle bin files [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 days # Note: Here is/bin/rm-rfb. It is unavoidable to add a scheduled task crontab-e1 5 ** 0 sh/root/clean_recycle.sh7, we can't guess when, where, and under what circumstances a mistake will happen. Since such a factor exists, a mechanism can be used to solve the problem. Author: jie737421