ChuckPa / PlexDBRepair

Database repair utility for Plex Media Server databases
Other
884 stars 43 forks source link

Could Not Determine SQL Lite Path Error #143

Closed chriskeeganhw closed 6 months ago

chriskeeganhw commented 7 months ago

Hi

I have been directed here by Plex Ninja (Otto) to see if the repair tool will fix my suspected corrupt Plex DB

I have downloaded the files, I am running it on a Windows server

When I run the DBRepair-Windows.bat in elevated CMD mode I get the error message "Could Not Determine SQL Lite Path"

My SQL Lite for plex is in the plex install directory of C:\Program Files (x86)\Plex\Plex Media Server

I am not so technical but I think the batch file to start the DB repair is looking for the SQL Lite program in C:\Program Files\Plex\Plex Media Server directory (I guess I am running the 32 bit plex server)

Is there a way for me to still run the DB repair on the version and place where its installed on my windows server??

Many thanks

Apologies if this is a dumb user error and Ive missed something somewhere

ChuckPa commented 7 months ago

I didn't realize there is a difference. (I had help with Windows)

In the script, it looks for "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe"

If you saved a copy, then changed %PROGRAMFILES%\ to %PROGRAMFILES% (x86)\ that might be enough.

Would you be willing to edit it and let me know the results?

chriskeeganhw commented 7 months ago

Hi CHuck

Thanks for the response

I get a slightly different message now replacing %PROGRAMFILES%\ to %PROGRAMFILES% (x86)\

\Plex\Plex Was unexpected at this time

I am useless at scripting and programming but had a go at "hard coding" the path to the SQL Lite somehow instead of searching for it. So I tried the following in the bits where it tries to find out the install location by putting in some rem statements and in the "set" line forcing the location

REM Find PMS installation location. for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe" if not exist "%PlexSQL%" ( rem if exist "%PROGRAMFILES (x86)%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES (x86)%\Plex\Plex Media Server\Plex SQLite.exe" rem) else ( rem echo Could not determine SQLite path. rem echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe rem echo. rem goto :EOF ) )

The script started to run

Got the session begins message followed by the exporting Main DB message but then it stopped with an error saying

The system cannot find the path specified

I guess there is another variable somewhere (or possibly more than 1) that I have to somehow hard code. Is it to do now with the PMS database location, or the plug in directory

ANy help gratefully received

Many thanks and best regards

On Fri, 26 Apr 2024 at 06:22, Chuck @.***> wrote:

I didn't realize there is a difference. (I had help with Windows)

In the script, it looks for "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe"

If you saved a copy, then changed %PROGRAMFILES%\ to %PROGRAMFILES% (x86)\ that might be enough.

Would you be willing to edit it and let me know the results?

— Reply to this email directly, view it on GitHub https://github.com/ChuckPa/PlexDBRepair/issues/143#issuecomment-2078652534, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4EE4E37V5NS4Q3UP25PH3Y7HQAVAVCNFSM6AAAAABGZJHPOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZYGY2TENJTGQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks and regards Chris

ChuckPa commented 7 months ago

Which value (path) did you hard code for the Plex SQLite?

I can handle getting the variables right.

Is this the right path? C:\Program Files (x86)\Plex\Plex Media Server\Plex SQLite.exe

ChuckPa commented 7 months ago

Would you try / look at this please ?

DBRepairWinTest.zip

chriskeeganhw commented 7 months ago

Hi Chuck

I got an error that says

\Plex\Plex\ was unexpected at this time

Thanks for the help

On Fri, 26 Apr 2024 at 18:36, Chuck @.***> wrote:

Would you try / look at this please ?

DBRepairWinTest.zip https://github.com/ChuckPa/PlexDBRepair/files/15133720/DBRepairWinTest.zip

— Reply to this email directly, view it on GitHub https://github.com/ChuckPa/PlexDBRepair/issues/143#issuecomment-2079808941, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4EE4CRJH4LQP52KSAMPHTY7KGBXAVCNFSM6AAAAABGZJHPOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZHAYDQOJUGE . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks and regards Chris

ChuckPa commented 7 months ago

did it show which line?

ChuckPa commented 7 months ago

Look at these pathnames, which is correct / incorrect?

REM Find PMS installation location.
for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe"
if not exist "%PlexSQL%" (
        if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" (
                set "PlexSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe"
                goto :FoundSQL
        ) else if exist "%PROGRAMFILES(x86)%\Plex\Plex Media Server\Plex SQLite.exe" (
                set "PlexSQL=%PROGRAMFILES(x86)%\Plex\Plex Media Server\Plex SQLite.exe"
                goto :FoundSQL
        ) else (
                echo Could not determine SQLite path.
                echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe
                echo Or %PROGRAMFILES% (x86)\Plex\Plex Media Server on 64 bit systems
                echo.
                goto :EOF
        )
)

It sounds like I'm accidentally adding something.

Can you show me the exact path?

ChuckPa commented 7 months ago

Chatting with Otto,

You do not need to run elevated privileges. PMS runs in your normal user account. Run the script in whichever account PMS runs as.

chriskeeganhw commented 7 months ago

Hi, sadly it didnt

On Fri, 26 Apr 2024 at 19:00, Chuck @.***> wrote:

did it show which line?

— Reply to this email directly, view it on GitHub https://github.com/ChuckPa/PlexDBRepair/issues/143#issuecomment-2079840425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4EE4AA72QDGEHUQE3WKHTY7KI3NAVCNFSM6AAAAABGZJHPOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZHA2DANBSGU . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks and regards Chris

chriskeeganhw commented 7 months ago

Hi Chuck

I hard coded as follows

REM Find PMS installation location. for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe" if not exist "%PlexSQL%" ( rem if exist "%PROGRAMFILES (x86)%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES (x86)%\Plex\Plex Media Server\Plex SQLite.exe" rem) else ( rem echo Could not determine SQLite path. rem echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe rem echo. rem goto :EOF

remmed out a couple of lines and replaced - only in the section of the batfile that looks for what SQL Lite is installed with a space then (86)

Regards

On Fri, 26 Apr 2024 at 19:01, Chuck @.***> wrote:

Look at these pathnames, which is correct / incorrect?

REM Find PMS installation location. for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe" if not exist "%PlexSQL%" ( if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" goto :FoundSQL ) else if exist "%PROGRAMFILES(x86)%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES(x86)%\Plex\Plex Media Server\Plex SQLite.exe" goto :FoundSQL ) else ( echo Could not determine SQLite path. echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe echo Or %PROGRAMFILES% (x86)\Plex\Plex Media Server on 64 bit systems echo. goto :EOF ) )

— Reply to this email directly, view it on GitHub https://github.com/ChuckPa/PlexDBRepair/issues/143#issuecomment-2079843479, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4EE4F7AP5TXJFKZ5ANCLDY7KI65AVCNFSM6AAAAABGZJHPOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZHA2DGNBXHE . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks and regards Chris

chriskeeganhw commented 7 months ago

Hi

So when I run it NOT in elevated mode, your original bat file stops when it tries to do something in the Plug In directory

Specifically it says

C:\PlexDBRepair>dbrepair-windows 21:41:55.89 -- ====== Session begins. (26/04/2024) ====== 21:41:56.58 -- Exporting Main DB The system cannot find the path specified.

C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-in Support\Databases> C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-in Support\Databases>

If I try to run the new test bat file (the dbr-win.bat) it stops with

C:\PlexDBRepair>dbr-win \Plex\Plex was unexpected at this time

Sorry

Regards

On Fri, 26 Apr 2024 at 19:13, Chuck @.***> wrote:

Chatting with Otto,

You do not need to run elevated privileges. PMS runs in your normal user account.

— Reply to this email directly, view it on GitHub https://github.com/ChuckPa/PlexDBRepair/issues/143#issuecomment-2079880088, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4EE4BHVHM5TSC3EUDIETDY7KKLHAVCNFSM6AAAAABGZJHPOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZHA4DAMBYHA . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks and regards Chris

ChuckPa commented 7 months ago

I have found my Windows 10 VM.

I have discovered the Plex installer writes incorrect information in the registry.

I will report this as a bug ( a big bug )

I will update the tool to ignore the registry

chriskeeganhw commented 7 months ago

Hi Chuck

Thanks

Look forward to registry free script

Thanks and regards

Chris

On Sat, 27 Apr 2024 at 08:30, Chuck @.***> wrote:

I have found my Windows 10 VM.

I have discovered the Plex installer writes incorrect information in the registry.

I will report this as a bug ( a big bug )

I will update the tool to ignore the registry

— Reply to this email directly, view it on GitHub https://github.com/ChuckPa/PlexDBRepair/issues/143#issuecomment-2080399865, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4EE4FAV3DFZXQYRJE6WATY7NH2TAVCNFSM6AAAAABGZJHPOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBQGM4TSOBWGU . You are receiving this because you authored the thread.Message ID: @.***>

danrahn commented 6 months ago

I have discovered the Plex installer writes incorrect information in the registry.

I will report this as a bug ( a big bug )

I will update the tool to ignore the registry

I saw this as well from investigating this reddit thread, and created my own fork to address it before I saw this thread that seems to be the ~same issue.

chriskeeganhw commented 6 months ago

Hi Dan

Thanks

I tried to copy your lines of script from the fork you posted to replace the same section that starts "REM Find PMS installation location" in Chucks script

Assuming I did it right and didnt mess it up, I got an error message that said

"" was unexpected at this time.

I am afraid I have no knowledge of scripting, syntx etc so dont know at what point that error message happens

I have attached Chucks script with the section replaced by your script

Many thanks

@echo off REM PlexDBRepair.bat - Database maintenance / rebuild tool for Windows. REM REM This tool currently works as a "full shot" service. REM - everything is done without need to interact. REM REM -- WARNNING -- WARNING -- WARNING REM REM This is stable working software but not "Released" software. Development will continue. REM REM ### Create Timestamp set Hour=%time:~0,2% set Min=%time:~3,2% set Sec=%time:~6,2%

REM ## Remove spaces from Hour ## set Hour=%Hour: =%

REM ## Set TimeStamp ## set TimeStamp=%Hour%-%Min%-%Sec%

REM Find PMS database location for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "LocalAppDataPath" 2^> nul') do set "PlexData=%%b\Plex Media Server\Plug-in Support\Databases" if not exist "%PlexData%" ( if exist "%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases" ( set "PlexData=%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases" ) else ( echo Could not determine Plex database path. echo Normally %LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases echo. goto :EOF ) )

REM Find PMS installation location. REM As of PMS 1.40.2, a 32-bit install on a 64-bit OS sets InstallFolder to 'C:\Program Files\Plex\Plex Media Server', even though it's actually installed at REM 'C:\Program Files (x86)\Plex\Plex Media Server'. Because of that, overwrite InstallFolder if %PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe exists for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe" if not exist "%PlexSQL%" (

if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" (
    set "PlexSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe"
) else (
    echo Could not determine SQLite path.
    echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe
    echo.
    goto :EOF
)

) else ( if exist "%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe" ( echo WARN: 32-bit version of PMS detected on a 64-bit version of Windows. Updating to the 64-bit release of PMS is recommended. set "PlexSQL=%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe" ) else ( if exist "%PROGRAMFILES(ARM)%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES(ARM)%\Plex\Plex Media Server\Plex SQLite.exe" ) else if not exists "%PlexSQL%" ( echo Could not determine SQLite path. echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe echo. goto :EOF ) ) )

REM Set temporary file locations set "DBtmp=%PlexData%\dbtmp" set "TmpFile=%DBtmp%\results.tmp"

REM Time now. echo %time% -- ====== Session begins. (%date%) ====== echo %time% -- ====== Session begins. (%date%) ====== >> "%PlexData%\PlexDBRepair.log"

REM Make certain Plex is NOT running. tasklist | find /I "Plex Media Server.exe" >NUL if %ERRORLEVEL%==0 ( echo %time% -- Plex is running. Please stop Plex Media Server and try again. echo %time% -- Plex is running. Please stop Plex Media Server and try again. >> "%PlexData%\PlexDBRepair.log" exit /B 1 )

cd "%PlexData%"

md "%PlexData%\dbtmp" 2>NUL del "%TmpFile%" 2>NUL

echo %time% -- Exporting Main DB echo %time% -- Exporting Main DB >> "%PlexData%\PlexDBRepair.log" echo .dump | "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db" > "%DBtmp%\library.sql_%TimeStamp%" if not %ERRORLEVEL%==0 ( echo %time% -- ERROR: Cannot export Main DB. Aborting. exit /b 2 )

echo %time% -- Exporting Blobs DB echo %time% -- Exporting Blobs DB >> "%PlexData%\PlexDBRepair.log" echo .dump | "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db" > "%DBtmp%\blobs.sql_%TimeStamp%" if not %ERRORLEVEL%==0 ( echo %time% -- ERROR: Cannot export Blobs DB. Aborting. )

REM Now create new databases from SQL statements echo %time% -- Exporting Complete. echo %time% -- Exporting Complete. >> "%PlexData%\PlexDBRepair.log"

echo %time% -- Creating Main DB echo %time% -- Creating Main DB >> "%PlexData%\PlexDBRepair.log" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db%TimeStamp%" < "%DBtmp%\library.sql%TimeStamp%" if not %ERRORLEVEL%==0 ( echo %time% -- ERROR: Cannot create Main DB. Aborting. echo %time% -- ERROR: Cannot create Main DB. Aborting. >> "%PlexData%\PlexDBRepair.log" exit /b 3 )

echo %time% -- Verifying Main DB echo %time% -- Verifying Main DB >> "%PlexData%\PlexDBRepair.log" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "PRAGMA integrity_check(1)" >"%TmpFile%" set /p Result= < "%TmpFile%" del "%TmpFile%"

echo %time% -- Main DB verification check is: %Result% echo %time% -- Main DB verification check is: %Result% >> "%PlexData%\PlexDBRepair.log" if not "%Result%" == "ok" ( echo %time% -- ERROR: Main DB verificaion failed. Exiting. echo %time% -- ERROR: Main DB verificaion failed. Exiting. >> "%PlexData%\PlexDBRepair.log" exit /B 4 ) echo %time% -- Main DB verification successful. echo %time% -- Main DB verification successful. >> "%PlexData%\PlexDBRepair.log"

echo %time% -- Creating Blobs DB echo %time% -- Creating Blobs DB >> "%PlexData%\PlexDBRepair.log" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db%TimeStamp%" < "%DBtmp%\blobs.sql%TimeStamp%" if not %ERRORLEVEL%==0 ( echo %time% -- ERROR: Cannot create Blobs DB. Aborting. echo %time% -- ERROR: Cannot create Blobs DB. Aborting. >> "%PlexData%\PlexDBRepair.log" exit /b 5 )

echo %time% -- Verifying Blobs DB echo %time% -- Verifying Blobs DB >> "%PlexData%\PlexDBRepair.log" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "PRAGMA integrity_check(1)" > "%TmpFile%" set /p Result= < "%TmpFile%" del "%TmpFile%"

echo %time% -- Blobs DB verification check is: %Result% echo %time% -- Blobs DB verification check is: %Result% >> "%PlexData%\PlexDBRepair.log" if not "%Result%" == "ok" ( echo %time% -- ERROR: Blobs DB verificaion failed. Exiting. echo %time% -- ERROR: Blobs DB verificaion failed. Exiting. >> "%PlexData%\PlexDBRepair.log" exit /B 6 ) echo %time% -- Blobs DB verification successful. echo %time% -- Blobs DB verification successful. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Import and verification complete. echo %time% -- Import and verification complete. >> "%PlexData%\PlexDBRepair.log"

REM Import complete, now reindex echo %time% -- Reindexing Main DB echo %time% -- Reindexing Main DB >> "%PlexData%\PlexDBRepair.log" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.db_%TimeStamp%" "REINDEX;"

echo %time% -- Reindexing Blobs DB echo %time% -- Reindexing Blobs DB >> "%PlexData%\PlexDBRepair.log" "%PlexSQL%" "%PlexData%\com.plexapp.plugins.library.blobs.db_%TimeStamp%" "REINDEX;"

REM Index complete, make active echo %time% -- Reindexing complete. echo %time% -- Reindexing complete. >> "%PlexData%\PlexDBRepair.log" echo %time% -- Moving current DBs to DBTMP and making new databases active echo %time% -- Moving current DBs to DBTMP and making new databases active >> "%PlexData%\PlexDBRepair.log"

move "%PlexData%\com.plexapp.plugins.library.db" "%PlexData%\dbtmp\com.plexapp.plugins.library.db%TimeStamp%" move "%PlexData%\com.plexapp.plugins.library.db%TimeStamp%" "%PlexData%\com.plexapp.plugins.library.db"

move "%PlexData%\com.plexapp.plugins.library.blobs.db" "%PlexData%\dbtmp\com.plexapp.plugins.library.blobs.db%TimeStamp%" move "%PlexData%\com.plexapp.plugins.library.blobs.db%TimeStamp%" "%PlexData%\com.plexapp.plugins.library.blobs.db"

echo %time% -- Database repair/rebuild/reindex completed. echo %time% -- Database repair/rebuild/reindex completed. >> "%PlexData%\PlexDBRepair.log" echo %time% -- ====== Session completed. ====== echo %time% -- ====== Session completed. ====== >> "%PlexData%\PlexDBRepair.log"

exit /b

REM #### Functions

REM Output - Write text to the console and the log file :Output

echo %time% %~1 echo %time% %~1 >> "%PlexData%\PlexDBRepair.log" exit /B

danrahn commented 6 months ago

Sorry about that @chriskeeganhw, I was too hasty with some refactoring and ended up posting a broken script. I've pushed a new commit that should address it (https://github.com/danrahn/PlexDBRepair/commit/4e427a104376d2af1f45556b650df5a6ed935782).

chriskeeganhw commented 6 months ago

Hi Dan

I think it must be me pasting code in the wrong place

Still get the same error "" was unexpected at this time.

I replaced this

REM 'C:\Program Files (x86)\Plex\Plex Media Server'. Because of that, overwrite InstallFolder if %PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe exists for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe" if not exist "%PlexSQL%" (

if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" ) else ( echo Could not determine SQLite path. echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe echo. goto :EOF ) ) else ( if exist "%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe" ( echo WARN: 32-bit version of PMS detected on a 64-bit version of Windows. Updating to the 64-bit release of PMS is recommended. set "PlexSQL=%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe" ) else ( if exist "%PROGRAMFILES(ARM)%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES(ARM)%\Plex\Plex Media Server\Plex SQLite.exe" ) else if not exists "%PlexSQL%" ( echo Could not determine SQLite path. echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe echo. goto :EOF ) ) )

with

REM 'C:\Program Files (x86)\Plex\Plex Media Server'. Because of that, overwrite InstallFolder if %PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe exists for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe"

if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" (

if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" ) else ( if exist "%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe" ( @@ -46,11 +46,13 @@ for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex ) else ( if exist "%PROGRAMFILES(ARM)%\Plex\Plex Media Server\Plex SQLite.exe" ( set "PlexSQL=%PROGRAMFILES(ARM)%\Plex\Plex Media Server\Plex SQLite.exe" ) else if not exists "%PlexSQL%" ( echo Could not determine SQLite path. echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe echo. goto :EOF ) else ( if not exist "%PlexSQL%" ( echo Could not determine SQLite path. echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe echo. goto :EOF ) ) ) )

danrahn commented 6 months ago

I'd avoid trying any partial copy/pasting and use the entire script directly. You can find the "raw" version here, which you can copy/paste in its entirety, or right-click > Save as: raw.githubusercontent.com/danrahn/PlexDBRepair/master/DBRepair-Windows.bat.

Also, as a future tip, if you paste code in a comment, you can surround it with three backticks to keep the formatting:

``` Your Code Here ```

becomes

Your
    Code
  Here
ChuckPa commented 6 months ago

This is a weird but fun problem ?

On X64 machines, ProgramFiles (x86) exists. A 32 bit Plex is installed there. On a x32 (x86) machine, everything ends up in Program files (e.g. "Program Files" is for all same-mode programs)

The problem I run into is the

if exists "......"  (
)

logic, setting the variable values, then trying to continue

Windows loves to say unexpected

It's further compounded when folks install Plex in anything but the default location.

FWIW: I stopped using Windows completely in 2002. Haven't missed it :rofl:

If anyone can help me finish this for all folks, I'll gladly implement immediately.

Please correct me if wrong, we need to solve for (without the registry)

  1. Install Path?
  2. Data Path ?
ChuckPa commented 6 months ago

regarding fixing this.

I would prefer a PR filed, which "Fixes: https://github.com/ChuckPa/PlexDBRepair/issues/143" This would make tracking all changes very easy for myself as well as everyone else (issues, prs, and commits all align) ALSO, PLEASE squash before the PR. (multi-commit PR's are ugly)

I use VS Code editor for all this work.

  1. It understands the different scripting languages
  2. It's GitHub aware

https://code.visualstudio.com/

ChuckPa commented 6 months ago

Thinking outloud.

How about this idea? (do NOT know the correct syntax)

set PlexSQLite=""

for %%D in  C D E (
  if exists "%%D:\Program Files\Plex\Plex SQLite.exe" (
    set PlexSQLite="%%D:\Program Files\Plex\Plex SQLite.exe"
  ) 
  if exists "%%D:\Program Files (x86)\Plex\Plex SQLite.exe" (
    set PlexSQLite="%%D:\Program Files (x86)\Plex\Plex SQLite.exe"
  )
)

If "%PlexSQLite" = "" (
  echo  ERROR:  Is Plex installed?   Cannot find PlexSQLite
  exit /b 99
)
danrahn commented 6 months ago

I would prefer a PR filed, which "Fixes: #143" This would make tracking all changes very easy for myself as well as everyone else (issues, prs, and commits all align) ALSO, PLEASE squash before the PR. (multi-commit PR's are ugly)

Sounds good! I was planning on opening a PR, but was hoping for confirmation that what I had so far worked on someone else's machine before sending it out, but I'll get what I have out soon.

As for drive letter iteration, I could see that as a potential fallback if the current approaches don't work, since I think in 99% of cases the InstallFolder/%PROGRAMFILES[(X86)]% checks would be more reliable. I also added a secondary fallback to user input if neither of those approaches work, but feel free to let me know in the PR if you think there's a better approach.

chriskeeganhw commented 6 months ago

Many thanks both of you

Have sucessfully run the script and I think cleaned up my database

I am being very cheeky and asking a follow on question, but I accept that I might not get an answer which is fair enough

GitHub has a variety of Plex backup scripts that save registry and then actual data settings, one of which I use to back up registry and both

If Plex 32 bit writes the registry wrong during install, would this likely mean any of those backup scripts that save the registry would be missing some registry entries, values and seetings?

Or would you think anything plex installers - 64 bit or 32 bit - write into the same plex registry area which I believe is called HKCU\SOFTWARE\Plex, Inc

Many thanks for making my DB work again

Best regards

On Sat, 4 May 2024 at 00:07, danrahn @.***> wrote:

I'd avoid trying any partial copy/pasting and use the entire script directly. You can find the "raw" version here, which you can copy/paste in its entirety, or right-click > Save as: raw.githubusercontent.com/danrahn/PlexDBRepair/master/DBRepair-Windows.bat .

Also, as a future tip, if you paste code in a comment, you can surround it with three backticks to keep the formatting:

Your
Code
Here

becomes

Your Code Here

— Reply to this email directly, view it on GitHub https://github.com/ChuckPa/PlexDBRepair/issues/143#issuecomment-2093870610, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4EE4ERU4V6T3ZWC2THQXLZAQKCBAVCNFSM6AAAAABGZJHPOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJTHA3TANRRGA . You are receiving this because you were mentioned.Message ID: @.***>

-- Thanks and regards Chris

ChuckPa commented 6 months ago

As I shared earlier. HKLM vs HKCU are the delineators.

(new versus old installers).

Not sure how windows handles the differences.

There's also a 'wow6432' out there.

Hope you gents can figure this out. My best windows skill is :bomb: lol

danrahn commented 6 months ago

would this likely mean any of those backup scripts that save the registry would be missing some registry entries, values and seetings?

From what I've seen, it's only InstallFolder that might be in HKLM instead of HKCU, but it's not something I've tested heavily. But that does still mean it's possible those backup scripts aren't capturing everything if they also aren't checking whether HKLM\SOFTWARE\Plex, Inc. (or apparently HKLM\SOFTWARE\WOW6432Node\Plex, Inc. as well, based on Chuck's new info).

ChuckPa commented 6 months ago

It's very likely they can be.

Any registry grab worth its salt should know to check the return value from the REG call to confirm it's a valid location