check_repo_stats update

main
Anthony 2025-06-03 02:15:49 +08:00
parent b4b2240fac
commit 0b3465f79e
1 changed files with 62 additions and 3 deletions

View File

@ -123,9 +123,68 @@ validate_repository() {
if [ "$(find "$BACKUP_REPO_PATH" -mindepth 1 2>/dev/null | wc -l)" -gt 0 ]; then
log_message "Repository directory contains files. Checking if it's a valid Restic repository..."
# Test if repository is accessible
if ! restic snapshots &>/dev/null; then
log_message "ERROR: Repository directory exists but is not a valid Restic repository."
# Check if this looks like a Restic repository structure
if [ -f "$BACKUP_REPO_PATH/config" ] && [ -d "$BACKUP_REPO_PATH/data" ]; then
log_message "Detected valid Restic repository structure. Testing access..."
# First try to unlock in case there are stale locks
log_message "Checking for stale locks before testing access..."
restic unlock 2>/dev/null || true
# Test if repository is accessible with current password
if restic snapshots &>/dev/null; then
log_message "Repository access successful with current password."
else
log_message "ERROR: Repository structure is valid but access failed."
log_message "This usually indicates a password mismatch."
log_message "Repository config file permissions: $(ls -la "$BACKUP_REPO_PATH/config" 2>/dev/null)"
log_message "Trying to unlock repository first..."
# Try unlocking again with verbose output
if ! restic unlock 2>/dev/null; then
log_message "Warning: Could not unlock repository, but continuing..."
fi
# Try accessing again after unlock
if restic snapshots &>/dev/null; then
log_message "Repository access successful after unlock."
else
log_message "ERROR: Repository access still failed after unlock."
log_message "Please verify the password in $PASSWORD_FILE matches the repository."
# Show more diagnostic information
log_message "Diagnostic information:"
log_message "- Repository path: $BACKUP_REPO_PATH"
log_message "- Password file: $PASSWORD_FILE"
log_message "- Password file exists: $([ -f "$PASSWORD_FILE" ] && echo 'Yes' || echo 'No')"
log_message "- Password file readable: $([ -r "$PASSWORD_FILE" ] && echo 'Yes' || echo 'No')"
log_message "- Current user: $(whoami) (UID: $EUID)"
# Try one more time with the working script's simple approach
log_message "Attempting simple password access method..."
if [ -f "$PASSWORD_FILE" ]; then
simple_password=$(cat "$PASSWORD_FILE" 2>/dev/null || echo "")
if [ -n "$simple_password" ]; then
export RESTIC_PASSWORD="$simple_password"
if restic snapshots &>/dev/null; then
log_message "SUCCESS: Repository accessible with simple password method."
else
log_message "ERROR: Repository still not accessible. Password mismatch likely."
exit 1
fi
else
log_message "ERROR: Could not read password from file."
exit 1
fi
else
log_message "ERROR: Password file not found."
exit 1
fi
fi
fi
else
# Directory has files but doesn't look like Restic repository
log_message "ERROR: Repository directory contains files but is not a valid Restic repository structure."
log_message "Repository contents: $(ls -la "$BACKUP_REPO_PATH" 2>/dev/null | head -10)"
exit 1
fi