- 论坛徽章:
- 0
|
我觉得这个最好是今天的零点来tar昨天的日志,同时移走七天前的压缩包,我写了个脚本,请参考:
# step 1, generate application statistics at the morning for yesterday
get_one_day_before_specified_date()
{
#get the command line input(date month & year)
day=$1
month=$2
year=$3
# if it is the first day of the month
if [ $day -eq 01 ]
then
# if it is the first month of the year
if [ $month -eq 01 ]
then
# make the month as 12
month=12
# deduct the year by one
year=`expr $year - 1`
else
# deduct the month by one
month=`expr $month - 1`
fi
day=`cal $month $year | awk 'NF != 0{ last = $0 }; END{ print last }' | awk '{ print $NF }'`
else
# deduct the day by one
day=`expr $day - 1`
fi
echo $year$month$day
}
YEAR_T=`date +%Y`;
MONTH_T=`date +%m`;
DAY_T=`date +%d`;
YESTERDAY=`get_one_day_before_specified_date $DAY_T $MONTH_T $YEAR_T`;
DATE=$YESTERDAY
LOGDIR1=/log1/
LOGDIR2=/log2/
#first backup all log
/usr/bin/tar cvf ${LOGDIR1}${DATE}.tar ${LOGDIR1}${DATE}*.log > /dev/null
/usr/bin/gzip ${LOGDIR1}${DATE}.tar
#second move the package which before the time
cd $LOGDIR1
rm -f ${DATE}*.log
for i in `find . -mtime +7 -name '*.tar.gz'`
do
cp $i $LOGDIR2
rm -f $i
done
在cron里每天零晨10分执行.
[ 本帖最后由 我老婆黑社会 于 2007-6-12 12:11 编辑 ] |
|