mirror of
https://github.com/ChuckPa/PlexDBRepair.git
synced 2025-11-06 03:08:55 -05:00
Merge pull request #28 from ChuckPa/ChuckPa/DBRepair-Windows-dev
Put Windows Development code on master
This commit is contained in:
commit
74a9b9e153
148
DBRepair-WinDev.bat
Normal file
148
DBRepair-WinDev.bat
Normal file
@ -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
|
||||||
BIN
DBRepair-Windows.zip
Normal file
BIN
DBRepair-Windows.zip
Normal file
Binary file not shown.
44
DBRepair.sh
44
DBRepair.sh
@ -396,35 +396,31 @@ HostConfig() {
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
# Docker
|
# Docker (All main docker variants except binhex)
|
||||||
elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] || [ "$(grep 0::/ /proc/1/cgroup)" = "0::/" ]; then
|
elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] && [ -d "/config/Library/Application Support" ]; then
|
||||||
|
|
||||||
# Docker (All main docker variants except binhex)
|
PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite"
|
||||||
if [ -d "/config/Library/Application Support" ]; then
|
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"
|
HostType="Docker"
|
||||||
AppSuppDir="/config/Library/Application Support"
|
return 0
|
||||||
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"
|
# BINHEX Plex container
|
||||||
return 0
|
elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] && [ -d "/config/Plex Media Server" ]; then
|
||||||
|
|
||||||
# BINHEX Plex container
|
PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite"
|
||||||
elif [ -d "/config/Plex Media Server" ]; then
|
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"
|
HostType="BINHEX"
|
||||||
AppSuppDir="/config"
|
return 0
|
||||||
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
|
|
||||||
|
|
||||||
# Western Digital (OS5)
|
# Western Digital (OS5)
|
||||||
elif [ -f /etc/system.conf ] && [ -d /mnt/HD/HD_a2/Nas_Prog/plexmediaserver ] && \
|
elif [ -f /etc/system.conf ] && [ -d /mnt/HD/HD_a2/Nas_Prog/plexmediaserver ] && \
|
||||||
|
|||||||
8
README.md
Executable file → Normal file
8
README.md
Executable file → Normal file
@ -73,7 +73,8 @@ It is a simple menu-driven utility with a command line backend.
|
|||||||
8. Give the utility 'execute' permission
|
8. Give the utility 'execute' permission
|
||||||
9. Invoke the utility
|
9. Invoke the utility
|
||||||
|
|
||||||
#### To install & launch on Synology DSM 6 (Showing with v0.6.1)
|
|
||||||
|
### To install & launch on Synology DSM 6 (Showing with v0.6.1)
|
||||||
```
|
```
|
||||||
cd /volume1/Plex
|
cd /volume1/Plex
|
||||||
sudo bash
|
sudo bash
|
||||||
@ -118,8 +119,9 @@ It is a simple menu-driven utility with a command line backend.
|
|||||||
```
|
```
|
||||||
osascript -e 'quit app "Plex Media Server"'
|
osascript -e 'quit app "Plex Media Server"'
|
||||||
cd ~/Downloads
|
cd ~/Downloads
|
||||||
tar xvf PlexDBRepair-0.6.1.tar.gz
|
tar xvf PlexDBRepai PlexDBRepair-0.6.1.tar.gz
|
||||||
cd PlexDBRepair-1.0.7
|
cd PlexDBRepai PlexDBRepair-0.6.1
|
||||||
|
|
||||||
chmod +x DBRepair.sh
|
chmod +x DBRepair.sh
|
||||||
./DBRepair.sh
|
./DBRepair.sh
|
||||||
```
|
```
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user