[[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/backtime= ' Date +%f--%t ' datedir1=/data/back/all_$timedatedir2=/data/back/${base}_${time}if [ -z $base ];thenmysqldump -uzou -h172.16.1.7 -p123.comer --all-databases -- lock-all-tables --flush-logs > $datedir 1 >>/dev/null[ $? == 0 ] && echo "$time == all databases has Backup ok " >> /data/back/back.log | | exit 5else 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 7mysqldump -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 | | The exit 9fi incremental backup script is as follows [[email protected] ~]# cat mysqldump_added.sh #!/bin/bash# mysqladmin flush-logsbackindexdir=/data/indexback/[ -e $backindexdir ] | | mkdir -p /data/indexback/indexfile= ' grep ' ^log_bin ' /etc/my.cnf | awk -f "=" ' {print $2} '. indexindexdir= ' grep ' DataDir ' /etc/my.cnf | cut -d = -f2 ' binfiles= ' Cat ${indexdir}/${indexfile} ' Totalfile= ' wc -l ${indexdir}/${indexfile} | awk ' {print $1} ' numindex=0for file in $binfiles;d onumindex=$ (($numindex + 1)) base= ' basename $file ' #判断备份目录里面没有这个文件, And is not a newly generated binary file (the above command will automatically create a new temporary no data) if [ ! -e $backindexdir/$base -a $numindex -ne $totalfile ];thencp $indexdir/$base $backindexdirfidone
This article is from the "Arctic Linux" blog, be sure to keep this source http://941012521.blog.51cto.com/9253690/1845536
MySQL script backup