日志/数据自动压缩备份删除小脚本


#!/bin/bash

#backup tomcatlog

#author zlx

#date 20151130

echo "这是一个日志和网站垃圾定时备份删除的小脚本"

TOMCAT_LOG=/var/log/tomcat2

BAK_LOG=/BakFile/tomcat/log7


if test -d $BAK_LOG

then

        echo "备份目录已准备好,即将开始备份"

else

       mkdir -p $BAK_LOG

fi

BakTime=`date -d"1 day ago" +"%F"`


tar -cPjvf $BAK_LOG/catalina$BakTime.tar.gz $TOMCAT_LOG/catalina.$BakTime* >> /dev/null

tar -cPjvf $BAK_LOG/dai$BakTime.tar.gz $TOMCAT_LOG/dai_$BakTime* >> /dev/null

tar -cPjvf $BAK_LOG/host-manager$BakTime.tar.gz $TOMCAT_LOG/host-manager.$BakTime* >> /dev/null

tar -cPjvf $BAK_LOG/localhost$BakTime.tar.gz $TOMCAT_LOG/localhost.$BakTime* >> /dev/null

tar -cPjvf $BAK_LOG/manager$BakTime.tar.gz $TOMCAT_LOG/manager.$BakTime* >> /dev/null

tar -cPjvf $BAK_LOG/www.gmdai.com_access_log$BakTime.tar.gz $TOMCAT_LOG/www.gmdai.com_access_log.$BakTime* >> /dev/null


echo "备份已经完成"

echo "正在删除7天前已经备份的日志文件,请稍后"

DelTime=`date -d"7 day ago" +"%F"`

find $TOMCAT_LOG -name *$DelTime* | xargs rm -rf >> /dev/null

echo "正在删除网站垃圾文件"

rm -rf /usr/htdoc/www/data/export/* >> /dev/null

echo "已经完成所有工作"


你可能感兴趣的:(shell,自动备份,日志数据)