Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1175437
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: Python/Ruby

2011-09-27 15:07:05

mysql自动备份的脚步,这个脚步可以输入参数以实现是完整备份还有增量备份

#!/bin/bash
echo -e "\033[31m please + f or d or i \033[0m"

FULLBK () {
  mysqldump --triggers --lock-all-tables --all-databases >/root/`date "+%Y:%m:%d--%H:%M:%S"`.sql
  if [ $? == 0 ];then
      tar jcf  /root/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2 /root/*.sql
      echo -e "\033[032m The backup is success....\033[0m"
         read -p "DO you want delete source file,y is "yes",other is "no": " A
         case $A in
         y|Y)
             rm -rf /root/*.sql
             echo -e "delete success....."
         ;;
         *)
              echo -e "you do nothing"
              return 2
        ;;
        esac
    else
      echo -e "\033[031m The backup is Failure....\033[0m"
  fi
}

############################################################################################33

ZLBK (){
 ZB='mysql -e "SHOW MASTER STATUS" |grep mysql-bin |cut -f1'
   if false;then
    mysql -e "FLUSH LOGS;"
    mysql -e   "FLUSH TABLES WITH READ LOCK;" 
#      read -p "please input you sql's data postion: " PT
    cp /data/mydata/$ZB /root/zback/
    tar jcf /root/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2 /root/$ZB && echo "Failure..."
    mysql -e "UNLOCK TABLES;"
      else
            CYBK
   fi
}

#############################################################################################

CYBK () {
   rm -rf /root/cyback && mkdir /root/cyback
    mysql -e "FLUSH LOGS;"
    mysql -e "FLUSH TABLES WITH READ LOCK;"
# read -p "please input you sql's data postion: " PT
    cp /data/mydata/mysql-bin* /root/cyback/ 
#    tar jcf /root/cyback/* /root/cyback/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2
    cd /root/cyback/
   tar jcf /mnt/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2 ./*
     REL=$?
    rm -rf /root/cyback/mysql-bin*
    mysql -e "UNLOCK TABLES;"    
}


# read -p "please input you sql's data postion: " PT
##############################################################################################
while getopts ":fid:" OPTS; do
 case $OPTS in
   f)
        FULLBK 
   ;;
   d)
        ZLBK 
   ;;
   i)    
        CYBK 
   ;;
    *)
          echo "nothing"
  ;;
  esac
done

#####################################################################################





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

上一篇:shell---LAMP

下一篇:一键制作linux

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