Files
deploy.stack/hindsight/backup.job
cnphpbb 0cf24fee31 refactor(hindsight): 使用Volumes_Path替代硬编码路径
- backup.job 改为从 env.cfg 读取 Volumes_Path
- stack.yml 路径替换为变量引用
- .gitignore 添加 hindsight/env.cfg
2026-06-08 03:28:26 +08:00

30 lines
927 B
Bash
Raw Permalink 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.
#!/bin/bash
# ============================================================
# Hindsight 备份任务(每日 02:30 跑cron 部署参考 crontab/
# - 热备份docker exec pg_dump 落盘到 bind 挂载的 backups/
# - 保留 7 天的 .sql.gz
# ============================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=/dev/null
source "${SCRIPT_DIR}/env.cfg"
BACKUP_DIR="${Volumes_Path}/backups"
KEEP_DAYS=7
TS=$(date +%Y%m%d_%H%M%S)
FNAME="hindsight_db_${TS}.sql.gz"
mkdir -p "${BACKUP_DIR}"
docker exec hindsight-db pg_dump \
-U hindsight_user \
-d hindsight_db \
--no-owner --no-privileges \
| gzip > "${BACKUP_DIR}/${FNAME}"
# 清理超过 KEEP_DAYS 天的旧备份
find "${BACKUP_DIR}" -name "hindsight_db_*.sql.gz" -mtime +${KEEP_DAYS} -delete
echo "[backup] ok: ${FNAME} ($(du -h "${BACKUP_DIR}/${FNAME}" | cut -f1))"