Add timeout and better error messages to connection test

The connection test now:
- Has a 30-second timeout to prevent indefinite hanging
- Shows "This may take up to 30 seconds..." message
- Differentiates between timeout (unreachable) and auth errors
- Provides specific troubleshooting steps based on error type
- Displays helpful commands for diagnosing connection issues

This fixes the issue where the script would hang indefinitely
when the PBS server was unreachable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zaphod-black 2025-11-01 16:37:11 -05:00
parent 8e958159d1
commit fde5a9edf2

View file

@ -486,16 +486,41 @@ create_encryption_key() {
# Test connection to PBS
test_connection() {
log "Testing connection to PBS server..."
info "This may take up to 30 seconds..."
export PBS_REPOSITORY="$PBS_REPOSITORY"
export PBS_PASSWORD="$PBS_PASSWORD"
if proxmox-backup-client snapshot list &>/dev/null; then
# Use timeout to prevent hanging (30 seconds max)
if timeout 30 proxmox-backup-client snapshot list &>/dev/null; then
log "Connection test successful!"
return 0
else
local exit_code=$?
echo
error "Connection test failed"
error "Please verify your server details and credentials"
if [ $exit_code -eq 124 ]; then
error "Connection timed out after 30 seconds"
error "Possible issues:"
error " - PBS server is unreachable (check IP/hostname)"
error " - Firewall blocking port ${PBS_PORT}"
error " - Network connectivity issues"
else
error "Authentication or configuration error"
error "Possible issues:"
error " - Invalid credentials (username/password/token)"
error " - Datastore does not exist on server"
error " - User lacks permissions for the datastore"
fi
echo
info "Troubleshooting:"
echo " 1. Verify server is reachable: ping ${PBS_SERVER}"
echo " 2. Test HTTPS connection: curl -k https://${PBS_SERVER}:${PBS_PORT}"
echo " 3. Verify credentials in PBS web interface"
echo " 4. Check datastore name matches exactly"
return 1
fi
}