This is probably one of the most annoying things for anybody who has Plex or Kodi database setup on their computer. At some point of time, something goes wrong and you have to wipe everything clean. As a result, all your past history including play status and bookmarks are gone.
I went through this process couple times. It’s not fun, therefore I’m always cautious about losing ability to restore database to its previous state.
Recently, I had a problem with Plex Server that was residing on one the shares on my server. I decided to install Plex docker instead of plugin too. I also wanted to move it cache drive. It would seem like trivial thing. Install docker and map the paths to existing library. But for some reason Plex server refused to start. Changing file permissions did not fix the issue. Of course everything was working great when I started from scratch with a new database.
After multiple trial and errors I was able to figure out that problem was caused by additional files that are in the same folder as database. Basically, when SQLite database is initiated, it creates 2 files that are like a fingerprint for database. In order to substitute database you have to delete them first.
Once I figure out what is causing the problem I decided to try to move database to different PC. I knew exactly what I have to do, but to my surprise media files were not playing. With a help of great tool SQLite Spy I was able to inspect file paths. Clearly in order to move database from one location to another, these paths need to be corrected.
I was able to do it in fairly quick. I had some parts of the code from different applications I was working on. All I had to do is to reuse it in the way that it made sense for this particular problem.
At the end standalone application PlexDBFix is a result of the initial idea.
First it connects to Plex database. It retrieves media parts paths and puts the in the top ListView. Now you have 4 options where do you want to move database. In addition, you need to specify which part of the string you want to replace and what you want to replace it with. Pressing preview button will show changes. Apply button will actually update media_parts and sections tables.
Important! Before you proceed always backup your original database file and stop Plex Server.
When making changes you need to specify where you are moving database file. There are four options. You can transfer your database from Server to PC or vice versa. Also, you have choice selecting PC to PC or Server to Server when changing in between a folders only.
Next, you have decide what part of file path you want to substitute. Hitting Preview button will show you how it will look.
Finally you need to press Apply for actual changes to take place. There is no undo button, so as I said before backup your original database file first.
Why do you need to make this changes?
Plex Server database contains information about file paths of your media files. Therefore, when you move it form one location to another, Plex server will not be able to locate them unless you make actual changes. As you probably noticed, we are changing information for video files. We do not touch anything related to artwork. It’s not necessary to do it. Database holds only reference to these files. Therefore you have two options:
- Copy/Paste folder containing artwork
- Start from scratch. Create sections that match sections already created in existing database. Scan media folder and allow Plex download necessary metadata. Finally, substitute new created database with the saved one.
Where is Plex Server database located?
Depending on your platform and server setup, you should be able to navigate to Plex Media Server folder and find Plug-in Support. There is a Database folder containing a file that we are looking for. This is an example showing location on my home PC
“\Plex Media Server\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db”
Before we complete moving database to a new location, we have to do delete two files. Do not worry they will be recreated automatically when Plex Server starts again. If we fail to do so, Plex Server will simply not recognize our new database. These files are in the same folder as our database and they are: