備份與還原
hotel-intel(PostgreSQL → GFS)
Section titled “hotel-intel(PostgreSQL → GFS)”走共用框架 ~/Code/backup-toolkit/(hotel-intel 是第一個 consumer)。
| 動作 | 指令 |
|---|---|
| 手動備份 | make backup-db-gfs |
| 健康檢查 | make backup-health |
| 還原 | make restore-db-gfs |
| 每天自動 | cron 30 3 * * * → scripts/backup-db-gfs.sh |
保留政策:daily 7、weekly(週六)4、monthly(13 號)6、yearly(6/15)2。
格式:pg_dump --format=custom → tar | zstd-8(custom format 自帶 schema+data,面對 schema drift 還原最彈性)。
- 還原進現有 DB 前,先確認當天已
make backup-db-gfs拍一份現在的。 - 面對 schema drift 用
--fresh-db,別對現 DB 用--clean。 - 詳細食譜見
backup-toolkit/CLAUDE.md「還原食譜」。
已知 follow-up:
backup-health目前沒 wire 進 cron/notify,備份失敗無主動告警。
Cloudflare 資料(D1 / KV / R2)
Section titled “Cloudflare 資料(D1 / KV / R2)”- D1:用
wrangler d1 export <db>定期匯出;或依賴 CF 平台備份。 - KV:short-lived session,一般不需備份;長期設定值另管。
- R2(圖片/物件):視重要性,用
rclone或 CF 的 R2 同步工具備份。
各服務 D1/KV 的具體備份頻率與責任歸屬,待各產品頁補上。