简述linux下log的管理(mvlog脚本)
时间:2007-11-21 来源:Nevins-su
#!/bin/bash
#
DATEM=`date +%Y%m%d`
DAY=`date +%d`
YEAR_MONTH=20"`date +%y%m`"
YEAR_MONTHY=20"`date +%y%m`"
DAYY=`expr $DAY - 1` 前一天的
DAY=`expr $DAY - 8` 前8天的
if [ $DAY -le 0 ];
then
MONTH=`date +%m`
MONTH=`expr $MONTH - 1`
case "$MONTH" in
'1'|'3'|'5'|'7'|'8'|'10'|'12')
DAY=`expr 31 + $DAY`
;;
'4'|'6'|'9'|'11')
# DAY=`30 + $DAY
DAY=`expr 30 + $DAY`
;;
'2')
DAY=`expr 28 + $DAY`
;;
esac
if [ $MONTH -lt 10 ];
then
MONTH=0$MONTH
fi
YEARM=`date +%Y`
YEAR_MONTH=$YEARM$MONTH
fi
if [ $DAYY -le 0 ];
then
MONTHY=`date +%m`
MONTHY=`expr $MONTHY - 1`
case "$MONTHY" in
'1'|'3'|'5'|'7'|'8'|'10'|'12')
DAYY=`expr 31 + $DAY`
;;
'4'|'6'|'9'|'11')
DAYY=`expr 30 + $DAY`
;;
'2')
DAYY=`expr 28 + $DAY`
;;
esac
if [ $MONTHY -lt 10 ];
then
MONTHY=0$MONTHY
fi
YEARMY=`date +%Y`
YEAR_MONTHY=$YEARMY$MONTHY
fi
if [ $DAY -lt 10 ];
then
DAY=0$DAY
fi
if [ $DAYY -lt 10 ];
then
DAYY=0$DAYY
fi
DATE=$YEARMY-$MONTHY-$DAY 日期格式0000-00-00
DATEY=$YEAR_MONTHY$DAYY 日期格式 20070108
cd /data1/AppLogs/bossv1Apps/BOSSResend 目标路径
gzip RESEND$DATEY.log 压缩resend.log的日志文件 datey为日期格式(前一天的log)
mv RESEND$DATEY.log.gz /data1/log/bosslog/BOSSRESEND移动压缩后的文件到/data1-下
cd /data1/StatLogs/BackupFile/SourceFile
#gzip access_log$DATEY.*
#gzip wapsvr_acclog$DATEY.*.log
mv access_log$DATEY.zip /data1/log/bosslog/BackupFile/SourceFile移动前一天的日志
mv wapsvr_acclog$DATEY.zip /data1/log/bosslog/BackupFile/SourceFile 移动该压缩文件
cd /data1/StatLogs/BackupFile/LoadFile
#gzip $DATE*.zip
mv $DATE*.zip /data1/log/bosslog/BackupFile/LoadFile
cd /data1/boss-baklog/bossresend
find . -name "RESEND*log.gz" -mtime +7 -exec rm -f {} \; 找到7天之内的备份文件否则删除
cd /data1/boss-baklog/SourceFile
find . -name "access_log*zip" -mtime +7 -exec rm -f {} \;
find . -name "wapsvr_acclog*zip" -mtime +7 -exec rm -f {} \;
cd /data1/boss-baklog/LoadFile
find . -name "*zip" -mtime +7 -exec rm -f {} \;