Shell script to back up the database

Source: Internet
Author: User
Tags mysql backup

#!/bin/bash
#back_mysql by 2016-11-14
bak_dir=/data/backup_db/' Date +%y%m%d '
Mysqldb=mysql
mysqluser=*****
mysqlpw=******
If [$UID-ne 0];then

echo "must to being use as root for exec shell"
Exit
Fi
#判断是否存在文件, \033[32m is the color of the display
if [!-D $bak _dir];then
Mkdir-p $bak _dir
Echo-e "\033[32mthe $bak _dir Create successfully!\033[0m"
Else
echo "This $bak _dir is exists ...."
Fi
#备份语句
mysqldump-u$mysqluser-p$mysqlpw-d $mysqldb > $bak _dir/$mysqldb. sql.tar.gz
#是否备份成功
If [$?-eq 0];then
ECHO-E "\033[32mthe MySQL backup $mysqldbsuccessfully \033[0m"
Else
ECHO-E "\033[32mthe MySQL backup $mysqldb failed. pleasecheck!\033[0m"
Fi
#执行脚本和备份结果
650) this.width=650; "src=" http://s5.sinaimg.cn/mw690/006lH9E0zy76psAu5s8f4&690 "alt=" script "title=" to back up the database Script for backing up the database "height=" width= "445"/>

650) this.width=650; "src=" http://s11.sinaimg.cn/mw690/006lH9E0zy76psAwDeW3a&690 "alt=" script "title=" to back up the database The script for backing up the database "height=" width= "417"/>


This article from "All Technical Blog" blog, reproduced please contact the author!

Shell script to back up the database

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.