針對可能會個毀壞的資料進行備份,重要的資料大概有三類:Database,Files和Configuration
Database
├── SQLite
│ └── inventory / product / events / notifications
Files
├── photos/
│ └── ESP32 上傳照片
Configuration
├── .env
├── systemd service
├── application config
└── mappings / rules
檔案系統中,分別有一些程式碼,但已經透過 Git 方式保存。 (但是其中涉及機敏的資訊並不會進到版本控制)
Code
├── app/
├── services/
├── routers/
└── scripts/
Data
├── database/fridge.db
└── photos/
Config
├── .env
├── systemd
└── runtime settings
sqlite3 \
database/fridge.db \
".backup backup/fridge.db"
import sqlite3
from pathlib import Path
SOURCE = Path(
"database/fridge.db"
)
DEST = Path(
"backup/fridge.db"
)
def backup_database():
DEST.parent.mkdir(
parents=True,
exist_ok=True,
)
with sqlite3.connect(
SOURCE
) as source:
with sqlite3.connect(
DEST
) as target:
source.backup(
target
)