Avoid accidental File Deletion: Linux recycle bin Mechanism

Source: Internet
Author: User


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.