MySQL 备份与还原

备份

每天自动备份脚本:/etc/cron.daily/backup_deepflow_database.cron

#!/bin/bash
path="/usr/local/deepflow/db"
mkdir -p $path
cd $path
mysqldump -uroot -p123456 deepflow --set-gtid-purged=OFF | gzip > backup-deepflow-$(date +%F).sql.gz
# 删除7天之前的备份文件
ls backup-deepflow-* | head -n -7 | xargs rm -f
exit 0

还原

cd 到/usr/local/deepflow/db/
# 解压备份文件
gzip -d backup-deepflow-2019-09-18.sql.gz
mysql -uroot -p deepflow < backup-deepflow-2019-09-18.sql

本文链接:

http://blog.ps-ef.cn/Linux/58.html
1 + 3 =
快来做第一个评论的人吧~