nex_math/scripts/db.sh

25 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
# nex_math 数据库运维:备份 / 恢复 / 内容快照。
#
# ./scripts/db.sh backup [标签] 备份 data/math.db(seed --force 也会自动备份)
# ./scripts/db.sh list 列出本机备份
# ./scripts/db.sh restore [文件|latest] 用备份覆盖当前库(覆盖前先自动备份)
# ./scripts/db.sh dump [输出文件] 导出内容快照(教材/章节/知识点/课程/题库),可提交进 git
# ./scripts/db.sh dump <输出文件> --full 同上,但含账号/答题记录/错题本,可整库还原
# ./scripts/db.sh load [快照文件] 把内容快照灌回当前库
# ./scripts/db.sh path 数据库文件位置
#
# 为什么要 dump:.gitignore 里 data/*.db 让库文件从来就没进过远端仓库,
# 库一重置,章节和题目就没了。把内容表导成 SQL 文本提交后,
# 远端仓库里始终有一份可恢复的数据库快照(且不含账号、答题记录等个人数据)。
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PY="$ROOT_DIR/backend/.venv/bin/python"
if [ ! -x "$PY" ]; then
echo "[db] 未找到 backend/.venv,请先执行 ./scripts/init.sh" >&2
exit 1
fi
cd "$ROOT_DIR/backend"
exec "$PY" -m dbtool "$@"