Files
IOT_SIM/deploy/restore.sh
T
xuyueandClaude Opus 5.5 982b1297aa
CI/CD / test (push) Canceled after 0s
CI/CD / deploy (push) Canceled after 0s
试用前准备:全班模拟压测、评分并发 6→16、手动备份与恢复
- test/classroom.ts:45 个虚拟学生走一遍登录、运行、自测、提交,统计每个环节等多久
- 评分并发可配置(SIM_GRADE_CONCURRENCY,默认 16),提交队列同时评的份数跟着走;
  2 核实测项目 8 任务 3 全班自测从约 4 分钟降到约 1.5 分钟
- 检查的默认等待 2 秒→5 秒,机器忙时不再误判正确的程序
- 删除学生时删除他的数据库(编号会重新用给新学生)
- deploy/backup.sh、deploy/restore.sh:手动备份到宿主机 backups/,恢复前先备份

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 20:08:31 +08:00

26 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 在服务器上执行:用 deploy/backup.sh 做的备份替换平台现在的全部数据。
# 替换前先自动备份现在的数据(恢复错了还能换回来);恢复时平台停止约十几秒,正在运行的学生程序会结束。
# 用法:deploy/restore.sh backups/<日期时间>
set -euo pipefail
cd "$(dirname "$0")/.."
dir=${1:?用法:deploy/restore.sh backups/<日期时间>}
if [[ ! -f $dir/iot-sim.db ]]; then
echo "$dir 不是备份目录(里面应该有 iot-sim.db)"
exit 1
fi
read -r -p "用 $dir 替换平台现在的全部数据?现在的数据会先备份。[y/N] " answer
[[ $answer == y || $answer == Y ]] || exit 1
echo "== 备份现在的数据"
deploy/backup.sh
echo "== 停止平台、替换数据"
docker compose stop app
# 旧库的 -wal、-shm 文件一定要删掉,否则会被当成新库的未写完的日志,把恢复的库弄坏
docker compose run --rm --no-deps -T -v "$(realpath "$dir"):/restore:ro" app \
sh -c 'rm -rf /data/iot-sim.db /data/iot-sim.db-wal /data/iot-sim.db-shm /data/databases && cp -r /restore/. /data/'
echo "== 启动平台"
docker compose up -d app
echo "已恢复到 $dir"