Shell script automatically deletes backup files above a specified size _linux shell

Source: Internet
Author: User

The recent local virtual machine space is always backed up to fill, in order to lazy don't want to log up every day to clear, just write this automatic cleanup script.

System: CentOS 5.x

Script content:

Cat make_room.sh

Copy Code code as follows:

#!/bin/bash
#size = ' Df-hp|grep/dev/mapper/volgroup00-logvol00|awk ' {print $} ' |cut-f 1-d ' G '
Size= ' Df-mp|grep/dev/mapper/volgroup00-logvol00|awk ' {print $} '
File= "/root/sqlbak"
if ["${size}"-le "1000"];then
Rm-f ${file}/*
Else
echo "$size"
Fi

Why not DF-HP, because if the time to judge always error, let me give up the number of decimal point of judgment, directly with a trillion to judge this more accurate. Of course, you can also add other ways to clean up the space, such as deleting the hard disk is larger than the 50-100m file, or delete the first 5-10 large files, these judgments rely on your own to write, these judgments are best not to affect the stability of the server system.

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.