[Web Squad] Database Dump, Restore & Create
目前官網 backend 有一台 PostgreSQL (GitHub Repo) 在跑,為了資料備份或是希望用 production data 做測試,網站組時常會需要執行 DB dump & restore。
此頁面紀錄了將 production DB data 倒進 staging DB 的步驟與對應指令。
TODO: DB dump & restore 的自動化方案
DB Dump
- ssh 到 production GCE 後,確認 postgres 有在運作
- 執行指令將 db data dump 到
/tmp
底下
** pycontw2022是db內table name, 不是docker name.
- 將 DB dump 用任何方式傳到 staging GCE 上,例如用 scp
DB Restore
- 進到 postgres container 將當年度 database 資料清除(刪除 db 並重建)
- 將 data dump restore 進當年度 database
DB Create
- 執行指令將前年度 db data dump 到
/tmp
底下
- 檢查db data是否dump成功, 並複製該db data 檔案名 (e.g db.dump.202401xx.sql)
- 進到 postgres container 建立當年度 database 資料
- 將前年度db data restore進當年度database