基于dockerMysql的shell备份脚本

#!/bin/bash
#For Backup Mysql
#Date:XXX
DOCKERNAME="dockernames"
USER="xx"
PASS="xx"
MYSQL_BAKDIR="/data/mysqlback/"
MYSQL_DIR="/data/mysqlback/date +%Y%m%d"
function CMD()
{
docker exec ${DOCKERNAME} mysqlshow -u${USER} -p${PASS}
return 0
}

function DEL()
{
find ${MYSQL_BAKDIR} -type d -name date +"%Y%m%d" -d "-7 days"|xargs rm -rf
return 0
}

function DUMP()
{
docker exec ${DOCKERNAME} mysqldump -u${USER} -p${PASS} ${1}
echo ${1}
return 0
}

if [ ! -d ${MYSQL_DIR} ];then
mkdir ${MYSQL_DIR} -p
fi
for i in CMD
do
echo $i|grep -qnviE '-|+|||schema|Databases' && DUMP ${i}|gzip > ${MYSQLDIR}/${i}$(date +%F).sql.gz && if [ -f ${MYSQLDIR}/${i}$(date +%F).sql.gz ];then
echo -e "date \ndump success" >> /mysqlback.log
else
echo -e "date \ndump failed" >> /mysqlback.log
fi
done
DEL

转载于:https://blog.51cto.com/13958766/2171941

你可能感兴趣的:(基于dockerMysql的shell备份脚本)