请编写一个shell脚本:每天1:00备份/var/log目录下前一天的日志文件并存放到当前目录的btslog目录中,并删除15天前的log备份文件
cat bak_logs.sh
#!/bin/bash
#this is to backup logs
#updated by yehaifeng
#qq:769358362
#define var
YESTERDAY=date +%F -d '-1 day'
LOG_DIR=/var/log
BAK_DIR=/var/log/btslog
LOG_FILE=btsvr.log
cd $LOG_DIR/
if [ -f $LOG_DIR/$LOG_FILE.$YESTERDAY] ;then{
tar zcf $LOG_DIR/$LOG_FILE.$YESTERDAY.tar.gz$LOG_DIR/$LOG_FILE.$YESTERDAY
/bin/mv $LOG_DIR/$LOG_FILE.$YESTERDAY.tar.gz/BAK_DIR/
}
else
echo “the file is not exist.”
fi