每天备份tomcat日志

#!/bin/bash
Backup_Home=/data/backup-log
mkdir -p $Backup_Home
Log_Home=/data/Tomcat/logs
App_Log_Home=/data/app/tomcat/log
Date=`date -d 'yesterday' '+%Y-%m-%d'`
#将昨天tomcat日志mv到备份目录
/usr/bin/mv $Log_Home/catalina.$Date.log $Backup_Home
/usr/bin/mv $Log_Home/localhost.$Date.log $Backup_Home
cd $Backup_Home
tar -zcf catalina_"$Date"_log.tar.gz catalina.$Date.log
tar -zcf localhost_"$Date"_log.tar.gz localhost.$Date.log
if [ $? -ne 0 ]; then
        echo "$Date:备份失败并退出" >> backup_err.log
        exit
else
        echo "$Date:***打包成功正在删除源日志文件***" >> backup_access.log
	/usr/bin/rm -rf catalina.$Date.log
	/usr/bin/rm -rf localhost.$Date.log
	
fi
#==========================================================================
echo "app日志开始备份"
/usr/bin/mv $App_Log_Home/springboot.out $Backup_Home/springboot_"`date +%F`".out
cd $Backup_Home
tar -zcf springboot_"`date +%F`".tar.gz springboot_"`date +%F`".out
if [ $? -ne 0 ]; then
	echo "`date +%F`:app日志备份失败并退出" >> backup_err.log
	exit
else
	echo "`date +%F`:app日志打包成功,正在删除源文件"	>> backup_access.log
	/usr/bin/rm -rf springboot_"`date +%F`".out
fi
#清理日志目录
find Backup_Home/* -mtime +30 -exec rm {} \;

  

转载于:https://www.cnblogs.com/python-cat/p/9896614.html

你可能感兴趣的:(每天备份tomcat日志)