创建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
标签:-%,log,+%,database,备份,MySQL,date,outdir,多库 From: https://www.cnblogs.com/outsrkem/p/18528938