diff --git a/plex/backup-plex.sh b/plex/backup-plex.sh index f2da595..bf1244b 100755 --- a/plex/backup-plex.sh +++ b/plex/backup-plex.sh @@ -202,12 +202,12 @@ send_notification() { [ "$status" == "error" ] && tags="${tags},errors" [ "$status" == "warning" ] && tags="${tags},warnings" - # Enhanced message with additional context - local enhanced_message="$message\n\nHost: $hostname\nTimestamp: $(date '+%Y-%m-%d %H:%M:%S')" + # Clean message without newlines or timestamps for webhook + local webhook_message="$message" curl -s \ -H "tags:${tags}" \ - -d "$enhanced_message" \ + -d "$webhook_message" \ "$WEBHOOK_URL" 2>/dev/null || log_warning "Failed to send webhook notification" fi @@ -227,6 +227,25 @@ send_notification() { fi } +# Format backed up files list for notifications +format_backed_up_files() { + local files=("$@") + local count=${#files[@]} + + if [ $count -eq 0 ]; then + echo "no files" + elif [ $count -eq 1 ]; then + echo "${files[0]}" + elif [ $count -eq 2 ]; then + echo "${files[0]} and ${files[1]}" + else + local last_file="${files[-1]}" + local other_files=("${files[@]:0:$((count-1))}") + local other_files_str=$(IFS=', '; echo "${other_files[*]}") + echo "${other_files_str}, and ${last_file}" + fi +} + # Enhanced checksum calculation with caching calculate_checksum() { local file="$1" @@ -900,6 +919,7 @@ main() { local backup_errors=0 local files_backed_up=0 + local backed_up_files=() # Array to track successfully backed up files local BACKUP_PATH="${BACKUP_ROOT}" # Ensure backup root directory exists @@ -970,6 +990,13 @@ main() { if verify_backup "$file" "$backup_file"; then log_success "Verified: $(basename "$file")" files_backed_up=$((files_backed_up + 1)) + # Add friendly filename to backed up files list + case "$(basename "$file")" in + "com.plexapp.plugins.library.db") backed_up_files+=("library.db") ;; + "com.plexapp.plugins.library.blobs.db") backed_up_files+=("blobs.db") ;; + "Preferences.xml") backed_up_files+=("Preferences.xml") ;; + *) backed_up_files+=("$(basename "$file")") ;; + esac else log_error "Verification failed: $(basename "$file")" backup_errors=$((backup_errors + 1)) @@ -1118,7 +1145,8 @@ main() { fi # Send notification - send_notification "Backup Completed" "Successfully backed up $files_backed_up files" "success" + local files_list=$(format_backed_up_files "${backed_up_files[@]}") + send_notification "Backup Completed" "Successfully backed up $files_list" "success" else log_message "No files needed backup" fi @@ -1148,7 +1176,8 @@ main() { exit 1 else log_success "Enhanced backup completed successfully" - send_notification "Backup Success" "All $files_backed_up files backed up successfully in ${total_time}s" "success" + local files_list=$(format_backed_up_files "${backed_up_files[@]}") + send_notification "Backup Success" "$files_list backed up successfully in ${total_time}s" "success" fi }