MySQL分库备份脚本

#!/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
posted @ 2018-07-13 10:43  Testder探索者  阅读(103)  评论(0编辑  收藏  举报