mysql 版本: 5.6
Mysql 分库备份脚本
#!/bin/sh
#Backup databases into separated files excluding system schemas
BACKUP_FOLDER=/home/okchem/mysqlbackup
MYUSER=user
MYPASS=password
SOCKET=/data/mysql/mysql.sock
MYCMD="mysql -u$MYUSER -p$MYPASS -S $SOCKET"
MYDUMP="mysqldump -u$MYUSER -p$MYPASS -S $SOCKET"
mkdir -p ${BACKUP_FOLDER}
#for database in `$MYDUMP -e "show databases;"|sed '1,2d'|egrep -v "mysql|schema"`
for database in `$MYCMD -e "show databases;" | egrep -Evi "database|mysql|schema|test"`
do
$MYDUMP $database >${BACKUP_FOLDER}/${database}_$(date +%Y%m%d).sql
#If compression is needed, use this command: $MYDUMP $database |gzip >/server/backup/${database}_$(date +$F).sql.gz
done
版权声明:本文为choelea原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。