Skip to content

Instantly share code, notes, and snippets.

@ConorShore
Created April 4, 2023 09:21
Show Gist options
  • Save ConorShore/7ef38804c89f5c397b449a1d8d793e14 to your computer and use it in GitHub Desktop.
Save ConorShore/7ef38804c89f5c397b449a1d8d793e14 to your computer and use it in GitHub Desktop.
Cut plex data from one user to another
#!/bin/bash
sudo apt install sqlite3
echo "Please enter the path to your database, should look something like this"
echo "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"
read -p "Full path to database [/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/]: " DB_LOC
DB_LOC=${DB_LOC:-/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/}
FULL_DB_LOC=${DB_LOC}com.plexapp.plugins.library.db
sudo cp "${FULL_DB_LOC}" "${FULL_DB_LOC}.backup"
sqlite3 "${FULL_DB_LOC}" 'SELECT id, name FROM accounts;'
read -p "User id to copy info FROM: " FROM_ID
read -p "User id to copy info TO: " TO_ID
sqlite3 "${FULL_DB_LOC}" "UPDATE metadata_item_views SET account_id=${TO_ID} WHERE account_id=${FROM_ID}; UPDATE metadata_item_settings SET account_id=${TO_ID} WHERE account_id=${FROM_ID}; UPDATE statistics_media SET account_id=${TO_ID} WHERE account_id=${FROM_ID}; UPDATE statistics_bandwidth SET account_id=${TO_ID} WHERE account_id=${FROM_ID}; UPDATE media_part_settings SET account_id=${TO_ID} WHERE account_id=${FROM_ID};"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment