Sign inSign up

nowsci/plex-db-sync

By nowsci

•Updated 24 days ago

Synchronizes the watched status between two Plex servers for all users without the need for tokens.

Image
12

100K+

nowsci/plex-db-sync repository overview

⁠plex-db-sync

Synchronizes the database watched status between two Plex servers. This includes watched times, and works for all users on the system without the need for tokens.

⁠Usage

To use the script, you will need to be able to access the databases of both Plex servers from one place. This can be done with programs like sshfs. For instance, you could run the script like this:

wget https://raw.githubusercontent.com/Fmstrat/plex-db-sync/master/plex-db-sync
apt-get install sshfs sqlite3
mkdir -p /mnt/sshfs
sshfs -o allow_other,IdentityFile=/keys/serverkey -p 22 \
	[email protected]:"/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/" \
	/mnt/sshfs
chmod +x plex-db-sync
./plex-db-sync \
	--plex-db-1 "/mnt/sshfs/com.plexapp.plugins.library.db" \
	--plex-start-1 "ssh -oStrictHostKeyChecking=no -i /keys/serverkey [email protected] service plexmediaserver start" \
	--plex-stop-1 "ssh -oStrictHostKeyChecking=no -i /keys/serverkey [email protected] service plexmediaserver stop" \
      	--plex-db-2 "/data/docker/containers/plex/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" \
	--plex-start-2 "service plexmediaserver start" \
	--plex-stop-2 "service plexmediaserver stop" \

The script stops and starts Plex Media Server for a very short period of time to make updates. Due to buffering and reconnections, this does not impact clients when playing, except perhaps on the first run when a very large number of records are being updated.

⁠Docker

The following example is for docker-compose. It assumes you are running one Plex server locally, and another remotely.

version: '2'

services:

  plex-db-sync:
    image: nowsci/plex-db-sync
    container_name: plex-db-sync
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./plex-db-sync/sshkey:/sshkey
      - /docker/plex/Library/Application Support/Plex Media Server/Plug-in Support/Databases/:/mnt/DB2
    cap_add:
      - SYS_ADMIN
    devices:
      - /dev/fuse
    security_opt:
      - apparmor:unconfined
    environment:
      - CRON=0 4 * * *
      - S1_SSH_KEY=/sshkey
      - S1_SSH_USER=root
      - S1_SSH_HOST=hostname
      - S1_SSH_PORT=22
      - S1_SSH_PATH=/docker/plex/Library/Application Support/Plex Media Server/Plug-in Support/Databases
      - S1_START=ssh -oStrictHostKeyChecking=no -i /sshkey root@hostname 'cd /docker; docker-compose up -d plex'
      - S1_STOP=ssh -oStrictHostKeyChecking=no -i /sshkey root@hostname 'cd /docker; docker-compose stop plex'
      - S2_DB_PATH=/mnt/DB2
      - S2_START=cd /docker; docker-compose up -d plex
      - S2_STOP=cd /docker; docker-compose stop plex
    restart: always

⁠Options

Command LineDocker VariableDescription
--backup <true/false>BACKUPCreate a backup of the DB before running any SQL.
--debug <true/false>DEBUGPrint debug output.
--dry-run <true/false>DRYRUNDon't apply changes to the DB.
--plex-db-(1/2)S(1/2)_DB_PATHLocation of the server's DB. For the script, this is the file itself, for docker, it is the path.
--plex-start-(1/2)S(1/2)_STARTThe command to start the Plex server.
--plex-stop-(1/2)S(1/2)_STOPThe command to stop the Plex server.
--nocomparedb <true/false>n/aDon't compare version db of Plex server.
n/aCRONA string that defines when the script should run in crond (Default is 4AM).
n/aINITIALRUNRun at start prior to starting cron.
n/aS(1/2)_SSH_KEYThe SSH identity file.
n/aS(1/2)_SSH_USERThe SSH user.
n/aS(1/2)_SSH_HOSTThe SSH host.
n/aS(1/2)_SSH_PORTThe SSH port.
n/aS(1/2)_SSH_PATHPath to the database file on the SSH server.

Tag summary

Content type

Image

Digest

sha256:0b220015c…

Size

9.6 MB

Last updated

24 days ago

docker pull nowsci/plex-db-sync