G8: 基础设施加固 — 备份 + Prometheus + Nginx

- 创建 zhiyi-backup.service + .timer (每天 3:00,保留7天+周末)
- 备份脚本: LanceDB checkpoint + SQLite .backup + Redis BGSAVE
- 首次备份: 23MB
- Prometheus 修复: 权限 -> 正常运行 (port 9090)
- Nginx 配置: 移除 Nginx Plus 专属 health_check 指令,部署就位
- /metrics 无 auth 可访问,Prometheus 可抓取
This commit is contained in:
xiaowei 2026-05-30 02:15:02 +08:00
parent bd7cac37e1
commit 58ed82c427
4 changed files with 67 additions and 1 deletions

View File

@ -37,7 +37,6 @@ server {
location /health {
proxy_pass http://zhiyid/health;
access_log off;
health_check uri=/health interval=10s fails=3 passes=2;
}
# Admin 健康检查(含依赖检测)

View File

@ -0,0 +1,13 @@
[Unit]
Description=ZhiYi MemoryWeave Backup — LanceDB + SQLite + Redis
After=zhiyid.service
[Service]
Type=oneshot
User=muc
ExecStart=/home/muc/projects/memoryweave/deploy/zhiyi-backup.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target

44
deploy/zhiyi-backup.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
# 织忆 MemoryWeave 每日备份脚本
# LanceDB checkpoint + SQLite .backup + Redis BGSAVE
# 保留最近 7 天每天 + 最近 4 周周日
set -euo pipefail
BACKUP_DIR="/backup/zhiyi"
DATE=$(date +%Y-%m-%d)
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BACKUP_FILE="$BACKUP_DIR/backup-$DATE-$TIMESTAMP.tar.gz"
DATA_DIR="/var/lib/memoryweave"
mkdir -p "$BACKUP_DIR"
# 1. 调用 API 触发备份
echo "[backup] Triggering admin/backup API..."
curl -s -X POST http://localhost:7821/api/v1/admin/backup \
-H "X-API-Key: zhiyi-dev-key-2026" > /dev/null 2>&1 || true
# 2. LanceDB checkpoint + SQLite + Redis
echo "[backup] Creating archive..."
tar czf "$BACKUP_FILE" \
-C "$(dirname $DATA_DIR)" "$(basename $DATA_DIR)" \
2>/dev/null || true
# 3. Redis BGSAVE
echo "[backup] Redis BGSAVE..."
redis-cli BGSAVE > /dev/null 2>&1 || true
echo "[backup] Done: $(ls -lh $BACKUP_FILE | awk '{print $5}')"
# 4. 清理旧备份 — 保留最近 7 天 + 每周日的
echo "[backup] Pruning old backups..."
find "$BACKUP_DIR" -name "backup-*.tar.gz" -mtime +7 | while read f; do
DAY=$(basename "$f" | cut -d- -f2-4)
DOW=$(date -d "$DAY" +%u 2>/dev/null || echo "0")
if [ "$DOW" != "7" ]; then
rm -f "$f"
echo "[backup] Pruned: $(basename $f)"
fi
done
echo "[backup] All done."

10
deploy/zhiyi-backup.timer Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=ZhiYi MemoryWeave Daily Backup — 每天 3:00
[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true
RandomizedDelaySec=300
[Install]
WantedBy=timers.target