From 58ed82c4277e3b07c3f02b6491c2137d3045cc86 Mon Sep 17 00:00:00 2001 From: xiaowei Date: Sat, 30 May 2026 02:15:02 +0800 Subject: [PATCH] =?UTF-8?q?G8:=20=E5=9F=BA=E7=A1=80=E8=AE=BE=E6=96=BD?= =?UTF-8?q?=E5=8A=A0=E5=9B=BA=20=E2=80=94=20=E5=A4=87=E4=BB=BD=20+=20Prome?= =?UTF-8?q?theus=20+=20Nginx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建 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 可抓取 --- deploy/nginx-zhiyi.conf | 1 - deploy/zhiyi-backup.service | 13 +++++++++++ deploy/zhiyi-backup.sh | 44 +++++++++++++++++++++++++++++++++++++ deploy/zhiyi-backup.timer | 10 +++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 deploy/zhiyi-backup.service create mode 100755 deploy/zhiyi-backup.sh create mode 100644 deploy/zhiyi-backup.timer diff --git a/deploy/nginx-zhiyi.conf b/deploy/nginx-zhiyi.conf index 50c2118..2c7c622 100644 --- a/deploy/nginx-zhiyi.conf +++ b/deploy/nginx-zhiyi.conf @@ -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 健康检查(含依赖检测) diff --git a/deploy/zhiyi-backup.service b/deploy/zhiyi-backup.service new file mode 100644 index 0000000..acfe7db --- /dev/null +++ b/deploy/zhiyi-backup.service @@ -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 diff --git a/deploy/zhiyi-backup.sh b/deploy/zhiyi-backup.sh new file mode 100755 index 0000000..4b04085 --- /dev/null +++ b/deploy/zhiyi-backup.sh @@ -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." diff --git a/deploy/zhiyi-backup.timer b/deploy/zhiyi-backup.timer new file mode 100644 index 0000000..88f2a87 --- /dev/null +++ b/deploy/zhiyi-backup.timer @@ -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