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