About a month ago, the hard drive hosting my Plex installation crashed. My media files are on a NAS, so they are fine, and I have the backup of the Media folder from the migration I did about four months ago, along with the database backup (and the registry file).
I thought that I’d be able to restore the database to the state it was before the earlier migration (since the only changes I made were new media files in the existing libraries), but after I imported the registry, copied the media folder from the migration backup, and replaced the database file with the latest backup, Plex Media Server would not start complaining that the database is corrupted. I tired to check database integrity using Sqlite3 and it reports that every backup file (I have four backups) is bad.
So my question is: am I completely hosed, or is there any hope to fix the database? I do not remember if I had any issues with Plex before the hard drive crash (my kids mostly use it), so I’m not sure why every backup would be bad. I saw articles explaining how to recover the corrupted database, but I’m wondering if it would make sense at all or whether I should just start from scratch, which I really hate to do, since I have a lot of metadata that needed to enter manually (custom videos, obscure TV episodes, etc). I spent so many hours defining the metadata, so I can’t even bring myself to thinking about doing this again.
(I am also wondering why every backup file I have is corrupt, but I’ll as this in a separate thread.)
I had something similar yesterday. I restored a backup yesterday, and saw in the logs that there was lots of SQLLITE errors. The reason for this was, that the database was from the previous version of PMS. I reinstalled the latest PMS, which probably made some changes to the database. I would guess that you’re db version is some versions old, and would need the updates (incremental) to work with the current version of PMS.
Might be a good idea to wait for a Plex Ninja … before updating …
If you used solid file name that doesn’t trip up the scanner and you didn’t have INDEX generation turned on it’s probably easier to reinstall Plex from scratch and setup the libraries again. The time to rescan should be minimal and you won’t drive yourself crazy trying to “fix it” just to get it to run again.
If you can upload your current Sqlite3 database someplace and PM I can take a look and see if there is anything I can do with it to repair or export/import it.
@cayars said:
If you used solid file name that doesn’t trip up the scanner and you didn’t have INDEX generation turned on it’s probably easier to reinstall Plex from scratch and setup the libraries again. The time to rescan should be minimal and you won’t drive yourself crazy trying to “fix it” just to get it to run again.
If you can upload your current Sqlite3 database someplace and PM I can take a look and see if there is anything I can do with it to repair or export/import it.
Thank you, Plex Ninja.
I’m not sure about the INDEX and all of my files are using the standard naming conventions, it’s just I have many that are custom or really obscure, so none of the scanners can find metadata and I had to manually enter the info (took me many, many hours). Don’t mind recreating libraries, but would really hate to redefine the metadata.
By “current Sqllite3 database”, did you mean the database backups? If so, I uploaded them here: DropSend (they’ll be available for 7 days, let me know if you have a problem downloading them).
I extracted com.plexapp.plugins.library.db-2017-03-19 and renamed it to:
com.plexapp.plugins.library.db
I ran the following:
sqlite3
.open ‘com.plexapp.plugins.library.db’
pragma integrity_check;
It’s telling me the database is OK
I can run .tables as well as normal SQL against the database.
Shut down Plex.
Uninstall current Plex version
Replace the current database with the version 3/19 that you just renamed to “com.plexapp.plugins.library.db”
Download server version 1.5.5
Install this version. If there were any database changes it should automatically update the database.
Don’t launch Plex yet.
Delete your log files
Start Plex and keep your fingers crossed
If you get any errors then wait about 30 seconds and go to SETTINGS/SERVER/HELP and download the LOG ZIP files and post them here.
Keep your fingers crossed as I think you will be ok.
@cayars said:
Shut down Plex.
Uninstall current Plex version
Replace the current database with the version 3/19 that you just renamed to “com.plexapp.plugins.library.db”
Download server version 1.5.5
Install this version. If there were any database changes it should automatically update the database.
Don’t launch Plex yet.
Delete your log files
Start Plex and keep your fingers crossed
Carlo
Thanks a lot Carlo. Weird thing: I ran the database check again like you described and it checked out fine. I repeated then what I exactly did yesterday (well, most exactly) and it was fine too. Go figure.
Just need to clarify a couple of things.
(1) The 1.5.5 version is current, right? So it’s the one that I downloaded and installed yesterday. Not sure why I need to uninstall it, but I did. So what do I do with the %LOCALAPPDATA% Plex Media Server files since they remained: do I delete them?
(2) When I reinstalled PMS, what should I do with the %LOCALAPPDATA% backup (it’s a couple of months older than my database backup)? Do I discard it and just use the database backup and use whatever is installed by the PMS installer, or can I salvage anything from the backup (not the database file)? If I were to use the old backup files (not the database), do I overwrite everything under the ‘%LOCALAPPDATA%\Plex Media Server’ folder, or just Media subfolder (or something else)?
I think I understand the process with the database, just not sure about the other backup files.
The main things is to make use of your backup since that will have many of the custom things you have done to customize Titles and things like that.
So lets try and restore everything you have under the Plex Media Folder (with Plex not running).
Then replace your database again with the version we already talked about and tested.
Uninstall Plex again
Rerun the Plex installed with the most recent version (e.g. 1.5.5) again which will update anything that’s out of date.
At that point you are “back” as much as possible. Then it’s testing time. Can you view a library and get icons, descriptions? Can you play one of your videos?
Pick your smallest library and RESCAN/REFRESH the library. Did it work OK? Try another library, etc Try smallest to biggest just so you can see/get results faster for piece of mind!
Report back how things work up to this point. Depending on how things go and any errors encountered (hopefully none) we may want to optimize the database or do some other processing.
How big are your libraries? Roughly how many movies, TV Episodes, Music Albums?
Oh, yeah! I’m back, baby, I’m back! Thank you sooooo much, Carlo. I had Plex uninstalled, kept the new LOCALAPPDATA folders (from the last installation), copied the Media and the Metadata folders from my old backup, installed Plex again, re-ran the .reg file just in case, launched Plex, and it seems to be working. Hooray! I’m still puzzled with why I’d get the database corruption errors. Maybe it was because I replaced the full LOCALAPPDATA folder with the old copy, not just the Medai/Metadata folders underneath it. Still Sqlite3 wouldn’t care, right? Anyway, it looks like I’m good now. Will need to think of a better backup strategy for the next time (I so wish it were more streamlined). And thanks one more time: you saved me many hours. I appreciate it!
Most likely that was due to now running a newer version of the server and your database didn’t get “updated” properly so you ended up with a mismatch and it complained. That’s why I had you do the update just to make sure any new changes would get added. Figured it couldn’t hurt since we had your database backed up.
At this point I would do something like:
Optimize database
Rescan movies library
Optimize database
rescan TV library
Optimize database
until you get all your libraries done.
Then you can delete trash
Clean Bundles
Final Optimize database
You can just rescan everything if you wish but if you’ve added a lot of new content the database will get fragmented and will make it slow. By doing the optimize in bween libs it helps to keep performance up. No other reason except that.
Once you’ve done all this and are confident everything is working fine get yourself some new backups.