日志文件定期压缩移动删除
压缩移动删除备份文件:
1.压缩日志文件 tar -zcvf catalina.2022-09-29.log
2 移动备份文件到home/baklogs
3.删除原有日志文件catalina.2022-09-29.log
#!/bin/bash #日志所在目录 logsurl="/home/taobao-logs"; #备份目录 baklogs="home/baklogs"; #日志文件 logs="catalina.`date -d yesterday +%F`.log"; cd $logsurl #压缩函数 tarf(){ tar -zcf $logs.tar.gz $logs >>scriptlogs.txt echo -e "\033[1;32m`date +%Y-%m-%d:%H:%M:%S`==>$logs completed tar \033[0m" >> scriptlogs.txt; } #移动函数 mvf(){ mv catalina.`date -d yesterday +%F`.log.tar.gz /home/baklogs; echo -e "\033[1;32m `date +%Y-%m-%d:%H:%M:%S`==>$logs.tar.gz completed mv $baklogs \033[0m" >>scriptlogs.txt } #函数函数 deletef(){ rm -rf $logs >>scriptlogs.txt; echo -e "\033[1;32m`date +%Y-%m-%d:%H:%M:%S`==>$logs completed rm \033[0m" >>scriptlogs.txt; } if [ -e $logs ] then tarf mvf deletef else echo -e "\033[1;31m`date +%Y-%m-%d:%H:%M:%S`==>Not find $logs\033[0m" >>scriptlogs.txt; fi