Sign inSign up

timekills/plex-db-sync-plexguide

By timekills

•Updated almost 8 years ago

Synchronizes the status of videos for all users between multiple Plex servers using Plexguide setup

Image
1

101

timekills/plex-db-sync-plexguide repository overview

⁠plex-db-sync-plexguide

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. Modified from original to include locations for Plexguide installation.

⁠Usage (manual script - not the Docker install)

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://github.com/timekills/plex-db-sync-plexguide/blob/master/plex-db-sync-plexguide 

apt install sshfs sqlite3

mkdir -p /mnt/sshfs

sshfs -o allow_other,nonempty [email protected]:"/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases/" /mnt/sshfs

chmod +x plex-db-sync

./plex-db-sync ./plex-db-sync --plex-db-1 "/mnt/sshfs/com.plexapp.plugins.library.db" --plex-start-1 "ssh -o StrictHostKeyChecking=no -i root@TLD docker start plex"  --plex-stop-1 "ssh -o StrictHostKeyChecking=no -i root@TLD docker stop plex" --plex-db-2 "/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" --plex-start-2 "docker start plex" --plex-stop-2 "docker stop plex"

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 (S2), and another remotely (S1) and that you are using the Plexguide.com install.

version: '3'

services:

  plex-db-sync-plexguide:
    image: timekills/plex-db-sync-plexguide
    container_name: plex-db-sync-plexguide
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./plex-db-sync/sshkey:/sshkey
      - /opt/appdata/plex/database/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=~/.ssh/id_rsa
      - S1_SSH_USER=root
      - S1_SSH_HOST=hostname
      - S1_SSH_PORT=22
      - S1_SSH_PATH="/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in" Support/Databases/
      - S1_START=ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@hostname docker start plex
      - S1_STOP=ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@hostname docker stop plex
      - S2_DB_PATH="/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in" 
      - S2_START=docker start plex
      - S2_STOP=docker stop plex
    restart: always

⁠Information

S1 = remote Server S2 = server that script/Docker is running on

⁠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.
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

Size

6.6 MB

Last updated

almost 8 years ago

docker pull timekills/plex-db-sync-plexguide:1.0