按大小切割
#!/bin/bash
timeStamp=date '+%Y%m%d-%H%M%S'
foldorpath=/opt/logs/nginx
bakpath=/opt/logs/nginx_bak
for file in $( ls $foldorpath)
do
file_len=stat $foldorpath/$file |grep Size |awk '{print $2}'
if [ “$file_len” -ge “1073741824” ]; then
cd $foldorpath
mv $file
b
a
k
p
a
t
h
/
bakpath/
bakpath/file-$timeStamp
/opt/opt/nginx/sbin/nginx -s reopen
fi
done
按日期切割
#! /bin/sh
LOGPATH=/opt/logs/nginx
lastDate=date -d last-day '+%Y%m%d'
for i in ls $LOGPATH/*access.log
;do
mv $i
i
−
i-
i−lastDate
done
/opt/opt/openresty/nginx/sbin/nginx -s reopen
#删除
find /opt/logs/nginx/ -type f -name ‘access.log-’ -mtime +15 | xargs rm -f