Fix: VM selection by list number instead of raw backup ID
Users were entering list number (e.g. 4) but script expected backup ID (e.g. 201). Now maps selection number to actual VM ID via temp file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -397,6 +397,8 @@ vm_groups = [g for g in groups if g.get("backup-type") == "vm"]
|
|||||||
|
|
||||||
if vm_groups:
|
if vm_groups:
|
||||||
print("\033[1;36m=== VM 백업 목록 ===\033[0m")
|
print("\033[1;36m=== VM 백업 목록 ===\033[0m")
|
||||||
|
# VM ID 목록을 파일로 저장 (번호→ID 매핑)
|
||||||
|
id_list = []
|
||||||
for i, group in enumerate(vm_groups, 1):
|
for i, group in enumerate(vm_groups, 1):
|
||||||
bid = group.get("backup-id", "N/A")
|
bid = group.get("backup-id", "N/A")
|
||||||
count = group.get("backup-count", 0)
|
count = group.get("backup-count", 0)
|
||||||
@@ -418,12 +420,19 @@ if vm_groups:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
id_list.append(str(bid))
|
||||||
last_str = datetime.fromtimestamp(last).strftime("%Y-%m-%d %H:%M") if last > 0 else "N/A"
|
last_str = datetime.fromtimestamp(last).strftime("%Y-%m-%d %H:%M") if last > 0 else "N/A"
|
||||||
print(f" {i}. VM {bid:<6} - {count}개 백업 (최근: {last_str})")
|
print(f" {i}. VM {bid:<6} - {count}개 백업 (최근: {last_str})")
|
||||||
if comment:
|
if comment:
|
||||||
print(f" \033[0;90m└─ {comment}\033[0m")
|
print(f" \033[0;90m└─ {comment}\033[0m")
|
||||||
|
|
||||||
|
# 번호→ID 매핑 파일 저장
|
||||||
|
with open('/tmp/pbs_vm_ids.txt', 'w') as f:
|
||||||
|
f.write('\n'.join(id_list))
|
||||||
else:
|
else:
|
||||||
print("VM 백업이 없습니다.")
|
print("VM 백업이 없습니다.")
|
||||||
|
with open('/tmp/pbs_vm_ids.txt', 'w') as f:
|
||||||
|
f.write('')
|
||||||
PYEOF
|
PYEOF
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@@ -434,8 +443,20 @@ PYEOF
|
|||||||
TEMPLATE_VMID="$ARGS_VM_ID"
|
TEMPLATE_VMID="$ARGS_VM_ID"
|
||||||
print_ok "VM 백업 자동 선택: $TEMPLATE_VMID"
|
print_ok "VM 백업 자동 선택: $TEMPLATE_VMID"
|
||||||
else
|
else
|
||||||
echo -ne "${CYAN}복원할 VM 백업 ID (숫자, Enter로 건너뛰기): ${NC}"
|
echo -ne "${CYAN}복원할 번호 선택 (1~7, Enter로 건너뛰기): ${NC}"
|
||||||
read -r TEMPLATE_VMID </dev/tty || true
|
read -r VM_CHOICE </dev/tty || true
|
||||||
|
if [ -n "${VM_CHOICE:-}" ]; then
|
||||||
|
# 번호 → 실제 VM ID 변환
|
||||||
|
TEMPLATE_VMID=$(sed -n "${VM_CHOICE}p" /tmp/pbs_vm_ids.txt 2>/dev/null || echo "")
|
||||||
|
if [ -z "$TEMPLATE_VMID" ]; then
|
||||||
|
print_err "잘못된 번호입니다: $VM_CHOICE"
|
||||||
|
TEMPLATE_VMID=""
|
||||||
|
else
|
||||||
|
print_ok "선택: VM $TEMPLATE_VMID"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
TEMPLATE_VMID=""
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${TEMPLATE_VMID:-}" ]; then
|
if [ -z "${TEMPLATE_VMID:-}" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user