Skip to content

Instantly share code, notes, and snippets.

@rostislavzz
Last active April 13, 2022 05:18
Show Gist options
  • Save rostislavzz/7aa7a1a049031c1ed2c168cdeac85c3d to your computer and use it in GitHub Desktop.
Save rostislavzz/7aa7a1a049031c1ed2c168cdeac85c3d to your computer and use it in GitHub Desktop.
Scripts for optimize Plex database to use with Docker container https://github.com/linuxserver/docker-plex. Place "optimize-db.sh" to "/config", and "install-cron-sqlite.sh" to "/config/custom-cont-init.d".
#!/bin/bash
apt-get update && \
apt-get install -y cron sqlite3
apt-get clean
if [ -z "$(crontab -l | grep 'optimize-db.sh')" ]; then
crontab -l | { cat; echo "0 0 1 * * /config/optimize-db.sh 2>&1"; } | crontab -
fi
#!/bin/bash
s6-svc -d /var/run/s6/services/plex/
cd "/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"
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 .dump > dump.sql
rm com.plexapp.plugins.library.db
rm com.plexapp.plugins.library.db-shm
rm com.plexapp.plugins.library.db-wal
sqlite3 com.plexapp.plugins.library.db < dump.sql
chown abc:abc com.plexapp.plugins.library.db
s6-svc -u /var/run/s6/services/plex/
@nwithan8
Copy link

nwithan8 commented Apr 13, 2022

Note, you can't download or run these scripts via the normal terminal, since their paths anticipate the path as seen by the Docker container. You'll need to console into the Docker container to manage them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment