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

So many methods shown here. Which is the preferred way of doing it this today?

I would like to simply change the mount point from my NAS library without losing any of the history, etc. My motivation for doing this is prep for an eventual move from a standard ubuntu install to a snap install on a new machine.

That being said, is there any reason that the aforementioned edits to media_streams, media_parts, and section_locations would not work? And, along those lines, I looked at my database and saw no paths in metadata_items in the guid column so that’s why I didn’t list it.

Hi.
I just wanted to say that your method is the only one that worked for me!
I tried copying, then I also tried editing the database file but none of these worked properly. With your method, I only had to clean up (delete) a couple of double entries, but on whole, it worked like a charm, thanks!
Kristian.

It worked like a charm
Within the file com.plexapp.plugins.library.db change all entries of direct file or folder paths with a simple replace function to point to the new locations of the files and watched folders.

In my case they where in the following three tables:
section-location
metadata-items
media-parts

For instructions of the replace function within SQLite editors it can be found here: https://www.sqlitetutorial.net/sqlite-replace-function/

com.plexapp.plugins.library.db Is located in the databases folder in plug-in support folder. Delete all other files in this databases folder except:
com.plexapp.plugins.library.blobs.db
com.plexapp.plugins.library.db

If done correctly and thoroughly, Plex will never notice that the media has been moved!

If you copy your files to a new location, add that folder to the same library, then remove the old folder from the library, it will recognise them as the same files and it will just remap the file paths keeping all the meta data and your watched lists entact. Then you are free to delete the files from the old location. If you are worried about losing something, refresh the library after adding the new folder, and it will indicate that you have 2 of each movie, show etc. Then remove the old folder from the library.

7 posts were split to a new topic: Merging two library by editing DB

@anon18523487 where exactly do I find the tool you mention? and is it only for a specific OS?
Thanks

The tool I mentioned was something I created many, many years ago that I haven’t supported for a long time. I wouldn’t bother trying to use it. The Plex database has changed quite a bit since then.

Old Topic, same issue. I’m a data guy and I just looked at all the tables in the db.
I am also on this journey to understanding the Plex database structure.
Looking to move from an external device to an internal one Under Linux.

I just went through all the tables and I can (9/3/2021) only find 2 places where my directory is stored within the database.

select * from section_locations where root_path like ā€˜%/mnt/mediastorage/%’ limit 1000;
select * from media_parts where file like ā€˜%/mnt/mediastorage%’ limit 100

I will update if its successful. I still cannot believe Plex does not offer a better functional way of doing this in a support manor across multiple platforms… Sad really

insert into section_locations
select (select seq from sqlite_sequence where name = ā€˜section_locations’) as id, library_section_id, ā€˜G:\Movies’ as root_path, available, scanned_at, created_at, updated_at
from section_locations
where root_path = ā€˜F:\Movies’;

update sqlite_sequence
set seq = seq + 1
where name = ā€˜section_locations’;

UPDATE metadata_items
SET guid= replace(guid, ā€˜F:\Movies’, ā€˜G:\Movies’)
where guid like ā€˜F:\Movies%.mp4’;

UPDATE media_parts
SET file= replace(file, ā€˜F:\Movies’, ā€˜G:\Movies’)
where file like ā€˜F:\Movies%.mp4’;

UPDATE media_streams
SET url= replace(url, ā€˜F:\Movies’, ā€˜G:\Movies’)
where media_item_id in (select media_item_id from media_parts where file like ā€˜G:\Movies%.mp4’);

update media_items
set section_location_id = (select id from section_locations where root_path = ā€˜G:\Movies’)
where id in (select media_item_id from media_parts where file like ā€˜G:\Movies%.mp4’);

Hi. Sorry to bring this back up but does the above script still work? If so, on this script, what is the old location and the new location?

I am transitioning my data and would hate to have my server have to rescan.

Thank you!

F is the old, G is the new, so change those parameters to match your folders.

For those looking to do this using DB Browser (thanks to @yooniverse ):

In DB Browser, delete the two triggers, and write (commit) the change:
fts4_metadata_titles_before_update_icu
fts4_metadata_titles_after_update_icu

Run your metadata update SQL statements.

Then recreate the two triggers, then commit:

CREATE TRIGGER fts4_metadata_titles_before_update_icu BEFORE UPDATE ON metadata_items BEGIN DELETE FROM fts4_metadata_titles_icu WHERE docid=old.rowid; END;

CREATE TRIGGER fts4_metadata_titles_after_update_icu AFTER UPDATE ON metadata_items BEGIN INSERT INTO fts4_metadata_titles_icu(docid, title, title_sort, original_title) VALUES(new.rowid, new.title, new.title_sort, new.original_title); END

hello all, i’m upgrading my plex server and part of that is upgrading the location of all my media.

i’ve tested (albeit shortly) with a few of the suggestions here but haven’t got it setup fully. in short, the libraries within plex are pointing to the new directory but the media items themselves still show the old path.

i’ve a bandaid fix in place (symlink) but i’d like to get it done and dusted properly. anyone done this recently? thanks!

Hi.
The solution on post #44 is not working for me. I have my media in Y:\Movies\YYYY, where YYYY is the year the media was released. I created the Z:\Movies\YYYY directory structure and added it to the Movies library.
When I move media from Y: to Z: it is picked up by the Plex Server, a new match is made and I lose all my custom metadata. Can this be because I donĀ“t use standard directory names? I use ā€œPortuguese Title - Original Title (YEAR)ā€ for the media directory name.

As long as the movie was able to automatically match originally, this should still work. If you had to manually match them or if they are still listed as unmatched, this won’t work.

1 Like

I’d like to try this method to implement copying all of my music files from one server to another. Since many of my files either don’t match at all or match incorrectly, I’d like to keep all of the metadata about the files on the original server and have them on the new server. Is there a way using the SQLite method to only copy data related to music files?

The above steps change the location of your files. Just change the filter to use only the path to your music files. Then it won’t affect the others.

I followed levander’s move media to another location instructions and it does not work for me…all manually edited metadata on the moved files is LOST!. I created an empty new folder in the target library, rescanned the target library, moved (not copied) the file from the source library to the new folder created in the target library, rescanned the target library, and all manually entered metatdata on the file was gone. I need a solution that keeps me from losing years of manually entered metadata on 50,000+ files.

I’m moving files between two libraries on the same NAS but between different volumes. Could this be the problem?

Is this procedure still safe to do on a PMS in 2022 [Version 1.29.1.6276] ?

Hi Just wondering if there are any step by step guides to doing this as I have several large libraries to move to a new location with a lot of unique content. I haven’t done any database editing before so was hoping there might be some more detailed guides available for this process?