diff --git a/Jellyfin_Fix_and_Scan.sh b/Jellyfin_Fix_and_Scan.sh index 5412887..5189090 100644 --- a/Jellyfin_Fix_and_Scan.sh +++ b/Jellyfin_Fix_and_Scan.sh @@ -43,6 +43,38 @@ else echo "No error found in journal." fi +greenecho "Double checking the DB integrity" + +# Run the SQLite integrity check and capture the output +output=$(sudo sqlite3 /var/lib/jellyfin/data/library.db "PRAGMA integrity_check;") + +# Check if the output indicates that the database is OK +if [[ "$output" != "ok" ]]; then + + echo "Database integrity check failed: $output" + # Stop Jellyfin + sudo systemctl stop jellyfin + yellowecho "Waiting 60 seconds for jellyfin to stop" + sleep 60 + # Remove bad DB + rm -f /var/lib/jellyfin/data/library.db + rm -f /var/lib/jellyfin/data/library.db* + # Replace bad DB + cp "/path/to/backups/Jellyfin/library.db.master" "/var/lib/jellyfin/data/library.db" + # Fix Permissions + /usr/bin/chown jellyfin:jellyfin "/var/lib/jellyfin/data/library.db" + /usr/bin/chmod 600 "/var/lib/jellyfin/data/library.db" + greenecho "Database file replaced with backup." + greenecho "Starting Jellyfin." + yellowecho "Waiting 60 seconds so JF can start." + # Start Jellyfin + sudo systemctl start jellyfin + sleep 60 +else + + greenecho "Database integrity is OK." +fi + #Even if no DB curruption, update the live TV, why not? # Trigger Live TV / M3U scan