mirror of
https://github.com/ChuckPa/PlexDBRepair.git
synced 2025-11-06 03:08:55 -05:00
Merge pull request #147 from ChuckPa/chuckpa/manual-config
Allow running DBRepair in non-standard/unknown locations
This commit is contained in:
commit
ec7e04dc35
@ -7,7 +7,9 @@ REM
|
||||
REM -- WARNNING -- WARNING -- WARNING
|
||||
REM
|
||||
REM This is stable working software but not "Released" software. Development will continue.
|
||||
REM
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM ### Create Timestamp
|
||||
set Hour=%time:~0,2%
|
||||
set Min=%time:~3,2%
|
||||
@ -34,16 +36,34 @@ if not exist "%PlexData%" (
|
||||
|
||||
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 InstallFolder might be set under HKLM, not HKCU
|
||||
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"
|
||||
)
|
||||
|
||||
REM If InstallFolder wasn't set, or the resulting file doesn't exist, iterate through the
|
||||
REM PROGRAMFILES variables looking for it. If we still can't find it, ask the user to provide it.
|
||||
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.
|
||||
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
|
||||
set "DBtmp=%PlexData%\dbtmp"
|
||||
|
||||
Binary file not shown.
152
DBRepair.sh
152
DBRepair.sh
@ -2,15 +2,12 @@
|
||||
#########################################################################
|
||||
# Plex Media Server database check and repair utility script. #
|
||||
# Maintainer: ChuckPa #
|
||||
# Version: v1.05.02 #
|
||||
# Date: 26-Mar-2024 #
|
||||
# Version: v1.06.00 #
|
||||
# Date: 01-May-2024 #
|
||||
#########################################################################
|
||||
|
||||
# Version for display purposes
|
||||
Version="v1.05.02"
|
||||
|
||||
# Flag when temp files are to be retained
|
||||
Retain=0
|
||||
Version="v1.06.00"
|
||||
|
||||
# Have the databases passed integrity checks
|
||||
CheckedDB=0
|
||||
@ -39,6 +36,7 @@ CPPL=com.plexapp.plugins.library
|
||||
TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")"
|
||||
|
||||
# Initialize global runtime variables
|
||||
ManualConfig=0
|
||||
CheckedDB=0
|
||||
Damaged=0
|
||||
DbPageSize=0
|
||||
@ -49,6 +47,15 @@ LOG_TOOL="echo"
|
||||
ShowMenu=1
|
||||
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
|
||||
Output() {
|
||||
if [ $Scripted -gt 0 ]; then
|
||||
@ -363,6 +370,15 @@ HostConfig() {
|
||||
# On all hosts except QNAP
|
||||
DFFLAGS="-m"
|
||||
|
||||
# Manual Config
|
||||
if [ $ManualConfig -eq 1 ]; then
|
||||
|
||||
CacheDir="$DBDIR/../../Cache"
|
||||
Logfile="$DBDIR/DBRepair.log"
|
||||
HostType="MANUAL"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Synology (DSM 7)
|
||||
if [ -d /var/packages/PlexMediaServer ] && \
|
||||
[ -d "/var/packages/PlexMediaServer/shares/PlexMediaServer/AppData/Plex Media Server" ]; then
|
||||
@ -1043,7 +1059,7 @@ DoRepair() {
|
||||
[ -e $CPPL.blobs.db ] && mv $CPPL.blobs.db "$TMPDIR/$CPPL.blobs.db-BACKUP-$TimeStamp"
|
||||
|
||||
Output "Making repaired databases active"
|
||||
WriteLog "Making repaired databases active"
|
||||
WriteLog "Repair - Making repaired databases active"
|
||||
mv "$TMPDIR/$CPPL.db-REPAIR-$TimeStamp" $CPPL.db
|
||||
mv "$TMPDIR/$CPPL.blobs.db-REPAIR-$TimeStamp" $CPPL.blobs.db
|
||||
|
||||
@ -1095,7 +1111,6 @@ DoRepair() {
|
||||
Output "Repair has failed. No files changed"
|
||||
WriteLog "Repair - $TimeStamp - FAIL"
|
||||
CheckedDB=0
|
||||
Retain=1
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@ -1529,16 +1544,10 @@ DoStop(){
|
||||
}
|
||||
|
||||
# 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
|
||||
DoUpdateTimestamp() {
|
||||
@ -1644,16 +1653,76 @@ ScriptWorkingDirectory="$(dirname "$ScriptPath")"
|
||||
# Initialize LastName LastTimestamp
|
||||
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)
|
||||
Scripted=0
|
||||
[ "$1" != "" ] && Scripted=1
|
||||
|
||||
# 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 ' Current supported container images: Plexinc, LinuxServer, HotIO, & BINHEX'
|
||||
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
|
||||
fi
|
||||
|
||||
@ -1676,13 +1745,6 @@ echo " "
|
||||
WriteLog "============================================================"
|
||||
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
|
||||
touch "$LOGFILE"
|
||||
|
||||
@ -1743,6 +1805,13 @@ do
|
||||
echo " Version $Version"
|
||||
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
|
||||
|
||||
@ -1785,24 +1854,9 @@ do
|
||||
if [ $Scripted -eq 0 ]; then
|
||||
echo ""
|
||||
printf "Enter command # -or- command name (4 char min) : "
|
||||
else
|
||||
Input="$1"
|
||||
|
||||
# If end of line then force exit
|
||||
if [ "$Input" = "" ]; then
|
||||
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
|
||||
# Read next command from user
|
||||
read Input
|
||||
|
||||
# Handle EOF/forced exit
|
||||
if [ "$Input" = "" ] ; then
|
||||
@ -1817,6 +1871,18 @@ do
|
||||
else
|
||||
NullCommands=0
|
||||
fi
|
||||
else
|
||||
|
||||
# Scripted
|
||||
Input="$1"
|
||||
|
||||
# If end of line then force exit
|
||||
if [ "$Input" = "" ]; then
|
||||
Input="exit"
|
||||
else
|
||||
shift
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Update timestamp
|
||||
|
||||
17
README.md
17
README.md
@ -293,6 +293,8 @@ Attention:
|
||||
|
||||
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
|
||||
|
||||
@ -850,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
|
||||
|
||||
Using DBRepair on Synology DSM 7 systems with Task Scheduler requires special handling.
|
||||
|
||||
24
ReleaseNotes
24
ReleaseNotes
@ -8,9 +8,31 @@
|
||||

|
||||
|
||||
# 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.bat now finds 32 bit PMS when installed on 64 bit Windows systems.
|
||||
|
||||
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.
|
||||
|
||||
v1.05.01
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user