Fix script crash: remove set -u, handle python exit safely
- set -euo → set -eo (unset var no longer fatal) - Python snapshot lookup: catch exceptions, use || true - Prevents script exit on empty PBS responses Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
# Phase 8: 검증 + 결과 출력
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
set -eo pipefail
|
||||
|
||||
# ============================================================
|
||||
# 명령행 인자 처리
|
||||
@@ -483,21 +483,24 @@ PYEOF
|
||||
-H "CSRFPreventionToken: ${PBS_CSRF}" > /tmp/pbs_snapshots.json
|
||||
|
||||
local LATEST_SNAPSHOT
|
||||
LATEST_SNAPSHOT=$(python3 << 'PYEOF'
|
||||
LATEST_SNAPSHOT=$(python3 << 'PYEOF' || true
|
||||
import json, sys
|
||||
from datetime import datetime
|
||||
with open('/tmp/pbs_snapshots.json', 'r') as f:
|
||||
try:
|
||||
with open('/tmp/pbs_snapshots.json', 'r') as f:
|
||||
data = json.load(f)
|
||||
snapshots = data.get("data", [])
|
||||
if not snapshots:
|
||||
sys.exit(1)
|
||||
latest = max(snapshots, key=lambda x: x.get("backup-time", 0))
|
||||
backup_time = latest.get("backup-time", 0)
|
||||
print(datetime.utcfromtimestamp(backup_time).strftime("%Y-%m-%dT%H:%M:%SZ"))
|
||||
snapshots = data.get("data", [])
|
||||
if not snapshots:
|
||||
sys.exit(0)
|
||||
latest = max(snapshots, key=lambda x: x.get("backup-time", 0))
|
||||
backup_time = latest.get("backup-time", 0)
|
||||
print(datetime.utcfromtimestamp(backup_time).strftime("%Y-%m-%dT%H:%M:%SZ"))
|
||||
except Exception:
|
||||
pass
|
||||
PYEOF
|
||||
)
|
||||
|
||||
if [ -z "$LATEST_SNAPSHOT" ]; then
|
||||
if [ -z "${LATEST_SNAPSHOT:-}" ]; then
|
||||
print_err "백업을 찾을 수 없습니다."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user