Corrupt Database - Transferring User Information

@Grappler1 I’m curious, when you done this procedure by exporting metadata_item_settings and metadata_item_views into a new DB did you run into any side effects ?

I’ve found that under the play history that the player and platform are now either blank or unknown for anything which was imported. New play activity registers correctly. Example screenshot below with the top item played after import of the data into a new DB…

Also, top users and play history on the main dashboard page only show new items in the summary, not legacy stuff from imports.

Looks like you also need the “devices” table from the original.

Cool, let me try that. I’m using this as an experiment just incase I ever need it in the future.

Would that also pull the top users historical data or is that in some other table? I took a quick look earlier but could see which one it is might be in.

Not sure on the “top” issue, but maybe. The query could be trying to create a join using the device info and without that the result would be empty. Let me know the result and I can dig some more if needed.

1 Like

Wonder would the accounts table be important if a join is happening. Anyhow, I’ll play around and report back in a few days.

No, that should get repopulated when you sign in. Although, if you had old users (managed or regular) you shared with before that you don’t share with now, those accounts won’t exist in the DB so their stats won’t show. You can grab that too if you want that history.

1 Like

I did lose that information but I was worried about just saving people’s previous watched history and that seemed to be intact after I followed Volt’s steps.

Yeah, that’s certainly in metadata_item_views but would like to keep the other information if I can. Will report back after I do some more testing.

Oh, interesting. Yeah, it makes sense to add devices and accounts if you’re doing metadata_item_views.

They’ll repopulate in the dashboard and database as those accounts and devices interact with the server again. But if you want the history to be complete …

It’s possible to just add them to the same command.

.../"Plex SQLite" com.plexapp.plugins.library.db ".output settings-views-accounts-devices.sql" ".dump metadata_item_settings" ".dump metadata_item_views" ".dump accounts" ".dump devices"

metadata_item_views also refers to library_sections.id, but that’s just not going to match without manual cleanup.

I’m tempted to clean this up so there aren’t primary key conflicts if the reload isn’t done immediately. I thought it would be easy to do with a temp table, but it’s more challenging than I expected - there’s no DROP COLUMN in SQLite. Hrm.

1 Like

I’d be curious to see all the steps. Would likely try it on another hard drive and set up since this one is working :slight_smile:

For me at least the library_sections.id column within table metadata_item_views matches what I have within the library_sections table. I only have two libraries, one for movies and one for television so it could be messy for folks with a large number of libraries.

1 Like

@anon18523487 okay, had some time this morning to run a test. At a high level this is what I done …

  • Backup existing /var/lib/plexmediaserver
  • Stopped plex and then nuked /var/lib/plexmediaserver
  • Started plex, claimed server and applied my specific settings to the server so they matched what it was previously
  • Added Movie Library (I use matching id tags for everything so they will match exactly the same)
  • Added TV Library (I use matching id tags for everything so they will match exactly the same)
  • For TV library I then adjusted the small number of shows custom episode ordering when compared to my library settings
  • Force refreshed all metadata for both libraries

Once done I then stopped plex and done the following …
Copied new com.plexapp.plugins.library.db to a temp location
Exported tables from source DB, the one taken in backup at the beginning using "/usr/lib/plexmediaserver/Plex Media Server" --sqlite com.plexapp.plugins.library.db ".output settings-views.sql" ".dump metadata_item_settings" ".dump metadata_item_views" ".dump accounts" ".dump devices"

I then dropped the tables in the new target database and confirmed count was 0…

"/usr/lib/plexmediaserver/Plex Media Server" --sqlite com.plexapp.plugins.library.db
delete from metadata_item_settings;
delete from metadata_item_views;
delete from accounts;
delete from devices;
select count(id) from metadata_item_settings;
select count(id) from metadata_item_views;
select count(id) from accounts;
select count(id) from devices;
.quit

Then imported "/usr/lib/plexmediaserver/Plex Media Server" --sqlite com.plexapp.plugins.library.db ".read settings-views.sql" source export into target db. Ran select counts again to ensure they imported.

Copied db from temp location back to plex main folder, set permissions and ownership and started plex.

The vast majority of things seem okay from what I’ve tested so far. CW, play count and full play history including device names all now appear which is great.

However, the top users and play history graphs on the main dashboard have been reset. For completeness sake is there any way to export and import that data ? Maybe its built off some complex query which is difficult to keep in scenarios like this.

@anon18523487 think I might have found it, statistics_media. Setting up for another test so don’t investigate until I report back.

@anon18523487 @Volts @Grappler1 okay, so the addition of statistics_media and statistics_bandwidth migrated the missing top users and play history graphs.

This is the full list of stuff I exported from source to target … not sure statistics_bandwidth is actually needed but I grabbed it anyhow :slight_smile:

"/usr/lib/plexmediaserver/Plex Media Server" --sqlite com.plexapp.plugins.library.db “.output settings-views.sql” “.dump metadata_item_settings” “.dump metadata_item_views” “.dump accounts” “.dump devices” “.dump statistics_media” “.dump statistics_bandwidth”.

From my testing anyhow metadata_item_settings is just needed for watch status but if you want CW and Dashboard stuff migrated also then metadata_item_views, accounts, devices, statistics_media and statistics_bandwidth worked well for me.

2 Likes

Nice work!!!

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