首页 > 代码库 > mysql脚本备份
mysql脚本备份
[root@slave ~]# cat mysqldump.sh #!/bin/bash # echo "============================" echo "mysql dump,youcan choose which database to backup,if not I will back all databases" echo "===========================" read -p "Please tell me which database do you want to backup ===> " base [ -d /data/back ] || mkdir -p /data/back && chown -R mysql.mysql /data/back time=`date +%F--%T` datedir1=/data/back/all_$time datedir2=/data/back/${base}_${time} if [ -z $base ];then mysqldump -uzou -h172.16.1.7 -p123.comer --all-databases --lock-all-tables --flush-logs > $datedir1 >>/dev/null [ $? == 0 ] && echo "$time == ALL databases has backup ok" >> /data/back/back.log || exit 5 else mysql -e "use $base" &> /dev/null [ $? == 0 ] || echo "Maybe the database $base is not exsit or the name is wrong" >> /data/back/back.log && exit 7 mysqldump -uzou -h172.16.1.7 -p123.comer --databases --lock-tables $base > $datedir2 >> /dev/null [ $? == 0 ] && echo "database $base has backup ok" >> /data/back/back.log || exit 9 fi 增量备份脚本如下 [root@slave ~]# cat mysqldump_added.sh #!/bin/bash # mysqladmin flush-logs backindexdir=/data/indexback/ [ -e $backindexdir ] || mkdir -p /data/indexback/ indexfile=`grep ‘^log_bin‘ /etc/my.cnf | awk -F "=" ‘{print $2}‘`.index indexdir=`grep ‘datadir‘ /etc/my.cnf | cut -d = -f2` binfiles=`cat ${indexdir}/${indexfile}` totalfile=`wc -l ${indexdir}/${indexfile} | awk ‘{print $1}‘` numindex=0 for file in $binfiles;do numindex=$(($numindex+1)) base=`basename $file` #判断备份目录里面没有这个文件,并且不是刚生成的二进制文件(上面执行命令会自动创建一个,新的暂时没数据) if [ ! -e $backindexdir/$base -a $numindex -ne $totalfile ];then cp $indexdir/$base $backindexdir fi done
本文出自 “北极的linux” 博客,请务必保留此出处http://941012521.blog.51cto.com/9253690/1845536
mysql脚本备份
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。