如何进行MySQL mysqldump从库备份,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
#!/bin/bash
MYSQL_PATH=/data/bin
export PATH=$PATH:$MYSQLPATH
DATABASE=***
PASSWORD=***
BACKUP_PATH=/server/backup/$(date +%F)
BACKUP_FILE=$BACKUP_PATH/$DATABASE_$(date +%F).sql.gz
BACKUP_LOG=/server/error_backup_log.txt
CNF=/etc/my.cnf
OLD_PATH=/server/backup/$(date +%F –date='28 days ago')
echo "$(date "+%F %T") backup is started." >> $BACKUP_LOG
if [ -d $OLD_PATH ]
then
rm -fr $OLD_PATH &>>$BACKUP_LOG
echo "delete the old dir $(date +%F –date='28 days ago')" >> $BACKUP_LOG
fi
if [ ! -d $BACKUP_PATH ]
then
mkdir -p $BACKUP_PATH
fi
mysqldump –master-data=2 –single-transaction -uroot -p$PASSWORD -F $DATABASE |gzip >$BACKUP_FILE
cp $CNF $BACKUP_PATH
echo "$(date "+%F %T") backup is completed." >> $BACKUP_LOG
看完上述内容,你们掌握如何进行MySQL mysqldump从库备份的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/tech/database/204380.html