#!/bin/bash
#Date: 2018/7/13
#Author: Testder
#Mail: 10000@testder.cn
#Version: 1.0
# Each database that needs to be backed up
cat > /tmp/bak.txt <<EOF
mysql
JUN
zabbix
EOF
[ $? -eq 0 ] && echo "Create file success!!!" || echo "Failure to create a file"
# Variable declaration
DBLIST=$(cat /tmp/bak.txt)
DBUSER=root
DBPASS=000000
BAKPATH=/server/bakup/mysql
# Database backup execution script
for i in $DBLIST
do
[ ! -d ${BAKPATH}/$i ] && mkdir -p ${BAKPATH}/$i
mysqldump -u$DBUSER -p$DBPASS -x -B -F -R --events $i | gzip > /server/bakup/mysql/$i/mysql_${i}_$(date +%F-%T).sql.gz
[ $? -eq 0 ] && echo "Backup $i database success!!!" || echo "Failure to backup $i database"
done