Chinaunix首页 | 论坛 | 博客
  • 博客访问: 205892
  • 博文数量: 75
  • 博客积分: 2049
  • 博客等级: 大尉
  • 技术积分: 780
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-08 12:37
文章分类

全部博文(75)

文章存档

2011年(1)

2010年(9)

2009年(65)

我的朋友

分类:

2009-04-30 14:17:49

#!/bin/bash



#configuration


db_user="root"
db_password="123456"
db_host="10.10.11.151"
db_port="3306"
db_name="crashcourse"
db_bin_dir="/home/mysql/log/"
db_bin_prefix="mysql"
db_binbackup_dir="/dir/logbin_backup/"
time_now=` date '+%Y%B%d%H%M%S' `


#start


#start

mysqladmin -h$db_host -P$db_port -u$db_user -p$db_password flush-logs

cd $db_bin_dir
for i in `cat ${db_bin_prefix}-bin.index`
do
        bin_list="$bin_list `basename $i`"

done
latest=$(basename `cat ${db_bin_prefix}-bin.index|tail -n1`)
backup_list=`ls $db_binbackup_dir |grep "${db_bin_prefix}-bin"`
backup_latest=`ls $db_binbackup_dir|grep "${db_bin_prefix}-bin" |tail -n1`


for j in $bin_list
do
        need_backup="YES"
        for k in $backup_list
        do
                if [ $j = $k ]
                then
                        need_backup="NO"
                fi
        done
        if [ $j = $latest ]
        then
                need_backup="NO"
        fi

        if [ $j = $backup_latest ]
        then
                need_backup="YES"
        fi

        if [ $need_backup = "YES" ]
        then
                cp $j $db_binbackup_dir
        fi
done

阅读(1328) | 评论(0) | 转发(0) |
0

上一篇:mysql完全备份

下一篇:check_slave

给主人留下些什么吧!~~