#!/bin/bash
BIN_LOG_DIR="/data/mysql/data"
DATE=`date "+%Y%m%d"`
BAK_DIR="/data/dbbk/local"
BAK_PATH=$BAK_DIR/bin-log-bk/$DATE
REMOTE_IP=192.168.1.100
REMOTE_PATH=/dbbackup/wj_30/log/
REMOTE_PATH_1=/dbbackup/wj_30/err/
ERR_LOG_DIR=/data/mysql/data
BAK_PATH_1=$BAK_DIR/err
OUTDATE_FILE=`date -d '8 days ago' +%Y%m%d`
####
if [ ! -d $BAK_PATH ] ; then
  mkdir -p $BAK_PATH
fi
find $BIN_LOG_DIR -name "mysql-bin.*" -mmin -60 -exec cp -a '{}' $BAK_PATH ';';
#add by coco in 2012/09/27
if [ ! -d $BAK_PATH_1 ] ; then
  mkdir -p $BAK_PATH_1
fi
find $ERR_LOG_DIR -name "*error.log" -mmin -60 -type f | xargs grep "ERROR" >  $BAK_PATH_1/$DATE.err;
s=`du -b $BAK_PATH_1/$DATE.err|awk '{print $1}'`
if [ $s -gt 0 ] ; then
#if [ $BAK_PATH_1/$DATE.err -ne 0 ] ; then
echo ftp
#scp -r -p $BAK_PATH_1/$DATE.err root@$REMOTE_IP:$REMOTE_PATH_1
else
        rm -f $BAK_PATH_1/$DATE.err
fi
find $BAK_DIR/bin-log-bk -name "*" -mtime +10 |xargs rm -rf   删除本地10天前的日志文件
find $BAK_DIR -type d -empty |xargs rm -rf
####
ftp -n<<!       ##上传
open $REMOTE_IP
user crmtest 1qaz2wsx,,
cd $REMOTE_PATH
mkdir $DATE
lcd $BAK_PATH
cd $DATE
prompt off
mput *
lcd $BAK_PATH_1
mput *
bye
!
ftp -n<<!               #删除8天前的日志文件
open $REMOTE_IP
user crmtest 1qaz2wsx,,
prompt off
cd $REMOTE_PATH
mdelete $REMOTE_PATH/$OUTDATE_FILE/
rmdir $REMOTE_PATH/$OUTDATE_FILE/
close
bye
!
exit 0