MySQL 多库备份脚本
创建MySQL备份用户: https://www.cnblogs.com/outsrkem/p/18528941
#!/bin/bash
DUMP="docker exec -it some-mysql /bin/mysqldump"
IPADDR=127.0.0.1
PORT=3306
USER=backupuser
PASSWD=backupuser
DATABASE=(db1 db2)
ROOT_DIR=/data
LogFile=/data/mysqldunp.log
DATE="`date +%Y%m%d`"
MYSQLDUMP="$DUMP -h$IPADDR -P$PORT -u$USER -p$PASSWD"
function log_info(){
echo -e "[`date +%Y-%m-%d\ %H:%M:%S`] - INFO " $@" " >> $LogFile
}
function log_error(){
echo -e "[`date +%Y-%m-%d\ %H:%M:%S`] - ERROR " $@" " >> $LogFile
}
function backup(){
local database=$1
local outdir="${ROOT_DIR}/mysql/${DATE}"
[ -d $outdir ] || mkdir -p $outdir
$MYSQLDUMP --databases --skip-extended-insert $database |gzip > ${outdir}/${database}-${DATE}.sql.gz
if [ $? == 0 ];then
log_info "${database} database ${table} table Backup successfully!"
else
log_error "${database}-${table} Backup failure 100"
exit 100
fi
}
log_info "Database backup starts `date +%Y-%m-%d\ %H:%M:%S`"
for db in ${DATABASE[*]}
do
backup $db
done
作者:Outsrkem
原文链接:https://www.cnblogs.com/outsrkem/p/18528938
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。