个人工作笔记:
日志备份:
#!/bin/bash
set -e
#此脚本放在日志所在目录
#年/月(两位)/日(两位)/主机名/servicename/filename
#绝对路径:/data/log1/2010/08/05/$HOSTNAME/$SERVICENAME/$FILENAME
#现在服务nginx,tomcat,squid,lighttpd
#for nginx;
#
#假定目录:/data/logs/nginx
YESTERDAY=`date -d '1 day ago' +%Y%m%d`
YEAR=`date -d '1 day ago' +%Y`;
MONTH=`date -d '1 day ago' +%m`;
DAY=`date -d '1 day ago' +%d`;
HOSTNAME=`echo $HOSTNAME`
SERVICENAME=`pwd |awk -F/ '{print $4}'`
cd /data/logs/nginx
for LOG in `ls |grep .log$`
do
[[ -f "$LOG" ]] && mv $LOG $LOG.$YESTERDAY ;
done
/bin/kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
for FILELOG in `ls |grep $YESTERDAY`
do
[[ -f "$FILELOG" ]] && gzip -9 $FILELOG;
done
/bin/mkdir -p ./$YEAR/$MONTH/$DAY/$HOSTNAME/$SERVICENAME
/bin/mv *.gz ./$YEAR/$MONTH/$DAY/$HOSTNAME/$SERVICENAME
/usr/bin/rsync -aR $YEAR/ backup@192.168.200.11::log1 --password-file=/etc/rsync.pass
/bin/rm -rf ./$YEAR;
#下面一行放在crontab中,计划执行任务
#1 0 * * * root /data/logs/nginx/nglogrotate.sh
阅读(818) | 评论(0) | 转发(0) |