資料庫備份
Piora 使用各資料庫的原生備份工具來確保備份的完整性與相容性。
支援的資料庫
Section titled “支援的資料庫”| 資料庫 | 備份工具 | 備份格式 |
|---|---|---|
| PostgreSQL | pg_dump | .sql / .dump |
| MySQL / MariaDB | mysqldump | .sql |
| MongoDB | mongodump | BSON 二進位 |
PostgreSQL 備份
Section titled “PostgreSQL 備份”設定自動備份
Section titled “設定自動備份”- 進入 PostgreSQL 資料庫設定頁面
- 點選「備份」分頁
- 設定備份排程與儲存位置
- 點選「啟用」
| 參數 | 說明 | 建議值 |
|---|---|---|
| 備份格式 | SQL 純文字或自訂格式 | 自訂格式(支援平行還原) |
| 壓縮 | 是否壓縮備份檔案 | 啟用 |
| 排程 | 備份頻率 | 每日 |
| 保留數量 | 保留幾份備份 | 7 |
手動備份與還原
Section titled “手動備份與還原”# 手動觸發備份(透過控制面板終端機)pg_dump -U piora_admin -Fc myapp > /backup/myapp_$(date +%Y%m%d).dump
# 還原備份pg_restore -U piora_admin -d myapp /backup/myapp_20240115.dumpMySQL / MariaDB 備份
Section titled “MySQL / MariaDB 備份”設定自動備份
Section titled “設定自動備份”- 進入 MySQL 資料庫設定頁面
- 點選「備份」分頁
- 設定參數與排程
- 啟用自動備份
# 完整備份mysqldump -u root -p --single-transaction --routines --triggers myapp > backup.sql
# 壓縮備份mysqldump -u root -p --single-transaction myapp | gzip > backup.sql.gz
# 還原mysql -u root -p myapp < backup.sqlMongoDB 備份
Section titled “MongoDB 備份”設定自動備份
Section titled “設定自動備份”# 完整備份mongodump --uri="mongodb://admin:password@mongodb:27017/myapp?authSource=admin" \ --out=/backup/mongodb_$(date +%Y%m%d)
# 壓縮備份mongodump --uri="mongodb://admin:password@mongodb:27017/myapp?authSource=admin" \ --archive=/backup/myapp.archive --gzip
# 還原mongorestore --uri="mongodb://admin:password@mongodb:27017/myapp?authSource=admin" \ /backup/mongodb_20240115/myapp/備份儲存至雲端
Section titled “備份儲存至雲端”設定 S3 儲存
Section titled “設定 S3 儲存”Piora 使用 RClone 將備份上傳到雲端儲存:
- 在控制面板的「備份設定」中新增儲存目的地
- 選擇儲存類型(S3、R2、GCS 等)
- 填入認證資訊:
| 參數 | 說明 |
|---|---|
| Endpoint | S3 端點 URL |
| Access Key | 存取金鑰 |
| Secret Key | 密鑰 |
| Bucket | 儲存桶名稱 |
| Region | 區域(如 us-east-1) |
為了保護備份資料的安全性,你可以啟用備份加密:
- 備份檔案在上傳前會以 AES-256 加密
- 加密金鑰由你自行設定與保管
- 還原時需要提供正確的加密金鑰
監控備份狀態
Section titled “監控備份狀態”在控制面板中可以查看:
- 最近的備份記錄與狀態
- 備份檔案大小
- 備份耗時
- 失敗的備份與錯誤訊息