Last active
November 12, 2020 00:39
-
-
Save djdembeck/6442a20d26e8ed0b9fd133cb5443efe9 to your computer and use it in GitHub Desktop.
Linux Plex SQLite DB repair script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# quick script to perform actions from https://support.plex.tv/articles/201100678-repair-a-corrupt-database/ | |
# MUST BE RUN FROM INSIDE "Library/Application Support/Plex Media Server/Plug-in Support/Databases" | |
# Don't forget to check user permissions of the databases after this script runs. Wrong user permissions will cause "Starting Plex Media Server" loop | |
# Only proceed if sqlite3 is found | |
if [[ -z $(which sqlite3) ]]; then | |
echo "ERROR: sqlite3 is not installed, exiting" | |
exit 1 | |
fi | |
# Run repair on blobs.db. If main db has corruption, blobs probably does too, so run both. | |
# Backup stored as .original extension | |
if [[ -s com.plexapp.plugins.library.blobs.db ]]; then | |
cp com.plexapp.plugins.library.blobs.db com.plexapp.plugins.library.blobs.db.original | |
sqlite3 com.plexapp.plugins.library.blobs.db "DROP index 'index_title_sort_naturalsort'" | |
sqlite3 com.plexapp.plugins.library.blobs.db "DELETE from schema_migrations where version='20180501000000'" | |
sqlite3 com.plexapp.plugins.library.blobs.db "PRAGMA integrity_check" | |
sqlite3 com.plexapp.plugins.library.blobs.db .dump > dump.sql | |
rm -v com.plexapp.plugins.library.blobs.db | |
sqlite3 com.plexapp.plugins.library.blobs.db < dump.sql | |
rm dump.sql | |
fi | |
# Run repair on main library.db. | |
# Backup stored as .original extension | |
if [[ -s com.plexapp.plugins.library.db ]]; then | |
cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original | |
sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'" | |
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'" | |
sqlite3 com.plexapp.plugins.library.db "PRAGMA integrity_check" | |
sqlite3 com.plexapp.plugins.library.db .dump > dump.sql | |
rm -v com.plexapp.plugins.library.db | |
sqlite3 com.plexapp.plugins.library.db < dump.sql | |
rm dump.sql | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment