Shell---mysql backup

Source: Internet
Author: User
Tags mysql backup

#!/bin/bash#file: mysql_backup.sh#date 2016-1-9backdes=/data/msyql_back/' date +%Y-%m-%d '       //Create the directory that holds the backup data backname= ' date +%y-%m-%d '      //backup name, You can omit the database=test      //backed up database mysqluser=root     // The user name at the time of backup #mysqlsec=         //the password at the time of backup, consider security, General manual input if [  $UID  -ne 0 ] ; then     //this if statement to indicate that root user backup must be used          echo  " you must use root to backup!"         sleep 2         exitfiif [ ! -d  $BACKDES  ] ; then      // This segment if statement, which indicates that the directory where the data is stored does not exist, creates         mkdir -p  $BACKDESelse          echo  "This dir exists." ficd  $BACKDES  && /usr/bin/mysqldump -u  $MYSQLUSER  -p -d $ database >  "$BACKNAME". sql     //into the directory where the data is stored, the command that is currently executing the backup database if [  $? -le 0 ] ; then      //This segment if statement indicates that the previous instruction executed successfully, Package. sql and prompt for export database success         tar -czvf  $BACKNAME. tar.gz   "$BACKNAME" .sql        echo  "$DATABASE  check is  successful! " else        echo  "checkout  $DATABASE  is not  successful! " Ficd /data/msyql_back/ && find . -type d -mtime +10 -exec  rm -rf {} \; && ls     //Delete the directory 10 days ago and view the current directory if  [ $? -le 0 ] ; then       //if the previous execution succeeds, prompt data backup completes, otherwise prompts to have the error, needs to check.         echo  "Congratulations, the data package  backup successful! " else        echo  "Sorry, something error, must  check it! " Fi


This article from "Experience from pain" blog, declined reprint!

Shell---mysql 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.