Feature: Automatic authentication test for all targets at startup
Added automatic connection testing when the script starts up. All
configured backup targets are now tested immediately, giving users
instant feedback about which targets are accessible.
NEW FUNCTIONS:
- quick_test_target() (lines 127-145)
- Lightweight auth test for a single target
- 5 second timeout for quick feedback
- Runs in subshell to avoid polluting environment
- Returns 0 on success, 1 on failure
- test_all_targets() (lines 148-176)
- Tests all configured targets
- Displays formatted status for each:
- "✓ Connected" - Authentication successful
- "✗ Failed" - Cannot authenticate
- Shows warning if any targets fail
- Suggests using "Edit target" option to fix issues
INTEGRATION:
- Called automatically after show_targets_list() at startup
- Only runs if targets exist
- Minimal performance impact (5s max per target)
- Non-blocking - script continues regardless of results
USER EXPERIENCE:
Before: User had to manually test each target or discover issues when backups fail
After: Immediate visual feedback on all target statuses at startup
Example output:
════════════════════════════════════════
Testing Backup Target Connections
════════════════════════════════════════
default: ✗ Failed
offsite: ✓ Connected
[WARN] Some targets failed connection test
[INFO] Use option 3 (Edit target) to fix connection issues
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
10534da9a6
commit
95e937b964
2 changed files with 62 additions and 0 deletions
|
|
@ -119,6 +119,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Manual backups always include block device even on non-Sunday
|
||||
- Script version bumped to 1.1.0 for multi-target support
|
||||
|
||||
### Added
|
||||
- **Automatic connection testing at startup**
|
||||
- All configured targets are automatically tested when script starts
|
||||
- Quick authentication check (5 second timeout per target)
|
||||
- Shows connection status: ✓ Connected or ✗ Failed
|
||||
- Helps identify configuration issues before running backups
|
||||
- Warns user if any targets have connection problems
|
||||
- Runs in subshell to avoid environment pollution
|
||||
|
||||
### Changed
|
||||
- **Improved menu flow for viewing target details**
|
||||
- "View target details" moved from main menu option 6 to sub-menu under "List all backup targets"
|
||||
|
|
|
|||
|
|
@ -123,6 +123,58 @@ resolve_target_input() {
|
|||
return 0
|
||||
}
|
||||
|
||||
# Quick authentication test for a single target (minimal output)
|
||||
quick_test_target() {
|
||||
local target_name="$1"
|
||||
local config_file="$(get_target_config_path "$target_name")"
|
||||
|
||||
if [ ! -f "$config_file" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Source config in subshell to avoid polluting environment
|
||||
(
|
||||
source "$config_file"
|
||||
export PBS_REPOSITORY
|
||||
export PBS_PASSWORD
|
||||
|
||||
# Quick auth test - just try to login
|
||||
echo "y" | timeout 5 proxmox-backup-client login >/dev/null 2>&1
|
||||
)
|
||||
return $?
|
||||
}
|
||||
|
||||
# Test all configured targets and display status
|
||||
test_all_targets() {
|
||||
if ! list_targets >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "════════════════════════════════════════"
|
||||
echo " Testing Backup Target Connections"
|
||||
echo "════════════════════════════════════════"
|
||||
echo
|
||||
|
||||
local all_ok=true
|
||||
while IFS= read -r target; do
|
||||
printf " %-20s " "$target:"
|
||||
|
||||
if quick_test_target "$target"; then
|
||||
echo "✓ Connected"
|
||||
else
|
||||
echo "✗ Failed"
|
||||
all_ok=false
|
||||
fi
|
||||
done < <(list_targets)
|
||||
|
||||
echo
|
||||
if [ "$all_ok" = false ]; then
|
||||
warn "Some targets failed connection test"
|
||||
info "Use option 3 (Edit target) to fix connection issues"
|
||||
fi
|
||||
}
|
||||
|
||||
migrate_legacy_config() {
|
||||
# Check if old single-target config exists
|
||||
if [ -f "$CONFIG_DIR/config" ] && [ ! -d "$TARGETS_DIR" ]; then
|
||||
|
|
@ -1965,6 +2017,7 @@ main() {
|
|||
# Check if any targets exist
|
||||
if list_targets >/dev/null 2>&1; then
|
||||
show_targets_list
|
||||
test_all_targets
|
||||
|
||||
# Main menu loop
|
||||
while true; do
|
||||
|
|
|
|||
Loading…
Reference in a new issue