MySQL backup script

Source: Internet
Author: User
Tags mysql backup

First script:

#!/bin/bash

#MYSQL备份脚本

#Date: 2017/08/17



bak_dir=/data/backup/' Date +%y%m%d '

mysqldb= database name

Mysqluser= Users

mysqlpwd= Password

Mysqlcmd=/usr/bin/mysqldump

mysqlser= Database Server

mysqlport= Port


if [!-D $BAK _dir];then

Mkdir-p $BAK _dir

Echo-e "\033[32mthe $BAK _dir Create successful!\033[0m"

Sleep 5s

$MYSQLCMD-u$mysqluser-p$mysqlpwd-h $MYSQLSER-P $MYSQLPORT--database $MYSQLDB > $BAK _dir/$MYSQLDB. S

Ql

echo "The ' Date +%y%m%d '-$MYSQLDB backup successful!" &>/dev/null

/bin/tar zcf $BAK _dir/' Date +%y%m%d '-$MYSQLDB. tar.gz $BAK _dir/$MYSQLDB. sql && rm-rf $BAK _dir/$MYSQLDB.

SQL &>/dev/null

Else

echo "The $BAK _dir is already exists!"

Exit

Fi



A second script:

#!/bin/bash

#此脚本是自动备份mysql数据库 and package the backed up database back into your windows!

#因为这个脚本执行, you need your windows to use a terminal to connect to the server in order to use the RZ command!

#Date: 2017/08/17

Command=/usr/bin/sz

bak_dir=/data/backup/' Date +%y%m%d '

$COMMAND $BAK _dir/*


#两脚本需要配合使用, add a self-timer task for daily scheduled backups


This article is from "Change life Start Fresh." blog, declined reprint!

MySQL 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.