Hansen's ink

Back

1、数据库备份脚本#

2、配置文件 config.json#

3、验证脚本 verify_backup.py#

4、使用说明#

# 1. 修改config.json中的数据库配置
# 2. 创建备份目录
sudo mkdir -p /data/backups/mysql
sudo chmod 755 /data/backups/mysql

# 3. 测试连接
python3 mysql_backup.py --config config.json --test

# 4. 手动执行一次备份
python3 mysql_backup.py --config config.json --run
shell

服务器定时执行脚本:

# 编辑crontab
crontab -e

# 添加以下内容,每天凌晨2点执行备份
0 2 * * * /usr/bin/python3 /data1/backups/mysql_backup/mysql_backup.py --config /data1/backups/mysql_backup/config.json --run >> /var/log/mysql_backup_cron.log 2>&1

# 查看crontab
crontab -l
shell
MySQL 自动备份脚本
https://astro-pure.js.org/blog/mysql-backup
Author Hansen W.
Published at October 26, 2025
Comment seems to stuck. Try to refresh?✨