Home Page
  • December 10, 2024, 06:51:00 pm *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Official site launch very soon, hurrah!


Author Topic: Plex recover posters & art from previous backup  (Read 2740 times)

Dakusan

  • Programmer Person
  • Administrator
  • Hero Member
  • *****
  • Posts: 551
    • View Profile
    • Dakusan's Domain
Plex recover posters & art from previous backup
« on: October 02, 2024, 03:18:20 am »


My Plex server decided to go through my database and screw with all the posters and art, so I made the below script which can be used to recover them. You should only use this if doing a full revert to backup is not a viable option. Do also note that if you have refreshed the metadata on any tv series since the backup, it could cause issues with the episode posters.




#Run the following commands as root
sudo su

#User variables
SERVICE_NAME='plexmediaserver'
BACKUP_LOCATION='/ROOT_BACKUP_LOCATION/'
PLEX_USER='plex'

#Derived variables (Slashes at end of directory paths are required)
SQLITE3_PATH="/usr/lib/$SERVICE_NAME/Plex SQLite"
DB_PATH="/var/lib/$SERVICE_NAME/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db"
IMG_PATH="/var/lib/$SERVICE_NAME/Library/Application Support/Plex Media Server/Metadata/"
CACHE_PATH="/var/lib/$SERVICE_NAME/Library/Application Support/Plex Media Server/Cache/PhotoTranscoder/"

#Stop the plex service until we have updated everything
echo "Stopping Plex"
systemctl stop "$SERVICE_NAME"

#Set the (user_thumb_url, user_art_url, and updated_at) from the old database in the new database.
#The updated_at is required to match the cached images
echo "Updating database"
sudo -u "$PLEX_USER" "$SQLITE3_PATH" "$DB_PATH" -cmd "ATTACH DATABASE '$BACKUP_LOCATION$DB_PATH' as OLDDB" "
UPDATE
 metadata_items AS NMDI
SET
 user_thumb_url=OMDI.user_thumb_url,
 user_art_url=OMDI.user_art_url,
 updated_at=OMDI.updated_at
FROM
   OLDDB.metadata_items AS OMDI
WHERE
   NMDI.id=OMDI.id
"

#Copy the posters and art from the old directory to the new directory
echo "Copying posters"
cd "$BACKUP_LOCATION$IMG_PATH"
find -type d \( -name "art" -o -name "posters" \) | xargs -n100 bash -c 'rsync -a --relative "$@" "'"$IMG_PATH"'"' _

#Copy the cached images over
echo "Copying cache"
rsync -a "$BACKUP_LOCATION$CACHE_PATH" "$CACHE_PATH"

#Restart plex
echo "Starting Plex"
systemctl start "$SERVICE_NAME"

Logged

Dakusan

  • Programmer Person
  • Administrator
  • Hero Member
  • *****
  • Posts: 551
    • View Profile
    • Dakusan's Domain
Re: Plex recover posters & art from previous backup
« Reply #1 on: October 16, 2024, 11:51:56 pm »

Adding a solution to my problem where movie posters kept disappearing in between plex server reboots.
For some reason it was storing the movie poster metadata in "Metadata/*/*/*/Upload" and it expected them in "Metadata/*/*/*/Contents/_combined/". Ran the following command in "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Metadata" to fix the missing posters:
Code: [Select]
IFS=$'\n'; for i in `ls */*/* -d`; do cd "$i"; if [ -d "Uploads" ]; then echo "$i"; rsync -a Uploads/ Contents/_combined/; fi; cd -; done
Logged