#!/bin/bash ############################################## #Author: Liuzhengwei - [email protected] #QQ:1135960569 #Last modified: 2017-08-16 16:05 #Filename: nginx_logrotate.sh #Description: ############################################## back_dir=/usr/local/nginx/logs/ year=`date ‘+%Y‘` month=`date ‘+%m‘` [ -d $back_dir/$year ] && mkdir $back_dir/$year/$month || mkdir -p $back_dir/$year/$month cp $back_dir/access.log $back_dir/$year/$month cp $back_dir/error.log $back_dir/$year/$month cd $back_dir/$year/$month gzip -c access.log > access.log_`(date ‘+%F‘)`.gz gzip -c error.log > error.log_`(date ‘+%F‘)`.gz find ./ -name "*.log" | xargs rm -f >$back_dir/access.log >$back_dir/error.log
时间: 2024-10-15 13:21:08