Migrating Plex from Warden to Iocage

Chris Dill

Contributor
Joined
Jan 1, 2014
Messages
116
I am running freenas 11.2. I have a legacy plugin install version of Plex from when I was back on 9.X. I am going to migrate this to a manually built iocage jail.

My library Mount points will be different.

what files do I need to transfer a cross in order to keep my library data intact? I am looking to maintain my watched tracking, all of my server settings IP addresses and everything else.

Do I need to move over the entire directory /var/db/Plex, or only preferences.xml?

in my manually built iocage jail, is the directory structure going to be the same? I will be installing PlexMediaserver-plexpass.

Also, with my current version of Plex I update using the PMS update or script. On the new iocage jail what is my method for updating?
 

Chris Dill

Contributor
Joined
Jan 1, 2014
Messages
116
If anyone has ANY tips, toss them out! I am poised to migrate in the next few hours, God willing.
 

colmconn

Contributor
Joined
Jul 28, 2015
Messages
174
I have done this many versions ago when iocage first became available.

I'll assume you've got your iocage jail created and you've got plex installed in it.

Off the top of my head, what I did was
  1. shut down both warden and iocage plex jails.
  2. On the host locate the plex directory in the warden dataset.
  3. Identify where you want this in the iocage plex jail and rsync it across.
  4. Ensure that user IDs in the iocage jail are appropriate to permit plex access to your media. This is especially important if you intend to let plex write access to your media library. Though ensureing read access is important if you want to actually stream anything.
  5. Now you can set some variables in the /etc/rc.conf to control where plex find is meta data, logs, etc, and the user and group name it will be run under. If you go with the defaults here you may have very little to set in the /etc/rc.conf file beyond item 4. Then you can set them in your jail's /etc/rc.conf file using the sysrc command. E.g.,
    1. sysrc plexmediaserver-plexpass_support_path="path used in rsync command above, remember that you will need to delete /mnt/iocage/jail/plexmediaserver-plexpass/root (double check this) from that path"
    2. sysrc plexmediaserver-plexpass_user="username you want plex to run as"
    3. sysrc plexmediaserver-plexpass_group="group name you want plex to run as"
    4. sysrc plexmediaserver-plexpass_enable="YES"
  6. I highly recommend keeping the library mount points in the iocage the same as in your warden jail. This will permit you to simply start up plex in your iocage jail, and assuming you've done everything above correctly, plex will just start up and all your metadata and library files will be in the right place and it should just work.
  7. Leave the warden jail in a stopped state until you're happy that your iocage plex jail is working correctly. The you can, if you like, delete your warden plex jail. You umight want to ensure that it doesn't start automatically on reboot as well.
Lastly don't be afraid to mess up your iocage plex jail. You can always blow it away and start again. Just dont delete your warden jail until you're happy that you've got the iocage jail working correctly.
 

Chris Dill

Contributor
Joined
Jan 1, 2014
Messages
116
I have done this many versions ago when iocage first became available.

I'll assume you've got your iocage jail created and you've got plex installed in it.

Off the top of my head, what I did was
  1. shut down both warden and iocage plex jails.
  2. On the host locate the plex directory in the warden dataset.
  3. Identify where you want this in the iocage plex jail and rsync it across.
  4. Ensure that user IDs in the iocage jail are appropriate to permit plex access to your media. This is especially important if you intend to let plex write access to your media library. Though ensureing read access is important if you want to actually stream anything.
  5. Now you can set some variables in the /etc/rc.conf to control where plex find is meta data, logs, etc, and the user and group name it will be run under. If you go with the defaults here you may have very little to set in the /etc/rc.conf file beyond item 4. Then you can set them in your jail's /etc/rc.conf file using the sysrc command. E.g.,
    1. sysrc plexmediaserver-plexpass_support_path="path used in rsync command above, remember that you will need to delete /mnt/iocage/jail/plexmediaserver-plexpass/root (double check this) from that path"
    2. sysrc plexmediaserver-plexpass_user="username you want plex to run as"
    3. sysrc plexmediaserver-plexpass_group="group name you want plex to run as"
    4. sysrc plexmediaserver-plexpass_enable="YES"
  6. I highly recommend keeping the library mount points in the iocage the same as in your warden jail. This will permit you to simply start up plex in your iocage jail, and assuming you've done everything above correctly, plex will just start up and all your metadata and library files will be in the right place and it should just work.
  7. Leave the warden jail in a stopped state until you're happy that your iocage plex jail is working correctly. The you can, if you like, delete your warden plex jail. You umight want to ensure that it doesn't start automatically on reboot as well.
Lastly don't be afraid to mess up your iocage plex jail. You can always blow it away and start again. Just don't delete your warden jail until you're happy that you've got the iocage jail working correctly.


Wow, thanks for taking the time, I appreciate it!

I was not aware of /etc/rc.conf edits for Plex. I will definitely need to look into this before I hack up some files. I have never used sysrc, will need to look into that also. I can keep the library mounts the same, thats no issue. I can even clean them up after.

What do you mean by this? "Ensure that user IDs in the iocage jail are appropriate to permit plex access to your media."

Typically I just use the user created when the jail is installed. And in fact, my permissions are so jacked not sure I can process this... I run a windows domain and all shares are CIFS permissioned + all of the jail permissions. When I log into my warden jail and check permissions on all of my media libraries now this is what I see:

Code:
root@plexmediaserver_1:/media # ls -la
total 846
drwxr-xr-x   16 root   wheel   16 Jan  9  2018 .
drwxr-xr-x   18 root   wheel   24 Jan 19  2017 ..
drwxr-xr-x    2 root   wheel    2 Mar 11  2016 Christmas
drwxrwxrwx+  37 352    352     39 Nov 21 00:38 Christmas-Movies
drwxrwxrwx+   2 352    352      2 Nov  8 16:53 Delete
drwxr-xr-x    2 root   wheel    2 Feb 19  2016 Drone
drwxrwxrwx+  16 352    352     17 Mar  2  2018 Fitness
drwxrwxrwx+ 423 20500  20513  423 Dec  9 18:09 Keep
drwxrwxrwx+ 340 352    352    341 Dec  6 22:31 Kids-Movies
drwxrwxrwx+  20 351    351     20 Dec  3 09:38 Kids-TV
drwxr-xr-x    2 root   wheel    2 Feb 19  2016 Music
drwxrwxrwx+  40 20500  352     41 Dec  8 04:48 New
drwxrwxrwx+  42 352    352     42 Nov  8 14:41 Nicholes Library
drwxr-xr-x    2 root   wheel    2 Mar 11  2016 Podcasts
drwxrwxrwx+  40 351    351     40 Dec 12 22:51 TV
drwxrwxrwx+   3 21120  20513    4 Mar  6  2018 Training
 

colmconn

Contributor
Joined
Jul 28, 2015
Messages
174
Re user IDs. Suppose you have a dataset called media on the host that stores all your media, e.g., movies, tc shows, music, etc. Further suppose that all the files in that data set are owned by a user named media with user ID 1002. In your plex jail the default is to create a user named plex with a user ID which can't remember, but lets suppose it's 2000. The same thing applies with the group ownership. I have all files in my media dataset owned by group named media with ID 1002. I keep the names and IDs (both user and group) the same for the sake of simplicity.

When the host's media dataset is mounted in the jail via nullfs the ID of the owner (user and group) on the host will be preserved (i.e., 1002) and not mapped to the IDs of the plex user and group. You have to account for this manually.

In my plex jail I created a group named media with ID 1002 and also a user named media with ID 1002. Note that the user and group names don't really matter. They could be media on the host and bigbird (or plex) in the jail. What matters is that the IDs (user and group) are the same on both host and jail. That way you will never have permissions issues, assuming you've got the correct rwx bits set correctly for user, group and other on the host.

In my jail I issued the following commands to create the media user and group:
Code:
pw groupadd -n media -g 1002 ## create group named media with ID 1002
pw useradd -n media -u 1002 -g media ## create user named media with ID 1002 and belonging to the group media


You could just as easily just use the preexisting plex user and group in the jail and modify its underlying IDs to match that of the host, e.g.,
Code:
pw groupmod -n plex -g 1002 ## change the plex group to have ID 1002
pw usermod -n plex -u 1002 ## change the plex user to have ID 1002
getent plex ## to check the user ID and group ID of the plex user


If you're unfamiliar with the pw and getent commands, read the man pages.

Just remember that the IDs of the user and group on both the host and jail need to match.

Since you say you share out the media files via CIFS/samba, what you could do is change the ownership (user and group) of all the files in your media dataset to match the that of the user and group you want your media owned by, media in the example above. There are then incantations that you can add to your samba share definitions to force it to create files in those shares with specific user IDs and group IDs and even specific patterns of rwx for user, group, and and other. However, since I use AFP I'm not that familiar with them.

With respect to the file listing you show, there is at least some consistency to is with the repeated showing of ID 352 which suggests that on the host much of it may be owned by this user and group ID. Fixing it should not be too much of a problem.
 

joebad1

Explorer
Joined
Nov 21, 2015
Messages
58
Alternative method worked for me to get Plex from warden plugin to iocage plugin. It's manual, and takes a few steps. I'm one step above a noob, and had no trouble. It's working great:

1) I'm running 11.2-U2.1
2) Installed new Plex Pass server using the iocage plug-in
3) Created mount points for the new jail using the same directories as the old warden jail for "movies", "music", "series", "photos".
4) Stopped the new jail/plug-in.
5) Went to the legacy UI and stopped the old Plex warden plug-in.
6) Used instructions on this website to copy the old database settings to the new Plex database:

Plex Support Article "Move Viewstate/Ratings from One Install to Another"

7) My pool structure is "/mnt/media". My old warden jails are under "/mnt/media/jails". My new iocage jails are under "/mnt/media/iocage/jails".
8) You're looking for a file called "com.plexapp.plugins.library.db".
9) My warden database file was here: /mnt/media/jails/plexmediaserver_1/var/db/plexdata/Plex Media Server/Plug-in Support/Databases. Open a FreeNAS Shell and navigate to this location.
10) Type the following SQLite command:
Code:
echo ".dump metadata_item_settings" | sqlite3 com.plexapp.plugins.library.db | grep -v TABLE | grep -v INDEX > settings.sql


This creates a file called "settings.sql"

11) Navigate to the new database location. In my case, it was found under "/mnt/media/iocage/jails/plex/root/Plex Media Server/Plug-in Support/Databases"

12) Copy the "settings.sql" file to the new database directory:

Code:
cp /mnt/media/jails/plexmediaserver_1/var/db/plexdata/Plex Media Server/Plug-in Support/Databases/settings.sql settings.sql


13) Install the old settings into the new database:

Code:
cat settings.sql | sqlite3 com.plexapp.plugins.library.db


14) Last few items: I disabled the autostart on the old warden jail and changed the new jail IP to match the old one.
15) Restarted the new iocage Plex jail.
16) Everything is right as rain
17) Note: My Roku Plex app had a little trouble "seeing" the new server. I had to "Restore to Defaults" in the Roku Plex App for it to work properly. Did not lose any of my settings when doing this. Other devices and web access had no problems.

One last postscript. Two final steps:
1) Make sure you go into "Authorized Devices" in your Plex account and remove/delete the old server.
2) I eventually found that I had to "Signout" of my Plex Account on the Roku App, and then re-link my Plex Account to the Roku App. This was the only way I could get the Roku to "forget" the old server.
 
Last edited:

msbxa

Contributor
Joined
Sep 21, 2014
Messages
151
Alternative method worked for me to get Plex from warden plugin to iocage plugin. Thanks you joebad1 and Chris
 

ChiknNutz

Patron
Joined
Nov 6, 2015
Messages
217
Perhaps I glossed over it, but how did you go about moving the actual data from the Warden jails to the Iocage jails? Although I've had my FreeNAS since version 9, I am a set it and forget it kinda user. I do not like to dig into the minutia of all this and need step by steps.
 

joebad1

Explorer
Joined
Nov 21, 2015
Messages
58
See note 3) above. Same music, movies and series directories that we’re used in the warden jails.

You have to add mount points to the new Plex jail. Stop the jail. Go to mount points and add the directories there.
 

ChiknNutz

Patron
Joined
Nov 6, 2015
Messages
217
Meaning you leave the data alone, just add pointers (which I presume are mount points) to that existing data? I thought the whole point of this exercise was to move stuff from the warden jail locations to the new iocage jail locations? No?

Honestly, all I care about is making this stuff work and don't really care about the details. My stuff still all works, but I see that 11.3 drops warden stuff altogether so assume you can't even move to 11.3 if you still have warden jails in place.
 

joebad1

Explorer
Joined
Nov 21, 2015
Messages
58
Meaning you leave the data alone, just add pointers (which I presume are mount points) to that existing data? I thought the whole point of this exercise was to move stuff from the warden jail locations to the new iocage jail locations? No?

Honestly, all I care about is making this stuff work and don't really care about the details. My stuff still all works, but I see that 11.3 drops warden stuff altogether so assume you can't even move to 11.3 if you still have warden jails in place.

Yes. You are correct. You are leaving the data alone. Remember, the warden jail directories are really just pointers to the actual directories on your pool. You added links to them when you created the jails/plugins during setup in version 9.3. Now you'll be creating iocage jails, and doing basically the same thing: Creating "mount points" or jail directories that really just point to the same old directories on your pool. My mount points look like this:

Screen Shot 2020-02-02 at 9.20.53 PM.png


My Music and Photos source directories are a little different. I use NextCloud to sync music and photos from my wife's MacBook Pro (sync'd from her phone to her Mac) to the server. I just point Plex to those directories.

You can move to 11.2 and keep the warden jails. But not 11.3.
 

ChiknNutz

Patron
Joined
Nov 6, 2015
Messages
217
Got it, thanks!
 

themachine

Cadet
Joined
Feb 21, 2020
Messages
2
alternative method didn't work out well for me. I followed steps from here https://support.plex.tv/articles/201370363-move-an-install-to-another-system/
Your setup, paths, and mileage may vary. This was under FreeNAS-11.2-U8

1. Create New Freenas iocage Jail
Stop warden jail and set autostart to false in legacy jail interface
Install plugin - plex-plexpass in Plugins
Set ip to old ip of warden jail plex server
Verify plex is running at web interface but do not login or configure

2. Backup old warden plex info
ssh to freenas server as root or use web interface shell
Code:
cd /mnt/zfs/jails/plexmediaserver_1/var/db/plexdata/
tar -czv --exclude=Plex\ Media\ Server/Stuff -f Plex_warden_backup.tgz Plex\ Media\ Server/

/mnt/zfs is my default pool and "Stuff" above is the mountpoint for my Plex libraries

3. Copy over and extract backup to new jail
Stop New Plex iocage Jail
Code:
cp Plex_warden_backup.tgz /mnt/zfs/iocage/jails/plex-plexpass/root/Plex_warden_backup.tgz
cd /mnt/zfs/iocage/jails/plex-plexpass/root/
tar -xzvf Plex_warden_backup.tgz


4. Setup Mountpoint for libraries
Create Mountpoint to match old jail under Jail mountpoint settings
Source: /mnt/zfs/plex
Destination: /mnt/zfs/iocage/jails/plex-plexpass/root/Plex Media Server/Stuff

5. Start new plex iocage jail

6. I had issues with plex not starting
https://support.plex.tv/articles/200250417-plex-media-server-log-files/
Code:
cd Plex\ Media\ Server/Logs/
less Plex\ Media\ Server.log


had errors like this in logs
Code:
Feb 21, 2020 21:16:10.776 [0x80ba16000] DEBUG - Opening 20 database sessions to library (com.plexapp.plugins.library), SQLite 3.26.0, threadsafe=1
Feb 21, 2020 21:16:10.779 [0x80ba16000] INFO - SQLITE3:(nil), 283, recovered 115 frames from WAL file /Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db-wal
Feb 21, 2020 21:16:10.781 [0x80ba16000] ERROR - SQLITE3:(nil), 11, database corruption at line 65066 of [bf8c1b2b7a]
Feb 21, 2020 21:16:10.781 [0x80ba16000] ERROR - SQLITE3:(nil), 11, statement aborts at 8: [] database disk image is malformed
Feb 21, 2020 21:16:10.781 [0x80ba16000] ERROR - SQLITE3:(nil), 11, database disk image is malformed in "PRAGMA cache_size=2000"
Feb 21, 2020 21:16:10.783 [0x80ba16000] ERROR - Database corruption: sqlite3_statement_backend::prepare: database disk image is malformed for SQL: PRAGMA cache_size=2000
Feb 21, 2020 21:16:10.783 [0x80ba16000] ERROR - Error: Unable to set up server: sqlite3_statement_backend::prepare: database disk image is malformed for SQL: PRAGMA cache_size=2000 (N4soci10soci_errorE)


Found info on restoring backup db but I just moved some temporary sqllite files out of the way and restarted jail and plex was happy again
https://support.plex.tv/articles/202485658-restore-a-database-backed-up-via-scheduled-tasks/

Code:
cd ..\Plug-in\ Support/Databases
ls -al
mv *shm ~/
mv *wal ~/

Restart Jail

7. Finish up
Edit Libraries with new path at / rather than /var/db/plexdata/
Rescan Libraries
Take a break and wait while plex matches up all your content

Life is good!
 
Top