[HowTo] Plex database modification - Moving media the right/wrong way


#1

People ask all the time about moving media content. I think the reason they ask is because I think this article is misleading:
https://support.plex.tv/hc/en-us/articles/201154537-Move-Media-Content-to-a-New-Location

You can't move content to a new location and expect any of your manual changes to apply to the moved content. If your files are all named perfectly, then sure, Plex will simply rematch your files. But any content you added posters to, edited titles or tags, or did a "fix incorrect match" on won't be matched correctly no matter how closely you follow the above article. Please correct me if I'm wrong, but I have tried following the article multiple times and everytime I've reverted to my backup because my manual changes haven't been noticed.

What I want to do is (backup, then) open up the sqlite database and modify the location in the database itself. I'll report back how well this fails. :)

Joseph Elwell.


Lost metadata during relocation
Change library file paths without losing meta data
Kepping things the way they are before and after migration windows 10 to windows 10
Migrating my server from Mac to Windows
#2

I have moved media before... a couple of times... from a laptop to a server, then on the server from a location on one drive to a location on another drive within the same server.

What I have found is that the KEY to a successful "move" is not to "move" the content at all, but instead "copy" the files to the new location, Plex will update automatically when the new location is assigned to the library, then once Plex identifies "both" copies of the media (you should see a blue "2" in every entry that was copied), it will be able to keep the association with the previous files metadata, then you can remove the location listed in the library and the move should be complete.

I know others have tried this and had mixed results, but it has worked for me.

Anxious to hear your results.


#3

Looks like the following tables have references to filepaths that are pertinent here:
section_locations - this has the "root" path for a given set of movies.
metadata_items - this looks like all the MANUAL changes I made. So any movie that I manually updated has a reference there.
media_streams - this has paths to my subtitle files.
media_parts - looks like any movie that is split into 2 or more files has an entry here with a full file path. And some random movies that don't have multiple parts, not sure about this one.

Joseph Elwell.


#4

@jelwell said:
People ask all the time about moving media content. I think the reason they ask is because I think this article is misleading:
https://support.plex.tv/hc/en-us/articles/201154537-Move-Media-Content-to-a-New-Location
Not sure what is misleading. If you follow those steps, it works.
You can't move content to a new location and expect any of your manual changes to apply to the moved content. If your files are all named perfectly, then sure, Plex will simply rematch your files.
The whole idea is you want Plex to match your files so your files should be named properly in the first place. If your files are not named according to the way Plex wants and didn't get matched properly the first time, it obviously will not match it properly a second time.
But any content you added posters to, edited titles or tags, or did a "fix incorrect match" on won't be matched correctly no matter how closely you follow the above article. Please correct me if I'm wrong, but I have tried following the article multiple times and everytime I've reverted to my backup because my manual changes haven't been noticed.
Can you give an exact example of a movie, including filename and full before and after paths?
What I want to do is (backup, then) open up the sqlite database and modify the location in the database itself. I'll report back how well this fails. :)
I've actually looked into doing this too.


#5

@jelwell said:
Looks like the following tables have references to filepaths that are pertinent here:

You should collaborate with @MovieFan.Plex, he's been working the Plex Database for quite a while.
I always get a little nervous when third-party apps start changing things in my Database.
No sense re-inventing the wheel.

Just my $.02


#6

You can move you data and be successful. The key is to leave all DB pointers intact and let the scanner pick up the new location. It will then have 2 locations for each file.

By this I mean to modify the storage locations for your current library and ADD the new location while leaving the old location.

Do a complete refresh of your library. If you check any file it will have 2 locations listed. Now edit the library and remove the original location and do another refresh. Then delete "Empty Trash" and "Clean Bundles".

Everything will be as normal if done correctly and only the new locations will show up/be used.

Carlo


Change library file paths without losing meta data
#7

Thanks to everyone posting for trying to help me.

Plexhilarated : Awesome tip on checking out MovieFan.Plex's Database Tool. I suspect when I'm done I can contribute to that tool to help everyone else with this problem.

@MovieFan.Plex said:

@jelwell said:
People ask all the time about moving media content. I think the reason they ask is because I think this article is misleading:
https://support.plex.tv/hc/en-us/articles/201154537-Move-Media-Content-to-a-New-Location
Not sure what is misleading. If you follow those steps, it works.

As I pointed out before (and in more detail below) manual edits are lost. The opinion is whether "works" includes lost manual edits or not. If your definition includes losing that data, then sure, it works good enough. Good enough is clearly not good enough for me.

@MovieFan.Plex said:
You can't move content to a new location and expect any of your manual changes to apply to the moved content. If your files are all named perfectly, then sure, Plex will simply rematch your files.

I can expect it to work. I know my expectations don't match Plex's abilities - which is why I am fixing it myself. And I'm hoping to contribute a better overall solution for others.

@MovieFan.Plex said:
The whole idea is you want Plex to match your files so your files should be named properly in the first place. If your files are not named according to the way Plex wants and didn't get matched properly the first time, it obviously will not match it properly a second time.

I think it's not too much to ask for Plex to FIX my filenames for me when I manually match or edit my library using the Plex web interface. So that a rescan WILL match correctly. It would be great if there was a way to tell Plex to rename my files the best way possible. I have seen some third party tools that will attempt to do this for you, but the third party tools only work well for filenames Plex was likely to already match just fine. I also don't think it's too much to ask to offer a true move feature rather than shoehorning people into rematching everything. I'm running the rematch now (so that I can attempt to give specific examples) and it's taking hours. This is a huge waste of resources - plex already knows what all these files are. Moving them shouldn't be that big of a deal.

@MovieFan.Plex said:

But any content you added posters to, edited titles or tags, or did a "fix incorrect match" on won't be matched correctly no matter how closely you follow the above article. Please correct me if I'm wrong, but I have tried following the article multiple times and everytime I've reverted to my backup because my manual changes haven't been noticed.
Can you give an exact example of a movie, including filename and full before and after paths?

Here are just two of the numerous examples of me repeating the steps in the article (and yes most of the movies rematched just fine and indeed showed a little blue 2 icon - but it's easy to find the ones that failed; no blue 2 icon):
/Users/jelwell/Shared/63 Minutes Later (360p).mp4 (original location)
/Volumes/Movies/63 Minutes Later (360p).mp4 (copy)

/Users/jelwell/Shared/Hall of Fame/Blame_It_On_Rio_1984.mkv (original location)
/Volumes/Movies/Hall of Fame/Blame_It_On_Rio_1984.mkv (copy gets named "Hall of Fame")

I would have to manually edit these (and many more). Neither movie was matched to the original. I think what you and others are attempting to purport is that I should change my workflow so that I edit filenames rather than use plex web to search/match/edit things. I have 2 problems with this suggestion.
1. I can't go back in time. So there's already a lot of wasted work.
2. In attempting to rename files I will be guessing what Plex wants the file to be called. A lot of times the movies in question are obscure or have alternate titles (especially different languages). And my file manager isn't as helpful as Plex Web's built in search features.

Thanks,
Joseph Elwell.


#8

Or... perhaps the Plex "lock" mechanism could actually LOCK things?
That would be nice too.

[Peeve of mine]


#9

I opened up my database using http://sqlitebrowser.org/
I manually updated section_locations using the tool. Then I ran these 3 SQL statements:


UPDATE metadata_items
SET guid= replace(guid, 'file:///Users/jelwell/Shared', 'file:///Volumes/Movies')
where guid like '%file:///Users/jelwell/Shared%'


UPDATE media_streams
SET url= replace(url, 'file:///Users/jelwell/Shared', 'file:///Volumes/Movies')
where url like '%file:///Users/jelwell/Shared%'


UPDATE media_parts
SET file= replace(file, '/Users/jelwell/Shared', '/Volumes/Movies')
where file like '%/Users/jelwell/Shared%'

Note that media_part uses a different reference notation than the rests. (no file:///).

I haven't been able to drop the changes in place yet. I will try that later and report back.
Thanks,
Joseph Elwell.


#10

Ok, wow! That was surprisingly easy. Everything seems to be working GREAT!

So just so it's clear. Following my instructions will likely mess up your Library. But it worked wonders for me. AND it is SO easy. Easier than following the nuanced instructions in that article I linked above.

  1. Shutdown plex server
  2. Backup your data https://support.plex.tv/hc/en-us/articles/201539237
  3. Copy your content to the new location
  4. Edit your database. Find the location here: https://support.plex.tv/hc/en-us/articles/201100678-Repair-a-Corrupt-Database

There are 4 edits you'll need to make (change pathing to appropriate values):

UPDATE section_locations
SET root_path= replace(root_path, '/Users/jelwell/Shared', '/Volumes/Movies')
where root_path like '%/Users/jelwell/Shared%'

UPDATE metadata_items
SET guid= replace(guid, 'file:///Users/jelwell/Shared', 'file:///Volumes/Movies')
where guid like '%file:///Users/jelwell/Shared%'
UPDATE media_streams
SET url= replace(url, 'file:///Users/jelwell/Shared', 'file:///Volumes/Movies')
where url like '%file:///Users/jelwell/Shared%'
UPDATE media_parts
SET file= replace(file, '/Users/jelwell/Shared', '/Volumes/Movies')
where file like '%/Users/jelwell/Shared%'

5 Start up Plex Server
6 Verify that everything is working (test loading some of the copied files, note the location of that library changed in plex web settings)
7 Delete the old files.
8 Drink a beer for me.

@MovieFan.Plex might be worth adding to your tool?
Thanks everyone, I can't believe how simple it is and how inaccurate that article is. Might be a good idea to just implement a move function in Plex Web...
Joseph Elwell.

[moderator edit: repaired code formatting with Markdown syntax]


Moving my library and improperly matched movies
#11

@MovieFan.Plex might be worth adding to your tool?
Thanks everyone, I can’t believe how simple it is and how inaccurate that article is. Might be a good idea to just implement a move function in Plex Web…
Joseph Elwell.

:-"

> @jelwell said:


#12

@MovieFan.Plex said:

@MovieFan.Plex might be worth adding to your tool?
Thanks everyone, I can’t believe how simple it is and how inaccurate that article is. Might be a good idea to just implement a move function in Plex Web…
Joseph Elwell.

:-"

> @jelwell said:

I’m sure many people will thank you for adding this.
Joseph Elwell.


#13

Thank you for adding that.


#14

Doesn't look like there is a way to mark that I answered my own question. Which really isn't very surprising. Until MovieFan.Plex's new database tool is released, you can follow my SQL based solution above.
Joseph Elwell.


#15

Thanks for all the info. I'm about to attempt moving my library from a router shared HDD to a Firewire HDD connected straight to the computer. I'll try moving just the music first. add the path as an addition to the current library and see how it goes.


#16

I'm so glad i found this thread. I tried following the support topic to move media and even though i followed it exactly, a lot of my media got added as new and not matched to the original media. Editing the database worked perfectly.

One minor difference i found with my database is that in the metadata_items table, the guid field uses a url encoding scheme so spaces are represented as %20. So i had to modify the command slightly since my original and target folders have spaces in the paths.


#17

If i open the .db File with SQLite, how exactly can i change/find the Things need to be changed?


#18

@Cilow said:
If i open the .db File with SQLite, how exactly can i change/find the Things need to be changed?
See the selected answered post above.


#19

All i want to know is how can i find:
UPDATE section_locations
SET root_path= replace(root_path, '/Users/jelwell/Shared', '/Volumes/Movies')
where root_path like '%/Users/jelwell/Shared%'

??
I'm not so familiar with SQLite, as i use it the first time.


#20

Not sure what you mean by find. You just type that command replacement the paths with the old and new paths that you have. In the example "/users/..." is the old path, "/movies/..." is the new path.

If you are not familiar with salute, make a backup. You can really mess up your database if you do things wrong.