1.  Add  Start/Stop support for Binhex containers
1.  Restart after update (optional)
2.  Remove DEFLATE (PMS 1.41.8)
This commit is contained in:
ChuckPa 2025-06-01 20:19:45 -04:00
parent 65f4e5d33d
commit baf8398085
No known key found for this signature in database
GPG Key ID: 38D684FFA607AF70
3 changed files with 44 additions and 127 deletions

View File

@ -2,12 +2,12 @@
#########################################################################
# Database Repair Utility for Plex Media Server. #
# Maintainer: ChuckPa #
# Version: v1.11.03 #
# Date: 31-May-2025 #
# Version: v1.11.04 #
# Date: 03-Jun-2025 #
#########################################################################
# Version for display purposes
Version="v1.11.03"
Version="v1.11.04"
# Have the databases passed integrity checks
CheckedDB=0
@ -716,6 +716,12 @@ HostConfig() {
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
if grep rpcinterface /etc/supervisor.conf > /dev/null; then
HaveStartStop=1
StartCommand="supervisorctl start plexmediaserver"
StopCommand="supervisorctl stop plexmediaserver"
fi
HostType="BINHEX"
return 0
@ -1738,74 +1744,6 @@ DoPrunePhotoTranscoder() {
}
##### Special function
# Remove bloat records from PMS database on a full disk
DoDeflate() {
if IsRunning; then
Output "Please stop PMS first and try again."
return 1
fi
# Get into DBDIR
cd "$DBDIR"
# Run this loop until we get a partial block
Removed=100000000
Limit=100000000
TotalRemoved=0
# Turn it off
Result="$("$PLEX_SQLITE" "$CPPL.db" 'PRAGMA journal_mode = off;')"
InitialSize=$(stat $STATFMT $STATBYTES $CPPL.db)
SQL="PRAGMA journal_mode = off;"
SQL="$SQL Begin transaction; "
SQL="$SQL DELETE from statistics_bandwidth where rowid in ("
SQL="$SQL select rowid from statistics_bandwidth where account_id is null limit 100000000 );"
SQL="$SQL Commit;"
SQL="$SQL select changes();"
Count=1
while [ $Removed -eq $Limit ]
do
Output "Removing - block $Count"
Removed=$("$PLEX_SQLITE" "$CPPL.db" "$SQL" | tail -1)
TotalRemoved=$((TotalRemoved + Removed))
Count=$((Count+1))
done
Output "Removed $TotalRemoved records."
Output "Vacuuming DB to reclaim working space."
"$PLEX_SQLITE" "$CPPL.db" "vacuum;"
Result=$?
if [ $Result -ne 0 ]; then
Output "ERROR: Unable to shrink database size. Error $Result"
WriteLog "Deflate - ERROR. Unable to shrink database size. ERROR $Result"
WriteLog "Deflate - FAIL."
return 1
fi
# Check size
Size=$(stat $STATFMT $STATBYTES $CPPL.db)
Output "Initial Database size = $((InitialSize / 1000000)) MB"
Output "Final Database size = $((Size / 1000000)) MB"
# Turn journal mode back on
Result="$("$PLEX_SQLITE" "$CPPL.db" "PRAGMA journal_mode = WAL;")"
# Now write abbreviated log entries
WriteLog "Deflate - Report."
WriteLog "Deflate - Initial Database size = $((InitialSize / 1000000)) MB"
WriteLog "Deflate - Final Database size = $((Size / 1000000)) MB"
WriteLog "Deflate - Records Removed = $TotalRemoved"
WriteLog "Deflate - PASS."
}
#############################################################
# Main utility begins here #
#############################################################
@ -2083,12 +2021,8 @@ do
# Automatic of all common operations
2|auto*)
# Get current status
RunState=0
# Check if PMS running
if IsRunning; then
RunState=1
WriteLog "Auto - FAIL - PMS runnning"
Output "Unable to run automatic sequence. PMS is running. Please stop PlexMediaServer."
continue
@ -2380,6 +2314,13 @@ do
88|upda*)
# Don't update again after restarting after updating
if [ "$DBRepairRestartedAfterUpdate" = "1" ]; then
Output "Already updated. Continuing."
WriteLog "Update - Ignore Update request after updating."
continue
fi
DoUpdate=0
Output "Checking for update"
GetLatestRelease
@ -2401,8 +2342,15 @@ do
Result=$?
if [ $Result -eq 0 ]; then
chmod +x "$ScriptWorkingDirectory/$ScriptName"
if [ $Scripted -eq 0 ] && ConfirmYesNo "Restart and use $LatestVersion ?" ; then
WriteLog "Restarting after upgrade"
Output "Restarting"
export DBRepairRestartedAfterUpdate="1"
exec "$0" "$@"
else
Output "Restart to launch updated DBRepair.sh ($LatestVersion)"
WriteLog "Update - Updated to version $LatestVersion."
fi
exit 0
else
Output "Unable to download and update. Error $Result."
@ -2456,21 +2404,6 @@ do
exit 0
;;
# Deflate
911|defl*)
Output "This command operates directly on your existing PMS DB."
Output "There are no backups however the DB is protected by transaction blocking."
Output "DO NOT INTERRUPT once started but you can if you must (It will resume where it left off)."
Output " "
if ! ConfirmYesNo "Ok to begin deflating the databases?" ; then
Output "No action taken."
WriteLog "Deflate - No action taken."
else
DoDeflate
fi
;;
# Unknown command
*)
WriteLog "Unknown command: '$Input'"

View File

@ -75,10 +75,8 @@ If sufficient privleges exist (root), and supported by the environment, the opti
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
911 - 'deflate' - Deflate a bloated PMS database (Temporary special function)
98 - 'quit' - Quit immediately. Keep all temporary files.
99 'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) :
@ -356,8 +354,8 @@ Select
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
98 - 'quit' - Quit immediately. Keep all temporary files.
99 - 'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : 1
@ -384,8 +382,8 @@ Select
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
98 - 'quit' - Quit immediately. Keep all temporary files.
99 - 'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : auto
@ -438,8 +436,8 @@ Select
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
98 - 'quit' - Quit immediately. Keep all temporary files.
99 - 'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : start
@ -466,8 +464,8 @@ Select
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
98 - 'quit' - Quit immediately. Keep all temporary files.
99 - 'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : stat
@ -497,8 +495,8 @@ Select
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
98 - 'quit' - Quit immediately. Keep all temporary files.
99 - 'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : exit
@ -943,8 +941,8 @@ Select
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
98 - 'quit' - Quit immediately. Keep all temporary files.
99 - 'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) :
```

View File

@ -8,27 +8,13 @@
![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg)
# Release Info:
v1.11.03 - Add log entries for DEFLATE
v1.11.04
v1.11.02 - Special release
1. Binhex start/stop - Add support for stopping and starting PMS in Binhex containers.
1. Restart after update - Add option to restart after live updating.
2. Remove temp Deflate - Remove deflate function as of PMS 1.41.8 availability
1. Database bloat - (Enh) A better method was found to handle bloat processing.
This new method works on SSD/HDDs where the disk is full and PMS can't run.
There is no free space required to perform this task.
Each "block" being removed is 100 million records.
The CPU will have one core maxed at 100% for the duration.
Before & after info will be printed after final cleanup is finished.
New command name: Deflate ( # 911 )
v1.11.01
1. Database bloat - (New) Database bloat processing now surrounded by TRANSACTION/COMMIT to speed processing.
2. Space Needed - (Fix) Handle cases where "Databases" directory is not on the same volume as AppSuppDir.
3. Menu options - (New) Add option 98 = quit. Rename 99 = exit.
4. Reporting - (Fix) When insufficient space available, Now print out how much is needed
v1.11.01 - v1.11.03 - Temporary versions to assist PMS database bloat issue.
v1.11.00