[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