joy-cli/scripts/manhuang/purge-codex-pool.sh
feibisi 4bc732312b ops(manhuang): 清理无用 Codex 号池脚本与空仓语义
归档后清空 scout 工作池;health total=0 显示「空仓待采购」;
purge-codex-pool.sh 可复用。旧号在 scout:~/data/codex-tokens-archive/。
2026-07-13 09:53:26 +08:00

45 lines
1.8 KiB
Bash
Executable file
Raw Permalink 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
# 清理 scout 无用 Codex 号池:归档后清空工作目录(保留 api-endpoints
# 用法: bash scripts/manhuang/purge-codex-pool.sh [--yes]
set -euo pipefail
if [[ "${1:-}" != "--yes" ]]; then
echo "将归档并清空 scout:~/data/codex-tokens 下所有账号批次。"
echo "保留 api-endpoints.json归档目录 codex-tokens-archive/purged-*"
echo "确认执行: $0 --yes"
exit 1
fi
# 实际清理逻辑与 2026-07-13 会话一致ssh 归档 tar + rm batches
exec ssh -o BatchMode=yes scout 'bash -s' <<'REMOTE'
set -euo pipefail
ROOT="$HOME/data/codex-tokens"
ARCH_ROOT="$HOME/data/codex-tokens-archive"
STAMP=$(date +%Y%m%d-%H%M%S)
DEST="$ARCH_ROOT/purged-$STAMP"
mkdir -p "$DEST" "$ROOT"
cd "$ROOT"
mapfile -t ITEMS < <(find . -maxdepth 1 \( -type d -o -name "*.zip" \) ! -name "." | sed "s|^\./||" | sort)
if [[ ${#ITEMS[@]} -eq 0 ]]; then
echo "[purge] nothing to archive"; exit 0
fi
tar -czf "$DEST/codex-tokens-batch.tar.gz" "${ITEMS[@]}"
sha256sum "$DEST/codex-tokens-batch.tar.gz" | tee "$DEST/SHA256.txt"
for it in "${ITEMS[@]}"; do rm -rf "$ROOT/$it"; done
printf "[]\n" > "$ROOT/alive-pool.json"
python3 - <<PY
import json
from datetime import datetime, timezone
from pathlib import Path
root = Path.home() / "data" / "codex-tokens"
summary = {
"timestamp": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"total": 0, "scanned": 0, "quick": False, "elapsed_sec": 0,
"counts": {"has_quota": 0, "exhausted": 0, "dead": 0, "error": 0},
"rates": {"has_quota_pct": 0.0, "alive_pct": 0.0},
"refresh": {}, "files": {}, "errors": [],
"note": "purged; await new procurement",
}
(root / "health-status.json").write_text(json.dumps(summary, ensure_ascii=False, indent=2) + "\n")
print("archive", "$DEST")
print("remaining", sorted(p.name for p in root.iterdir()))
PY
REMOTE