Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2343727
  • 博文数量: 276
  • 博客积分: 5998
  • 博客等级: 大校
  • 技术积分: 5175
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 14:43
文章分类

全部博文(276)

文章存档

2014年(25)

2013年(11)

2012年(69)

2011年(167)

2010年(4)

分类: Mysql/postgreSQL

2011-10-12 11:48:25

  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
阅读(1146) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~