MySQL script backup

Source: Internet
Author: User

[[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.