#!/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