MySQL backup script

Source: Internet
Author: User
Tags mysql backup

#!/bin/bash#auto backup mysql every database; #date  2014.07.07#author firxiao### mysql_config### #HOST = "localhost"         # #mysql主机IPUSER = "xxxx"               # #用户名PASSWD = "xxxx"             # #密码BACKUPDIR = '/backup '      # #备份目录 # # # ############### #DATE = ' date +%y%m%d '      # #当前日期 (no need to change) m= ' date +%y%m '            # #当前月 (no need to change) Function createdir ()            # #判断备份目录是否存在   does not exist create {while [ ! -d  $BACKUPDIR  ]; do        echo  "$BACKUPDIR  is not  Exits, will create now "        mkdir -p $ backupdirdonecd  $BACKUpdirwhile [ ! -d  "$DATE" &NBSP;];d O        mkdir   $DATEdonewhile  [ ! -d  "$M" &NBSP;];d o         mkdir  $Mdone}function showdatabase ()           ## Find out which libraries are in MySQL {mysql -h  $HOST  -u$USER -p$PASSWD -e  ' show databases; '  |grep -v  ' Database ' |grep -v  ' Information_schema '  > /tmp/mysqldblist} function backup  ()                # #备份并将备份移到当前月份文件夹 {while read linedo   mysqldump -h  $HOST  -u$user  -p$PASSWD  $LINE  >  $DATE/$LINE $date.sqldone < /tmp/mysqldblistmysqldump  -h  $HOST  -u$USER -p$PASSWD --all-database >  $DATE/all$date.sqltar  cvfj  $DATE .tar.gz  $DATErm -rf  $DATEmv   $DATE .tar.gz  $M/}createdir && showdatabase &&  backup    # #开始备份



Related Article

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.