Files
wx_service/docs/ops/backup_recovery.md
T
2026-02-28 16:39:53 +08:00

34 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 数据备份策略与恢复演练
对应 issue`#12 [P1][T9] 备份策略与恢复演练`
## 1. 备份策略
- 备份脚本:`scripts/ops/backup_mysql.sh`
- 备份格式:`<db>_YYYYmmdd_HHMMSS.sql.gz`
- 默认保留:`KEEP_DAYS=7`
- 支持告警:`OPS_ALERT_WEBHOOK`
推荐 cron(每天 02:00):
```bash
0 2 * * * MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=*** MYSQL_DATABASE=wx_service BACKUP_DIR=/var/backups/wx_service KEEP_DAYS=7 OPS_ALERT_WEBHOOK="https://example.com/webhook" /path/to/wx_service/scripts/ops/backup_mysql.sh >> /var/log/wx_service-backup.log 2>&1
```
## 2. 恢复流程
- 恢复脚本:`scripts/ops/restore_mysql.sh`
- 为避免误操作,必须显式设置:`CONFIRM_RESTORE=1`
示例:
```bash
CONFIRM_RESTORE=1 MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=*** MYSQL_DATABASE=wx_service /path/to/wx_service/scripts/ops/restore_mysql.sh /var/backups/wx_service/wx_service_20260228_020000.sql.gz
```
## 3. 演练建议
1. 先在演练库执行恢复,不要直接对生产库恢复。
2. 恢复后执行关键表行数与抽样数据校验。
3. 记录耗时、失败点、回滚步骤,形成固定 runbook。