Compare commits

..

5 Commits

Author SHA1 Message Date
ChuckPa
d0084c96fb Manual config support
See Release notes about --sqlite and --databases options.
2024-05-05 01:22:32 -04:00
Chuck
ec7e04dc35 Merge pull request #147 from ChuckPa/chuckpa/manual-config
Allow running DBRepair in non-standard/unknown locations
2024-05-05 00:58:00 -04:00
ChuckPa
1a3228e648 Windows: Make path discovery better
DBRepair (Win)  now understands mixed mode (32 bit on 64 bit OS)
2024-05-05 00:51:52 -04:00
ChuckPa
852fdfc0d5 Manual mode - Initial commit 2024-05-01 02:02:32 -04:00
ChuckPa
ee8556d0f9 Update README.md 2024-04-23 22:04:52 -04:00
5 changed files with 194 additions and 67 deletions

View File

@@ -7,7 +7,9 @@ REM
REM -- WARNNING -- WARNING -- WARNING REM -- WARNNING -- WARNING -- WARNING
REM REM
REM This is stable working software but not "Released" software. Development will continue. REM This is stable working software but not "Released" software. Development will continue.
REM
setlocal enabledelayedexpansion
REM ### Create Timestamp REM ### Create Timestamp
set Hour=%time:~0,2% set Hour=%time:~0,2%
set Min=%time:~3,2% set Min=%time:~3,2%
@@ -22,27 +24,45 @@ set TimeStamp=%Hour%-%Min%-%Sec%
REM Find PMS database location 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" 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 not exist "%PlexData%" (
if exist "%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases" ( if exist "%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases" (
set "PlexData=%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases" set "PlexData=%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases"
) else ( ) else (
echo Could not determine Plex database path. echo Could not determine Plex database path.
echo Normally %LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases echo Normally %LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases
echo. echo.
goto :EOF goto :EOF
) )
) )
REM Find PMS installation 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" 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 not exist "%PlexSQL%" (
if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" ( REM InstallFolder might be set under HKLM, not HKCU
set "PlexSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKLM\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PlexSQL=%%b\Plex SQLite.exe"
) else ( )
echo Could not determine SQLite path.
echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe REM If InstallFolder wasn't set, or the resulting file doesn't exist, iterate through the
echo. REM PROGRAMFILES variables looking for it. If we still can't find it, ask the user to provide it.
goto :EOF 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 (
if exist "%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe" (
echo NOTE: 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 (
echo Could not determine SQLite path. Please provide it below
echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe
echo.
REM Last ditch effort, ask the user for the full path to Plex SQLite.exe
set /p "PlexSQL=Path to Plex SQLite.exe: "
if not exist "!PlexSQL!" (
echo "!PlexSQL!" could not be found. Cannot continue.
goto :EOF
)
)
)
) )
REM Set temporary file locations REM Set temporary file locations

Binary file not shown.

View File

@@ -2,15 +2,12 @@
######################################################################### #########################################################################
# Plex Media Server database check and repair utility script. # # Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa # # Maintainer: ChuckPa #
# Version: v1.05.02 # # Version: v1.06.00 #
# Date: 26-Mar-2024 # # Date: 01-May-2024 #
######################################################################### #########################################################################
# Version for display purposes # Version for display purposes
Version="v1.05.02" Version="v1.06.00"
# Flag when temp files are to be retained
Retain=0
# Have the databases passed integrity checks # Have the databases passed integrity checks
CheckedDB=0 CheckedDB=0
@@ -39,6 +36,7 @@ CPPL=com.plexapp.plugins.library
TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")" TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")"
# Initialize global runtime variables # Initialize global runtime variables
ManualConfig=0
CheckedDB=0 CheckedDB=0
Damaged=0 Damaged=0
DbPageSize=0 DbPageSize=0
@@ -49,6 +47,15 @@ LOG_TOOL="echo"
ShowMenu=1 ShowMenu=1
Exit=0 Exit=0
# On all hosts except Mac
PIDOF="pidof"
STATFMT="-c"
STATBYTES="%s"
STATPERMS="%a"
# On all hosts except QNAP
DFFLAGS="-m"
# Universal output function # Universal output function
Output() { Output() {
if [ $Scripted -gt 0 ]; then if [ $Scripted -gt 0 ]; then
@@ -363,6 +370,15 @@ HostConfig() {
# On all hosts except QNAP # On all hosts except QNAP
DFFLAGS="-m" DFFLAGS="-m"
# Manual Config
if [ $ManualConfig -eq 1 ]; then
CacheDir="$DBDIR/../../Cache"
Logfile="$DBDIR/DBRepair.log"
HostType="MANUAL"
return 0
fi
# Synology (DSM 7) # Synology (DSM 7)
if [ -d /var/packages/PlexMediaServer ] && \ if [ -d /var/packages/PlexMediaServer ] && \
[ -d "/var/packages/PlexMediaServer/shares/PlexMediaServer/AppData/Plex Media Server" ]; then [ -d "/var/packages/PlexMediaServer/shares/PlexMediaServer/AppData/Plex Media Server" ]; then
@@ -1095,7 +1111,6 @@ DoRepair() {
Output "Repair has failed. No files changed" Output "Repair has failed. No files changed"
WriteLog "Repair - $TimeStamp - FAIL" WriteLog "Repair - $TimeStamp - FAIL"
CheckedDB=0 CheckedDB=0
Retain=1
return 1 return 1
fi fi
} }
@@ -1529,16 +1544,10 @@ DoStop(){
} }
# Do command line switches # Do command line switches
DoOptions() { #DoOptions() {
for i in $@
do #}
Opt="$(echo $i | cut -c1-2 | tr [A-Z] [a-z])"
[ "$Opt" = "-i" ] && IgnoreErrors=1 && WriteLog "Opt: Database error checking ignored."
[ "$Opt" = "-f" ] && IgnoreErrors=1 && WriteLog "Opt: Database error checking ignored."
[ "$Opt" = "-p" ] && RemoveDuplicates=1 && WriteLog "Opt: Remove duplidate watch history viewstates."
done
}
# UpdateTimestamp # UpdateTimestamp
DoUpdateTimestamp() { DoUpdateTimestamp() {
@@ -1644,16 +1653,76 @@ ScriptWorkingDirectory="$(dirname "$ScriptPath")"
# Initialize LastName LastTimestamp # Initialize LastName LastTimestamp
SetLast "" "" SetLast "" ""
# Process any given command line options in the ugliest manner possible :P~~
while [ "$(echo $1 | cut -c1)" = "-" ] && [ "$1" != "" ]
do
Opt="$(echo $1 | awk '{print $1'} | tr [A-Z] [a-z])"
[ "$Opt" = "-i" ] && shift
[ "$Opt" = "-f" ] && shift
[ "$Opt" = "-p" ] && shift
# Manual configuration options (running outside of container)
if [ "$Opt" = "--sqlite" ]; then
# Manually specify path to where Plex SQLite is installed.
if [ -d "$2" ] && [ -f "$2/Plex SQLite" ]; then
PLEX_SQLITE="$2/Plex SQLite"
ManualConfig=1
else
Output "Given directory path ('$1') for Plex SQLite is invalid. Ignoring."
fi
shift 2
fi
# Manual path to databases
if [ "$Opt" = "--databases" ]; then
# Manually specify path to where the databases reside
if [ -d "$2" ] && [ -f "$2"/com.plexapp.plugins.library.db ]; then
DBDIR="$2"
ManualConfig=1
LOGFILE="$DBDIR/DBRepair.log"
AppSuppDir="$( dirname "$(dirname "$(dirname "$db")))")")"
else
Output "Given directory path ('$1') for Plex databases is invalid. Ignoring."
fi
shift 2
fi
done
# Confirm completed manual config
if [ $ManualConfig -eq 1 ]; then
if [ "$DBDIR" = "" ] || [ "$PLEX_SQLITE" = "" ]; then
Output "Error: Both 'Plex SQLite' and Databases directory paths must be specified with Manual configuration."
WriteLog "Manual configuration incomplete. One of the required arguments was missing."
exit 2
fi
# Performing logging here
[ $IgnoreErrors -eq 1 ] && WriteLog "Opt: Database error checking ignored."
[ $RemoveDuplicates -eq 1 ] && WriteLog "Opt: Remove duplidate watch history viewstates."
WriteLog "Plex SQLite = '$PLEX_SQLITE'"
WriteLog "Databases = '$DBDIR'"
# Final configuration
HostType="User Defined"
fi
# Are we scripted (command line args) # Are we scripted (command line args)
Scripted=0 Scripted=0
[ "$1" != "" ] && Scripted=1 [ "$1" != "" ] && Scripted=1
# Identify this host # Identify this host
if ! HostConfig; then if [ $ManualConfig -eq 0 ] && ! HostConfig; then
Output 'Error: Unknown host. Current supported hosts are: QNAP, Syno, Netgear, Mac, ASUSTOR, WD (OS5), Linux wkstn/svr, SNAP' Output 'Error: Unknown host. Current supported hosts are: QNAP, Syno, Netgear, Mac, ASUSTOR, WD (OS5), Linux wkstn/svr, SNAP'
Output ' Current supported container images: Plexinc, LinuxServer, HotIO, & BINHEX' Output ' Current supported container images: Plexinc, LinuxServer, HotIO, & BINHEX'
Output ' ' Output ' '
Output 'Are you trying to run the tool from outside the container environment ?' Output 'Are you trying to run the tool from outside the container environment? Manual mode is available. Please see documentation.'
exit 1 exit 1
fi fi
@@ -1676,13 +1745,6 @@ echo " "
WriteLog "============================================================" WriteLog "============================================================"
WriteLog "Session start: Host is $HostType" WriteLog "Session start: Host is $HostType"
# Command line hidden options must come before commands
while [ "$(echo $1 | cut -c1)" = "-" ]
do
DoOptions "$1"
shift
done
# Make sure we have a logfile # Make sure we have a logfile
touch "$LOGFILE" touch "$LOGFILE"
@@ -1743,6 +1805,13 @@ do
echo " Version $Version" echo " Version $Version"
echo " " echo " "
# Print info if Manual
if [ $ManualConfig -eq 1 ]; then
WriteLog "Manual SQLite path: '$PLEX_SQLITE'
WriteLog "Manual Database path: '$DBDIR'
Output " PlexSQLite = '$PLEX_SQLITE'"
Output " Databases = '$DBDIR'"
fi
Choice=0; Exit=0; NullCommands=0 Choice=0; Exit=0; NullCommands=0
@@ -1785,24 +1854,9 @@ do
if [ $Scripted -eq 0 ]; then if [ $Scripted -eq 0 ]; then
echo "" echo ""
printf "Enter command # -or- command name (4 char min) : " printf "Enter command # -or- command name (4 char min) : "
else
Input="$1"
# If end of line then force exit # Read next command from user
if [ "$Input" = "" ]; then read Input
Input="exit"
Exit=1
Output "Unexpected EOF / End of command line options. Exiting. Keeping temp files."
fi
fi
# Watch for null command whether scripted or not.
if [ "$1" != "" ]; then
Input="$1"
# echo "$1"
shift
else
[ $Scripted -eq 0 ] && read Input
# Handle EOF/forced exit # Handle EOF/forced exit
if [ "$Input" = "" ] ; then if [ "$Input" = "" ] ; then
@@ -1817,6 +1871,18 @@ do
else else
NullCommands=0 NullCommands=0
fi fi
else
# Scripted
Input="$1"
# If end of line then force exit
if [ "$Input" = "" ]; then
Input="exit"
else
shift
fi
fi fi
# Update timestamp # Update timestamp

View File

@@ -148,9 +148,11 @@ Enter command # -or- command name (4 char min) :
### (In the examples below, substitute "x.y.z" with the actual version you download/use)
### EXAMPLE: To install & launch on Synology DSM 6 / DSM 7 ### EXAMPLE: To install & launch on Synology DSM 6 / DSM 7
cd /volume1/Plex # use /volume1/PlexMediaServer on DSM 7 cd /volume1/Plex # use /volume1/PlexMediaServer on DSM 7
sudo bash sudo bash
tar xf PlexDBRepair-x.y.z.tar.gz tar xf PlexDBRepair-x.y.z.tar.gz
@@ -165,8 +167,8 @@ Enter command # -or- command name (4 char min) :
sudo docker exec -it plex /bin/bash sudo docker exec -it plex /bin/bash
# extract from downloaded version file name then cd into directory # extract from downloaded version file name then cd into directory
tar xf PlexDBRepair-1.0.0.tar.gz tar xf PlexDBRepair-x.y.z.tar.gz
cd PlexDBRepair-1.0.0 cd PlexDBRepair-x.y.z
chmod +x DBRepair.sh chmod +x DBRepair.sh
./DBRepair.sh ./DBRepair.sh
``` ```
@@ -174,8 +176,8 @@ Enter command # -or- command name (4 char min) :
``` ```
sudo bash sudo bash
cd /path/to/DBRepair.tar cd /path/to/DBRepair.tar
tar xf PlexDBRepair-1.0.0.tar.gz tar xf PlexDBRepair-x.y.z.tar.gz
cd PlexDBRepair-1.0.0 cd PlexDBRepair-x.y.z
chmod +x DBRepair.sh chmod +x DBRepair.sh
./DBRepair.sh stop auto start exit ./DBRepair.sh stop auto start exit
``` ```
@@ -184,8 +186,8 @@ Enter command # -or- command name (4 char min) :
``` ```
osascript -e 'quit app "Plex Media Server"' osascript -e 'quit app "Plex Media Server"'
cd ~/Downloads cd ~/Downloads
tar xvf PlexDBRepai PlexDBRepair-1.0.0.tar.gz tar xvf PlexDBRepai PlexDBRepair-x.y.z.tar.gz
cd PlexDBRepair-1.0.0 cd PlexDBRepair-x.y.z
chmod +x DBRepair.sh chmod +x DBRepair.sh
./DBRepair.sh ./DBRepair.sh
@@ -291,6 +293,8 @@ Attention:
This executes: Stop PMS, Automatic (Check, Repair, Reindex), Start PMS, and Exit commands This executes: Stop PMS, Automatic (Check, Repair, Reindex), Start PMS, and Exit commands
Beginning with v1.06.00, the 'exit' command is optional when scripted.
## Exiting ## Exiting
@@ -495,7 +499,7 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases# ./DBRepair.sh
Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS) Plex Media Server Database Repair Utility (Ubuntu 20.04.5 LTS)
Version v1.0.0 Version v1.03.01
[2023-03-05 18.53.49] Stopping PMS. [2023-03-05 18.53.49] Stopping PMS.
@@ -848,6 +852,21 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases#
# #
``` ```
# Special considerations - MANUAL CONFIGURATION
Manual configuration is enabled by supplying two command line arguments.
These must precede all other options or commands on the command line.
Scripted Example:
DBRepair.sh --sqlite /usr/lib/plexmediaserver --databases /real/host/directory/...../Databases auto prune
Interactive Example:
DBRepair.sh --sqlite /usr/lib/plexmediaserver --databases /real/host/directory/...../Databases
# Special considerations - Synology DSM 7 # Special considerations - Synology DSM 7
Using DBRepair on Synology DSM 7 systems with Task Scheduler requires special handling. Using DBRepair on Synology DSM 7 systems with Task Scheduler requires special handling.

View File

@@ -8,9 +8,31 @@
![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg) ![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg)
# Release Info: # Release Info:
v1.06.00
1. Manual configuration - You may now run DBRepair from outside container environments.
This provides a method for running DBRepair when container healthcheck prevents it.
The directories to both:
a. Where Plex SQLite can be found: ( --sqlite "/real/host/path/to/plexmediaserver/Directory" )
b. Where the databases can be found: ( --databases "/real/host/path/to/Plugin Support/Databases" )
If used, these options MUST precede all other command line options
WARNING: The host MUST provide all standard commands AND support "stat -c" option. Bash commands will NOT autoconfigure.
2. "Exit" when scripted: The previously annoyance which required "exit" to be specified on the command line (scripted) has been fixed.
"exit" is no longer required in this use.
"exit" or "quit" is still required in interactive use.
3. Windows: DBRepair-Windows now supports 32 bit PMS on 64 bit Windows base systems. (Mixed mode operation)
v1.05.02 v1.05.02
1 HOTIO image paths HOTIO images have again changed PMS executable location. This update 1. HOTIO image paths HOTIO images have again changed PMS executable location. This update
adds support for the lastest location. adds support for the lastest location.
v1.05.01 v1.05.01