MySQL mydumper全库备份脚本

  运维
#!/usr/bin/bash
#全库备份脚本
alldump()
{
echo "=========开始备份=========="
/usr/local/bin/mydumper -h '127.0.0.1' -P 3306 -u 'root' -p '123456'  \
--regex '^(?!(mysql|test|sys))' -e -o '/opt/databackup/mysql_'$(date +%Y%m%d%H) -t 32  -v 3 -R \
-L '/opt/databackup/mysql_'$(date +%Y%m%d).log 
echo "=========备份成功=========="
}

cleandisk()
{
dir="/opt/databackup/mysql_`date -d '-10 days' +%Y%m%d`"
if [ -d ${dir} ]; then 
echo "=========开始清理磁盘=========="
rm -rf /opt/databackup/mysql_`date -d '-10 days' +%Y%m%d`
rm -rf /opt/databackup/mysql_`date -d '-10 days' +%Y%m%d`.log

echo "=========磁盘清理完成=========="
else 
echo "=========无需清理磁盘=========="
fi
}

alldump # && cleandisk

LEAVE A COMMENT

Captcha Code