MySQL Database backup script

Source: Internet
Author: User
Tags mysql automatic backup mysql backup

Automatically back up MySQL scripts:

The following script for MySQL automatic backup script, for reference only, can be modified according to the actual situation. #!/bin/sh  #auto backup mysql  #20170329 # define PATH definition variable bakdir=/data/backup/mysql/' date +%y-%m-%d '   mysqldb=webapp mysqlpw=backup mysqlusr=backup  #must Use root user run scripts must be run with root, $ UID is System variable if    [$UID-ne 0];then    echo This script must use the root user!!! &nbs P  sleep 2    exit 0 fi  #Define dir and mkdir dir to determine if the directory exists, does not exist the new if    [!-D $ Bakdir];then    mkdir-p $BAKDIR  else    echo This is $BAKDIR exists.... fi& nbsp; #Use mysqldump backup MySQL uses mysqldump to back up the database/usr/bin/mysqldump-u$mysqlusr-p$mysqlpw-d $MYSQLDB > $BAKDIR/ WEBAPP_DB.SQL CD $BAKDIR; Tar-czf  webapp_mysql_db.tar.gz *.sql  #查找备份目录下以. SQL End file and delete the Find  . -type f-name "*.sql" |xargs rm-rf  #如何数据库备份成功, print successfully, and delete the backup directory 30 days before the directory [$?-eq 0]&&echo "This ' date +%y-%m-%d ' MySQL BACKUP is SUCCESS " cd/data/backup/mysql/; find.  -type d  -mtime +30 |xargs rm-rf echo "The MySQL backup successfully"

MySQL database backup script

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.