脚本切割,由于日志较大,需要进行压缩。
tar -P, --absolute-paths
不要从文件名中去除 '/'
#!/bin/bash
year=`date +%Y`
month=`date +%m`
day=`date +%d`
logs_path="/var/log/nginx/"
logs_access="access"
logs_error="error"
pid_path="/var/log/nginx/nginx.pid"
rq=`date +%Y%m%d`
mv ${logs_path}${logs_access}.log ${logs_path}${logs_access}_${rq}.log
mv ${logs_path}${logs_error}.log ${logs_path}${logs_error}_${rq}.log
tar -zcvPf ${logs_path}${logs_access}_${rq}.log.tar.gz ${logs_path}${logs_access}_${rq}.log --remove-files
tar -zcvPf ${logs_path}${logs_error}_${rq}.log.tar.gz ${logs_path}${logs_error}_${rq}.log --remove-files
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
cd ${LOGS_PATH}
find . -mtime +7 -name "*20[1-9][3-9]*" | xargs rm -f