#!/bin/sh
DIR=/data/ascenlink/logs
#T=`find $DRI/* -type f -mtime +365`
#rm -rf $T
I=$(df -h |grep -v data2 |awk '/data/ {gsub ("'%'","");print $4}')
if [ $I -gt 95 ];then
mv $DIR/*.tar.gz /data2/backuplog
echo "No enough Free Disk Space for backup" >> /home/ascenlink/backuperror.log
fi
while true
CPU=$(vmstat 1 1 |awk '{print $13 }' |sed -n 3p)
MEM=$(free -m |awk '/Mem/ { print $3}')
do
if [[ $CPU -gt 90 ]] || [[ $MEM -gt 8000 ]];then
sleep 5m
else
break
fi
done
#DATE=`date +%Y-%m-%d%H%M`
cd /data/ascenlink/logs/
#LOG=`find ./ -type f -mtime -31 -print |xargs`
#wait
#tar -zcvf /data/ascenlink/logs/ascenlink.$DATE.tar.gz $LOG >/dev/null 2>&1
A=`date -d "-1 months" |awk '{print $2}' |sed -n 1p`
DATE=`date -d "-1 months" +%Y-%m-%d%H%M`
tar -zcvf /home/ascenlink/ascenlink.$DATE.tar.gz $(ls -l |grep $A |awk '{ print $9 }') >/dev/null 2>&1
二,定期执行任务时间
执行时间为每月一号,1点1分对上一个月的日志文件进行打包
cat /etc/crontab
1 1 1 */1 * ascenlink /bin/sh /home/ascenlink/logbackup.sh >/dev/null 2 >&1