From d4005fba1527353537bf9b360b717891d1fad288 Mon Sep 17 00:00:00 2001 From: ChuckPa Date: Sat, 24 Dec 2022 19:21:43 -0500 Subject: [PATCH] . --- DBRepair-WinDev.bat | 148 +++++++++++++++++++++++++++++++++++++++++++ DBRepair-Windows.zip | Bin 0 -> 1597 bytes DBRepair.sh | 44 ++++++------- README.md | 34 ++++++---- 4 files changed, 189 insertions(+), 37 deletions(-) create mode 100644 DBRepair-WinDev.bat create mode 100644 DBRepair-Windows.zip diff --git a/DBRepair-WinDev.bat b/DBRepair-WinDev.bat new file mode 100644 index 0000000..a941056 --- /dev/null +++ b/DBRepair-WinDev.bat @@ -0,0 +1,148 @@ +@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 1. This is stable working software but not "Released" software. Development will continue. +REM 2. You must ensure variable PlexData points to your databases. (there is no automatic detection at this time) +REM +REM System format controls ^Roll_eyes^ +set TimeStamp=%date:~10,4%-%date:~+4,2%-%date:~+7,2%_%time:~0,2%.%time:~3,2%.%time:~6,2% + +REM These assume PMS is in the default location +set "PlexData=%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases" +set "PlexSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite" +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%" + +mkdir "%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 diff --git a/DBRepair-Windows.zip b/DBRepair-Windows.zip new file mode 100644 index 0000000000000000000000000000000000000000..d98f6ac68d2e4aa4a9adfa59436ddb41177df78a GIT binary patch literal 1597 zcmZ{leLT|%9LIk)bE-pTF8Q^E39wA{il-MJFzR_;3+W>HMUa7ywS8V^7_#J?P;uIJF z{x*T zHm5zo%-lXbUBG^4Dic|yJU`#dxQFQ51&F zLMJGi)^SRRgAq*vyDW3A<$SHI!F^^y%+bBT<1p2IIP5)0WZQ7zs}JNw^vxGnt{Zpx zf35bzhCW5BEDKN1PpbHeZ9QLi=)RCr z9^?wA2q{L$-WnZ;$~I3e<{L+wG#qq{)l)vDT4m5;qJI#cH)Nd<`5V6r#ZEz|d|qNE zdp7^^$M|fQyodLR7DPo?$z(Jr*mLDya!yH2ZWc0QqI6jzO?~6I$PkY3SJK+;HG<<>JMV zd0az??9p)Pi2H|+cVB70$#6egt_}^_zGHojXn6RpKI#UGXh z1-M~3awiCuJ^8?wbKhYzQCSZUeJvPpW+!FB7Z%BIu|r0AHDUlFMI>Q%h*mGf?!KrP z`#gp>67~*XMKxu87;^-lH^0*FG5!4NRG8i_r?S_81?^rtteKwuYeFRR)wteuCx=$C zIl@%+cKvr|JnM*OYWp;HU};=oR_lTGOe@XwhldR^4!xbV2+?_8I51!mQW}0!f^0S# zPbU=eQnUaZlumQ*_XaRi#$zx5Fb3 zl^|E!QNqhNgH=wD3Q#U9XH(df#>~<0HB{CUEkyh0dirt-^mwU1^1QX*Os4jHK}OUc zzXy@3el#C_r=hG!h~t>hJ~p$3r{_IQPYQ;_pzo-K(o`wrI*NFC5L=JoV%JFZw6asu z_B9G))@sRr6+_Y8Oipx}IjZ&Wwn%60L$y~+)yjOzVEbxX+BGiAo{$?~QsikG_CAV7 zsZaczc4ylA*t40VsZT_o0kuhT-2J{bn$v`DS)oL=ki7Elc2b7| zh%$5L&G#p3rLmzFF}ui*tmw+cP-D_Q z`Q4F#BS}QWp5Akze#zf_26Z4KiBs=Mwf4br^-Ig;4|B+a>e$H(cayDtAAw^Cw^r9) zi~SrW==0S|PyNsMoh%7{mr}r7JCZIPT!gC6eBbP!_X79JI?>y1biGY-be04iBv~~v zH8Z}zb-b0ki2DQiYSsDWPiE$bfz#PxB3HplK{lpjBKk?~!LU7-e%gC3Fso6sa77Zs z?RSt#pL+b(q-&5wNL-!vlB8C|r?1?D3-TS|;{I1=eRY~;4J~_*whRL(a^dbx1!ueh t2nqf_o^L^YOA1@fXZ*GOC*2|c(EVRzcg91M{yI_ED$>>zZG{8?{0Z>C?%n_Z literal 0 HcmV?d00001 diff --git a/DBRepair.sh b/DBRepair.sh index 0b6e1d2..1678e44 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -396,35 +396,31 @@ HostConfig() { return 0 - # Docker - elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] || [ "$(grep 0::/ /proc/1/cgroup)" = "0::/" ]; then + # Docker (All main docker variants except binhex) + elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] && [ -d "/config/Library/Application Support" ]; then - # Docker (All main docker variants except binhex) - if [ -d "/config/Library/Application Support" ]; then + PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite" + AppSuppDir="/config/Library/Application Support" + PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" + DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases" + LOGFILE="$DBDIR/DBRepair.log" + LOG_TOOL="logger" - PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite" - AppSuppDir="/config/Library/Application Support" - PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" - DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases" - LOGFILE="$DBDIR/DBRepair.log" - LOG_TOOL="logger" + HostType="Docker" + return 0 - HostType="Docker" - return 0 + # BINHEX Plex container + elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] && [ -d "/config/Plex Media Server" ]; then - # BINHEX Plex container - elif [ -d "/config/Plex Media Server" ]; then + PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite" + AppSuppDir="/config" + PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" + DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases" + LOGFILE="$DBDIR/DBRepair.log" + LOG_TOOL="logger" - PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite" - AppSuppDir="/config" - PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" - DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases" - LOGFILE="$DBDIR/DBRepair.log" - LOG_TOOL="logger" - - HostType="BINHEX" - return 0 - fi + HostType="BINHEX" + return 0 # Western Digital (OS5) elif [ -f /etc/system.conf ] && [ -d /mnt/HD/HD_a2/Nas_Prog/plexmediaserver ] && \ diff --git a/README.md b/README.md index 50b9f54..9808b5b 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![master](https://img.shields.io/badge/master-stable-green.svg?maxAge=2592000)]('') ![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg) -# Introduction +## Introduction DBRepair provides database repair and maintenance for the most common Plex Media Server database problems. It is a simple menu-driven utility with a command line backend. @@ -62,18 +62,23 @@ It is a simple menu-driven utility with a command line backend. ``` -### To install & launch on general Linux or most Linux NAS platforms: - 1. Place the tar/zip/sh file in the appropriate directory - 2. Open a command line session (usually SSH) - 3. Elevate privilege level to root - 4. Extract the utility from the tar or zip file - 4. Invoke the utility +### To install & launch on general Linux or most Linux NAS platforms: (Showing with v0.6.1) + 1. Open your browser to https://github.com/ChuckPa/PlexDBRepair/releases/latest + 2. Download the source code (tar.gz) file + 3. Place the tar.gz file in the appropriate directory on the system you'll use it. + 4. Open a command line session (usually Terminal or SSH) + 5. Elevate privilege level to root (sudo) + 6. Extract the utility from the tar or zip file + 7. 'cd' into the extraction directory + 8. Give the utility 'execute' permission + 9. Invoke the utility -#### (Synology DSM 6 used as example) +#### (Synology DSM 6 and version v0.6.1 used as example) ``` cd /volume1/Plex sudo bash - tar xf DBRepair.tar.gz + tar xf PlexDBRepair-0.6.1.tar.gz + cd PlexDBRepair-0.6.1 chmod +x DBRepair.sh ./DBRepair.sh ``` @@ -93,7 +98,8 @@ It is a simple menu-driven utility with a command line backend. - tar xf DBRepair.tar.gz + tar xf PlexDBRepair-0.6.1.tar.gz + cd PlexDBRepair-0.6.1 chmod +x DBRepair.sh ./DBRepair.sh ``` @@ -102,7 +108,9 @@ It is a simple menu-driven utility with a command line backend. sudo bash systemctl stop plexmediaserver cd /path/to/DBRepair.tar - tar xf DBRepair.tar.gz + tar xf PlexDBRepair-0.6.1.tar.gz + cd PlexDBRepair-0.6.1 + chmod +x DBRepair.sh ./DBRepair.sh ``` @@ -110,8 +118,8 @@ It is a simple menu-driven utility with a command line backend. ``` osascript -e 'quit app "Plex Media Server"' cd ~/Downloads - tar xvf PlexDBRepair-0.3.4.tar.gz - cd PlexDBRepair-0.3.4 + tar xvf PlexDBRepai PlexDBRepair-0.6.1.tar.gz + cd PlexDBRepai PlexDBRepair-0.6.1 chmod +x DBRepair.sh ./DBRepair.sh ```