Skip to content

Instantly share code, notes, and snippets.

@stephanGarland
Created September 6, 2021 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephanGarland/9a7370540a11191660dd05041ee1df80 to your computer and use it in GitHub Desktop.
Save stephanGarland/9a7370540a11191660dd05041ee1df80 to your computer and use it in GitHub Desktop.
Fix Plex database - the DB frequently gets borked for one reason or another; this backs up your existing one and copies over the latest backup
#!/usr/bin/env bash
# Replace the directory on L7 with your actual location
echo "Stopping Plex"
docker stop plex
cd "/mnt/nvme_plex/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases"
existing="com.plexapp.plugins.library.db"
echo "Backing up $existing to $existing.bak"
cp $existing $existing.bak
backup=$(find . -regex ".*library\.db-[0-9]+.*" -print0 | xargs -r -0 ls -1 -t | head -1)
echo "Copying $backup to $existing"
cp $backup com.plexapp.plugins.library.db
echo "Deleting metadata"
rm com.plexapp.plugins.library.db-shm
rm com.plexapp.plugins.library.db-wal
echo "Restarting Plex"
docker start plex
echo "All done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment