Plex data directory: Essential files/folder structure?

Server Version#: 1.32.5.7349-8f4248874

Yesterday my backup drive got corrupted, so both hard drives dead in just a few weeks…
I’ve sourced out the Plex system folder to these external drives a while ago, just because of the growing size of the metadata folder.
Luckily I was able to recover (probably) all files of the Plex data directory itself, but there’s a problem:
The folder structure got completely wiped out, so I’m left with hundreds of thousands of mixed files in one folder.

My question is this:
Which are the 100% essential files for Plex to boot and what is the necessary folder structure?
Is there a list anywhere that could help me to sort these needed files “by hand”?

So as I understand it, there are 3 types of files in that folder:

  • 100% essential, Plex won’t start without them
  • rebuilt by reboot, Plex will automatically create them after stop/restart
  • rebuilt by rescan, Plex will only create them when re-scanning the library

So the last type (and the largest amount of those 100.000s of files) should just be metadata.
I will do a full rescan of my whole library anyway, so those files don’t need a backup I guess…?
Same with the 2nd type, as long as Plex gets to the boot process, I should be okay with leaving them out. As long as I get the server to start properly once, those files will be there again anyway.

But what bothers me are those essential files.
Which one of them do I really need, and what is the correct place for them to put in??

So my goal is basically to backup just those essential files, rearrange everything into its place, copy that folder onto a fresh hard drive, plug it into my server, and hope Plex loads everything correctly. From there I will do the rescans then to recreate my metadata.

Can anybody help me out with this?
ANY help regarding this topic is highly appreciated, as I’ll have to setup a completely new server if i can’t get it back to work this way…

Thanks in advance!

If I were doing this, I would likely try to tackle it something like this.

  • Treat it like a new installation initially; stop Plex Media Server, move /var/lib/plexmediaserver/ (or wherever you Plex data folder resides) out of the way, start Plex Media Server, and allow it to run for a bit to create the new data directory. Do not create any new libraries or claim the server at this point.
  • Stop Plex Media Server.

This should be identical to a new, non-configured installation.

Here’s a tree of the top-level Plex data directory hierarchy:

/var/lib/plexmediaserver/Library/Application Support/Plex Media Server$ tree -L 1
.
├── Cache
├── Codecs
├── Crash Reports
├── Diagnostics
├── Drivers
├── Logs
├── Media
├── Metadata
├── plexmediaserver.pid
├── Plug-ins
├── Plug-in Support
├── Preferences.xml
├── Scripts
├── Setup Plex.html
└── Updates

In that top-level directory, move your recovered Preferences.xml back into place, if you have it; this will recover most (all?) of your configured server settings and leave your server in its original claimed state.

Next, the only folder path we really care about is Plug-in Support/Databases. Here’s its tree:

/var/lib/plexmediaserver/Library/Application Support/Plex Media Server$ tree -L 2 Plug-in\ Support/Databases/
Plug-in Support/Databases/
├── com.plexapp.plugins.library.blobs.db
├── com.plexapp.plugins.library.blobs.db-2023-09-29
├── com.plexapp.plugins.library.blobs.db-2023-10-02
├── com.plexapp.plugins.library.blobs.db-2023-10-08
├── com.plexapp.plugins.library.blobs.db-2023-10-11
├── com.plexapp.plugins.library.blobs.db-shm
├── com.plexapp.plugins.library.blobs.db-wal
├── com.plexapp.plugins.library.db
├── com.plexapp.plugins.library.db-2023-09-29
├── com.plexapp.plugins.library.db-2023-10-02
├── com.plexapp.plugins.library.db-2023-10-08
├── com.plexapp.plugins.library.db-2023-10-11
├── com.plexapp.plugins.library.db-shm
├── com.plexapp.plugins.library.db-wal
├── tv.plex.providers.epg.cloud-20ab7cb6-aa2f-4693-a827-b548f5f570b1.db
├── tv.plex.providers.epg.cloud-20ab7cb6-aa2f-4693-a827-b548f5f570b1.db-shm
└── tv.plex.providers.epg.cloud-20ab7cb6-aa2f-4693-a827-b548f5f570b1.db-wal

Delete the existing com.plexapp.plugins.* files and replace them with your recovered copies, if you have them. This should restore your configured libraries and watch history and most other information which is stored in the databases.

From here, start Plex Media Server and scan your libraries. You’ll likely also need to refresh all metadata for each library. This will likely (eventually) get you back to where you were before the drive failures. It will probably take time though, and I can’t estimate how long.

Obviously, keep your recovered files around in case this doesn’t work out.

1 Like

Thanks for your fast reply!
I’ll try your solution as soon as I find some time the upcoming days.

Could you also give me some advice on recovering my plugins?
Is there a way to list everything installed up to a certain point?
I still have some of my last logs, so maybe some information there…?
I haven’t installed many plugins anyway (just some scanners and theme music for tv series), but don’t want to forget anything, just to make sure all my scanners work correctly when running Plex again.

Or can I get everything else to work first, and then reinstall the needed plugins afterwards…?
And can I just re-download them and unzip them into the “Plugins” folder, or is another step needed?

To be perfectly honest I don’t use any plug-ins myself so I don’t think I can authoritatively make suggestions in that regard. My best guess is that you could preemptively drop them in the correct spot before starting Plex Media Server (after the file restorations described above). But I really don’t know how they interact with the database or the rest of the directory structure. Sorry.

If I may add ?

  1. Keeping your existing files and saved instance (“Plex Media Server” dir) safe
  2. Let PMS install a new instance in /var/lib/plexmediaserver (nothing pre-existing)
  3. Claim the server
  4. TURN OFF ALL LIBRARY SETTINGS ( Don’t forget “Show Advanced”)
  5. Stop Plex

Now you can get to work

  1. The critical files you’ll need all exist in the “Databases” directory.
  2. Everything else will regenerate based on what exists in the databases

The process is:

sudo bash
systemctl stop plexmediaserver


# Move the empty databases out of the way
cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
cd "Plug-in Support"

#  rename the empty ones
mv "Databases"  "Unused-Databases"

# COPY in the saved "Databases" directory and contents to make it live
cp -rp   "/path/to/saved/Databases" .

# Fix ownership
chown -R plex:plex  Databases

# Start it up
systemctl start plexmediaserver

Now, One library section at a time

  1. Go to the library section
  2. Confirm your pathnames (for media) are still correct.
  3. Scan files – allow it to complete
  4. Refresh all metadata (it is actually downloading all fresh since it didn’t)
  5. When complete
    – Empty Trash
    – Optimize Database
  6. Repeat for the next library section until done
  7. Settings - Server - Library - Turn your automatic preferences back on as you wish

When you’re all done and the world is good again, remove the “Unused-Databases” directory

Ask if questions :slight_smile:

1 Like

This shouldn’t be necessary. Moving the recovered Preferences.xml file back into place will leave the server in a claimed state.

Arguably, this is likewise unnecessary. If it is for some reason, that implies larger problems that are going to affect the recovery in other ways. (If the media paths are different, it suggests that there were more significant system changes than were indicated, such as changing mount points, loss of media, etc…)

This could leave their PMS in a non-functional state as we don’t know whether or not it is running as the default user. They’re overriding the Plex data directory, so it’s possible (even likely) they’re overriding the Plex user as well. Stated more generically, “ensure that the owner/group of ./Databases and its contents matches that of the Plex data directory.”

I’d recommend sticking with my initial suggestions above, taking into consideration the ownership question (thanks for that!).

@pshanew

  1. The heart of my instructions are the databases. If the user wants to recover Preferences.xml then fine but not necessary.

  2. Turning off ALL the library settings make 100% certain the user has opportunity to fix library pathnames — without losing watch status / history / playlists before the directory paths are verified (network mounts. etc) as the folder structure was wiped out (user statement in the OP)

  3. When moving files around, I don’t know what the ownership of the files is.
    For all I know they could be owned by root:root which definitely won’t work.
    By stating plex:plex at least changing the ownership is noted in the process.

Like you, concern is the Databases directory and its contents in totality.
Everything else can be new but the server fully restored with just the databases.

User-added Plug-ins are obviously an additional step

Hey Chuck, thanks for your answer, too!
I have 2 additional questions:

Turning off ALL the library settings make 100% certain the user has opportunity to fix library pathnames — without losing watch status / history / playlists before the directory paths are verified (network mounts. etc) as the folder structure was wiped out (user statement in the OP)

I’m not sure, but this might be a misunderstanding?
Only the folder structure of my Plex data directory was wiped out, the hard drives with my media files are completely fine and still 100% as they were before.
So would the step above just be necessary, if the paths of my media changed, too…?

User-added Plug-ins are obviously an additional step

Could you please give me some more information on this step?
For example, how to get a complete list of all previously installed plugins first, then how to reinstall them? Is there anything plugin-related in the data directory that must be backed up, or can everything just be downloaded again manually and put into place?
And should this be done before or after I restored the server itself (Preferences.xml + databases)?

Thanks for your help!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.