Chinaunix首页 | 论坛 | 博客
  • 博客访问: 276095
  • 博文数量: 103
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 705
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-02 16:15
文章分类

全部博文(103)

文章存档

2014年(8)

2013年(95)

我的朋友

分类: Mysql/postgreSQL

2013-09-03 16:13:43

原文地址:binglog日志异地上传脚本 作者:xyaxlz

  1. #!/bin/bash

  2. BACK_DIR=/usr/local/mysql


  3. #ftp define
  4. ftpuser=xxx
  5. ftppwd=xxx
  6. ftpserver=ftp://xxx.xxx.xxx.xxx
  7. cur_ip=$(/sbin/ifconfig eth0 |grep "inet addr" |cut -d: -f2 |cut -d" " -f1)
  8. bin_dir=$(echo $cur_ip|awk -F . '{print $4}')
  9. ftp_dir=binlog/bak_$bin_dir

  10. #bin-log
  11. BINLOG=$BACK_DIR/binlog


  12. # mysql
  13. MYSQL_DIR=/usr/local/mysql

  14. # mysql data
  15. DATA_DIR=$MYSQL_DIR/binlog

  16. LOG_DIR=/home/mysql/logs

  17. #md5
  18. #sshuser=root
  19. #sship=192.168.99.98

  20. #log
  21. LOG=$LOG_DIR/binlog.log


  22. backup_binlog(){

  23.         if [ ! -f $LOG_DIR/mysql-bin.index ];then

  24.                 head -n -1 $DATA_DIR/mysql-bin.index > $LOG_DIR/mysql-bin.index


  25.         else


  26.                 BINSID=`tail -1 $LOG_DIR/mysql-bin.index | sed 's#/usr/local/mysql/binlog/##'`


  27.                 newfile=`cat $DATA_DIR/mysql-bin.index | sed -n "/$BINSID/,//p" | sed "/$BINSID/d" | head -n -1 | sed 's#/usr/local/mysql/binlog/##'`


  28.                 for i in $newfile
  29.                 do
  30.                         cd $DATA_DIR
  31.                         md5sum $i > $LOG_DIR/logmd5/${i}.md5
  32.                         curl -T $DATA_DIR/$i -u $ftpuser:$ftppwd $ftpserver/$ftp_dir/
  33.                         curl -T $LOG_DIR/logmd5/${i}.md5 -u $ftpuser:$ftppwd $ftpserver/$ftp_dir/
  34.                         if [ $? -eq 0 ];then
  35.                                 echo `date +'%Y%m%d %H:%M:%S'` ftpsucess $?>>$LOG
  36.                                 echo "/usr/local/mysql/binlog/${i}" >> $LOG_DIR/mysql-bin.index
  37.                         else
  38.                                 echo `date +'%Y%m%d %H:%M:%S'` ftpfail $?>>$LOG
  39. # curl ""
  40.                         fi

  41.                 done
  42.                 failsum=$(tail -6 $LOG |grep ftpfail|wc -l)
  43.                 if [ $failsum = 6 ];then
  44.                 curl ""
  45.                 fi
  46.         fi
  47. }



  48. DTTERM=`pgrep curl`
  49. if [ -n "$DTTERM" ]
  50. then exit
  51. else
  52. backup_binlog
  53. fi
阅读(880) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~