mysql脚本备份
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql脚本备份相关的知识,希望对你有一定的参考价值。
[[email protected] ~]# 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 增量备份脚本如下 [[email protected] ~]# 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脚本备份的主要内容,如果未能解决你的问题,请参考以下文章