Plex Media Server (move or clone)

Russell Bateman
August 2019
last update:

Moving or cloning a Plex Media Server on a different piece of hardware

I followed a number of articles on this that I found, but Move an Install to Another System is the one I followed the closest. However, this article doesn't even come close to all the help needed.

We consider what it means to copy the contents of an existing Plex Media Server (source system) to another, new server (destination system).

Preparation

  1. Disable emptying of trash by Plex. In brower from http://plex.tv, launch server and do:

    Settings → Settings → Library → Empty trash automatically after every scan

  2. Install Plex Media Server on the destination system (see Plex Media Server (new).)

  3. Halt Plex on the destination system.
    # systemctl stop plexmediaserver
    

Copy files from the source system

In the steps below, destination refers to the host where the new Plex Media Server is located. In my case, this is nargothrond whereas my original system, source, is tol-eressea. You must adjust the command line for your own circumstances.

  1. Halt Plex on the source system.
    # systemctl stop plexmediaserver
    
  2. There are two "piles" of content that you must copy.
    1. The Plex application files including this list (but not what's stricken out):
      • Cache
      • Codecs
      • Crash Reports
      • Diagnostics
      • Logs
      • Media
      • Metadata   !
      • Plug-ins
      • Plug-in Support
        under here is Databases   !
      • Preferences.xml
    2. The very media files (movies, videos, music, etc. that you're serving up on your Plex Media Server).
  3. The Plex application content is found:
    • On Linux, do this to find it (assumes installation of locate). This tells me that the path to my Plex Media Server is /var/lib/plexmediaserver/Library/Application Support/Plex Media Server.
      russ@tol-eressea:~$ locate "Library/Application Support/Plex Media Server" | head
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Codecs
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Crash Reports
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Diagnostics
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Media
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Metadata
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support
      /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins
      

      Note that, because I installed and already launched Plex on my new, destination system, all (or most) of these files already exist:

      root@nargothrond:/# ll /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server
      total 36
      drwxr-xr-x 8 plex plex 4096 Aug  3 12:44  .
      drwxr-xr-x 3 plex plex 4096 Jul 11 10:00  ..
      drwxr-xr-x 4 plex plex 4096 Aug  3 11:45  Cache
      drwxr-xr-x 3 plex plex 4096 Jul 29 20:38  Codecs
      drwxr-xr-x 4 plex plex 4096 Jul 29 20:38 'Crash Reports'
      drwxr-xr-x 3 plex plex 4096 Aug  2 02:36  Logs
      drwxr-xr-x 3 plex plex 4096 Jul 11 10:01  Plug-ins
      drwxr-xr-x 7 plex plex 4096 Jul 11 10:00 'Plug-in Support'
      -rw------- 1 plex plex  703 Aug  3 12:39  Preferences.xml
      
    • On Windows, it's at %LOCALAPPDATA%\Plex Media Server.
    • On Macintosh OS, I care even less than about Windows. Sorry.

    Here are the commands for coping from the source system:

    russ@tol-eressea: # cd /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server
    russ@tol-eressea: # scp -rp Codecs           nargothrond:/var/lib/plexmediaserver/Application\ Support/Plex\ Media\ Server
    russ@tol-eressea: # scp -rp Diagnostics      nargothrond:/var/lib/plexmediaserver/Application\ Support/Plex\ Media\ Server
    russ@tol-eressea: # scp -rp Logs             nargothrond:/var/lib/plexmediaserver/Application\ Support/Plex\ Media\ Server
    russ@tol-eressea: # scp -rp Media            nargothrond:/var/lib/plexmediaserver/Application\ Support/Plex\ Media\ Server
    russ@tol-eressea: # scp -rp Plug-ins         nargothrond:/var/lib/plexmediaserver/Application\ Support/Plex\ Media\ Server
    russ@tol-eressea: # scp -rp Plug-in\ Support nargothrond:/var/lib/plexmediaserver/Application\\ Support/Plex\\ Media\\ Server"
    russ@tol-eressea: # scp -rp Preferences.xml  nargothrond:/var/lib/plexmediaserver/Application\ Support/Plex\ Media\ Server
    

    Note that Metadata and plex-database-backup for me are special. Because I want these backed up along with the media files (residing on a mirrored, zfs volume), I will

    1. Move that content with the media files (below).
    2. Re-create the symbolic link from the Plex application files to it.
  4. Choose a place for your media files on the destination system. In my case, I'm moving them from (source system) /plex-movies and plex-television (two volumes) to (destination system) /plex-media (single volume). Here are the commands for coping:

    russ@tol-eressea: # cd /plex-movies
    russ@tol-eressea: # scp -rp Movies               nargothrond:/plex-media
    russ@tol-eressea: # scp -rp Documentaries        nargothrond:/plex-media
    russ@tol-eressea: # cd /plex-television
    russ@tol-eressea: # scp -rp TV                   nargothrond:/plex-media
    russ@tol-eressea: # scp -rp Metadata             nargothrond:/plex-media
    russ@tol-eressea: # scp -rp plex-database-backup nargothrond:/plex-media
    

    Note that I have Plex application subdirectories, Metadata and plex-database-backup, to copy. These I don't want on nargothrond's system disk because that disk isn't mirrored.

Restart both systems

  1. I can now restart my original (source) system:
    tol-eressea:# systemctl restart plexmediaserver
    
  2. Now I must reestablish the symbolic links on my new (destination) system:
  3. nargothrond:# cd /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server
    nargothrond:# ln -s /plex-media/Metadata
    nargothrond:# cd Plug-in\ Support
    nargothrond:# rm -rf Databases
    nargothrond:# ln -s /plex-media/plex-database-backup ./Databases
    
  4. And, I can bounce my new (destination) system. It's a good thing to bounce even the hardware so that any state Plex might have had in memory is gone and all is brand new:
  5. nargothrond:# reboot
    nargothrond:# systemctl restart plexmediaserver
    
  6. If I've been observing all of this on another system via a browser, I should sign out, then sign back in in order to update connection information though it's unlike that any of that changed since I already had my new Plex Media Server running empty before I started all of this.

Appendix: Getting around users, groups and permissions

Copying user-owned data between two Linux (Unix) hosts is problematic. The data is owned by user plex, group plex. But, user plex has no password, home directory or other accoutrements to facilitate copying between two machines. You must create a "real" user, superplex here, and make it belong to group plex and you must make use of root judiciously to get around trouble.

On both hosts (though mainly for the target), create the new user:

# useradd -d /home/superplex -m superplex
# passwd superplex
# usermod -a -G plex superplex

Edit /etc/passwd to change /bin/sh to /bin/bash.

The working formula, that gets around all the nasties, appears to be to use root on the source, modify the target directory to be writable by user superplex, then use this command to clean things up when finished. An example of target-host-subdirectory would be Plex Media Server. I had to modify it to allow superplex write access temporarily:

# chmod g+w /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server

Later, after the big copy, I fix that up as well as original ownership by user plex by doing this:

# chmod g-w /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server
# chown plex:plex -R target-host-subdirectory

Here's a sample copy command, copying from the source server (tol-eressea in my case) to the target server (nargothrond in my case). Note the tricks using scp:

# scp -rp Codecs superplex@nargothrond:"/var/lib/plexmediaserver/Library/Application\\ Support/Plex\\ Media\\ Server/"

Appendix: What went wrong bringing the second server up

  1. Routing confusion arose because of existing port-forwarding
  2. When connected to plex.tv, probably trying to get browser to connect to external port, internally, the browser saw the server on the network, so it tried to access the local server but using the external port.
  3. I fixed this by telling Plex that the subnet is on local network and that it should allow it to do this successfully
  4. Settings → Network → LAN networks. Enter subnet as 192.168.0.0/24.
  5. Also to facilitate authorization by those internal to my LAN, I set the list of IP addresses and networks that are allowed without authorization (the set is the same as above). Now someone in-house can access without logging in through their own Plex account.

What went wrong, version 2

Hacking around at the server to figure out why...

  1. ...I can't seem to find it in my browser, indeed even my browser right on the very host I'm running it on.
  2. ...when I get close, I often see an error, "You do not have permission to access this server."

This is the URL to use http://localhost:32400/web in answer to the above. This takes the browser directly to the web pages of the server itself. (I'm running my newest Plex Media server on a Linux Mint desktop instead of my usual headless, Ubuntu Server.)

Ultimately, the Preferences.xml file is problematic. There are sort of hidden settings here that are relevant including usernames and magic identities (ids). These have come over from the cloned Plex Media server and they won't work. The new server will be all about making you create new libraries and rescan content. This is why you cloned in the first place: in order not to have to do that again. It is necessary to remove this file, but first, you must shut down the Plex Media server:

# systemctl stop plexmediaserver
# pushd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
# mv Preferences.xml Preferences.xml.old
# popd
# systemctl start plexmediaserver

Here is a Plex support article URL:

Support Articles: Why am I locked out of Server Settings