A MySQL backup script (can be adjusted with multiple instances)

Source: Internet
Author: User
Tags mysql backup

MySQL Database backup script:

#!/bin/bash# Defining variable Information user=rootpass=redhat12345  socket=/data/3306/mysql.sockcmd= "Mysql -u$USER  -p$PASS -S  $SOCKET "dump=" mysqldump --opt -u$user -p$pass -s  $SOCKET " Des= "/usr/src/mysqlbackup" backuptime= "date +%f-%h:%m" #目录判断if  [ ! -d  "$DES/' date  +%f '  ];thenmkdir -p  $DES/' date +%f ' "Fi#mysqldump Backup Database echo "------------------------ ----Start backup mysql-------------------------------"for database in  ' $CMD  -e   "show databases"  | sed  ' 1,2d '  | egrep -v  "Mysql|schema" ' Do$dump   $database  -B|gzip> $DES/' date +%f '/${database}.sql.gzif [ $? -eq 0  ];thenecho  "$database  has been backup successful" elseecho  "$database  has  been not successful "fi/bin/sleep 5doneecho "---------------------------backup  is end -------------------------------------" 

The

Execution results are as follows:

[[email protected] mysqlbackup]# pwd/usr/src/mysqlbackup[[email protected]  Mysqlbackup]# ll Total dosage  4-rw-r--r-- 1 root root 805 12 month   6 18:50  backup.sh[[email protected] mysqlbackup]# bash backup.sh ---------------------- ------Start backup mysql-------------------------------dawnpro has been backup  successfulhangzhou has been backup successfuljames has been backup  Successfulwanlong has been backup successful---------------------------Backup is  end -------------------------------------[[email protected] mysqlbackup]# ll Total dosage  8drwxr-xr-x 2 root root 4096 12 Month   6 18:56 2016-12-06- Rw-r--r-- 1 root root  805 12 Month   6 18:50 backup.sh[[email  protected] mysqlbackup]# ll 2016-12-06/Total dosage  16-rw-r--r-- 1 root root 512 12 month   6 18:56  dawnpro.sql.gz-rw-r--r-- 1 root root 513 12 Month   6 18:56  Hangzhou.sql.gz-rw-r--r-- 1 root root 511 12 Month   6 18:56  James.sql.gz-rw-r--r-- 1 root root 511 12 Month   6 18:56  wanlong.sql.gzmysql> show databases;+--------------------+| database            |+--------------------+| information_schema | |  dawnpro            | |  hangzhou           | |  james              | |  mysql              | |  performance_schema | |  wanlong            |+--------------------+7  rows in set  (0.00 SEC)

Make a simple record, then add a detailed note or optimize the script in the back.

This article is from the "Frozen vs watermelon" blog, so be sure to keep this source http://molewan.blog.51cto.com/287340/1880184

A MySQL backup script (can be adjusted with multiple instances)

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.