MySQL backup script

Source: Internet
Author: User
Tags mysql backup

#!/bin/bash

#auto backup MySQL

#xiaosu 2015-08-06


User=root

password=123456

dir_back=/data/' Date +%y%m%d '

Date= ' Date +%y%m%d '

Database=test


#判断用户是否是管理员root


If [$UID-ne 0];then

Echo-e "\033[32mthe script must use root\033[0m"

Sleep 2

Exit

Fi


#判断备份目录是否存在


if [!-D $DIR _back];then

Mkdir-p $DIR _back;

Else

Echo-e "\033[32mthe $DIR _back is exist\033[32m"

Fi


#备份数据库

/usr/local/mysql/bin/mysqldump-u$user-p$password-d $DATABASE > $DIR _back/$DATE. sql


If [-F $DIR _back/$DATE. SQL];then

echo "The Mysqlbackup successfully"

Else

echo "The Mysqlbackup faied"

Fi


This article is from the "Linux---basics" blog, so be sure to keep this source http://perin.blog.51cto.com/10410663/1693253

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.