nginx/tengine日志切割升级版

#!/bin/bash
#author harlan
#this script is for CentOS
#请修改对应日志目录:accesslogs_path, backlogs_path
#备份日志到backlogs, 保留7天日志文件,删除月备份空目录
#给shell执行权限,并添加到crontab,一天执行一次
  
accesslogs_path="/usr/local/nginx/logs"
backlogs_path="/var/backlogs"
Dateym=`date '+%y_%m'`
Dated=`date '+%d'`
Datem=`date -d '-1 month' +%y_%m`
Logdir=`ls -l $backlogs_path/$Datem |wc -l`
  
mkdir -p ${backlogs_path}/${Dateym}/${Dated}/
mv ${accesslogs_path}/*.log ${backlogs_path}/$Dateym/$Dated/
 
find ${backlogs_path} -name "*.log" -type f -mtime +7 -exec rm -rf {} \;
 
if [ $Logdir -eq 1 ]
then
   rm -rf $Logdir
else
   echo "don't empty dir" > /dev/null 2>&1
fi



你可能感兴趣的:(nginx,tengine)