Compare commits

..

9 Commits

Author SHA1 Message Date
Chuck
abc552fb12
Merge pull request #253 from ChuckPa/chuckpa/readme
Minor Update & Correct documentation for v1.12.00
2025-10-21 17:33:14 -04:00
ChuckPa
aa76cbfefd
Update & Correct documentation for v1.12 2025-10-21 17:26:46 -04:00
Chuck
d79b5e2b9d
Merge pull request #252 from ChuckPa/chuckpa/dodeflate
v1.12.00 - Add  Deflate command

Reconstruct bandwidth statistics table  row  by row instead of previous bulk copy of non-null values
Regenerate new IDs during reconstruction for new indexes and reindex
2025-10-20 22:28:24 -04:00
ChuckPa
3bfb510ef7
Documentation correction
ASUSTOR - Incorrect location
2025-10-20 22:12:45 -04:00
ChuckPa
247338278b
Add Deflate command
Deflate
- Create new bandwidth_statistics table with proper schema.
- Transfer only valid data from existing bandwidth statistics into new.
- Drop old table.
- Vacuum into new database.
Merge Prune & Purge as one proper command
Update ASUSTOR documentation error.

Finalize Deflate integration & reporting.

Update Release Notes
2025-10-20 19:23:22 -04:00
Chuck
dea8a805ce
Merge pull request #239 from ChuckPa/chuckpa/Hotio-Cache-Dir
HotIO -  Path to Cache dir incorrect
2025-07-31 20:20:46 -04:00
ChuckPa
6d8bafbf99
HotIO - Path to Cache dir incorrect
Fixes path (working around silly symlink)
2025-07-31 20:18:21 -04:00
Chuck
e2acd24593
Merge pull request #232 from ChuckPa/chuckpa/restart-path
Correct path issue with restart
2025-07-07 20:23:33 -04:00
ChuckPa
24b746db1b
Correct path issue with restart 2025-07-06 19:29:25 -04:00
4 changed files with 361 additions and 72 deletions

View File

@ -2,12 +2,12 @@
######################################################################### #########################################################################
# Database Repair Utility for Plex Media Server. # # Database Repair Utility for Plex Media Server. #
# Maintainer: ChuckPa # # Maintainer: ChuckPa #
# Version: v1.11.07 # # Version: v1.12.01 #
# Date: 25-Jun-2025 # # Date: 21-Oct-2025 #
######################################################################### #########################################################################
# Version for display purposes # Version for display purposes
Version="v1.11.07" Version="v1.12.01"
# Have the databases passed integrity checks # Have the databases passed integrity checks
CheckedDB=0 CheckedDB=0
@ -719,7 +719,7 @@ HostConfig() {
AppSuppDir="/config" AppSuppDir="/config"
PID_FILE="$AppSuppDir/plexmediaserver.pid" PID_FILE="$AppSuppDir/plexmediaserver.pid"
DBDIR="$AppSuppDir/Plug-in Support/Databases" DBDIR="$AppSuppDir/Plug-in Support/Databases"
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
@ -1405,6 +1405,183 @@ DoReplace() {
fi fi
} }
##### Deflate
DoDeflate() {
Damaged=0
Fail=0
# Verify DBs are here
if [ ! -e $CPPL.db ]; then
Output "No main Plex database exists to deflate. Exiting."
WriteLog "Deflate - No main database - FAIL"
Fail=1
return 1
fi
# Check size
Size=$(stat $STATFMT $STATBYTES $CPPL.db)
# Exit if not valid
if [ $Size -lt 300000 ]; then
Output "Main database is too small/truncated, deflate is not possible. Please try restoring a backup. "
WriteLog "Deflate - Main databse too small - FAIL"
Fail=1
return 1
fi
# Calculate DBsize in GB
DBSize=$(( $Size / 1000000000 + 2 ))
# Continue
DoUpdateTimestamp
#Output "Backing up databases using timestamp: $TimeStamp"
# Make a backup
if ! MakeBackups "Deflate"; then
Output "Error making backups. Cannot continue."
WriteLog "Deflate - MakeBackups - FAIL"
Fail=1
return 1
else
WriteLog "Deflate - MakeBackups - PASS"
fi
# Inform user
Output "Starting Deflate (Part 1 of 2 - Repair database table)"
Output "Estimated completion is $((DBSize / 3)) minutes but is CPU & I/O speed dependent"
Output ""
WriteLog "Deflate - Start Deflate Pass 1"
# Library and blobs successfully exported, create new
"$PLEX_SQLITE" "$TMPDIR/$CPPL.db-BACKUP-$TimeStamp" << EOF
-- Exclusive DB access
BEGIN IMMEDIATE;
-- Create new table
CREATE TABLE temp_bandwidth (
id INTEGER PRIMARY KEY,
account_id INTEGER,
device_id INTEGER,
timespan INTEGER,
at INTEGER,
lan INTEGER,
bytes INTEGER
);
-- Copy good data to new table
INSERT INTO temp_bandwidth (
account_id, device_id, timespan, at, lan, bytes
)
SELECT account_id, device_id, timespan, at, COALESCE(lan, 0), bytes
FROM statistics_bandwidth WHERE account_id not null;
-- Swap new for old
DROP TABLE statistics_bandwidth;
ALTER TABLE temp_bandwidth RENAME TO statistics_bandwidth;
-- Create Indexes
CREATE INDEX IF NOT EXISTS index_statistics_bandwidth_on_at
ON statistics_bandwidth(at);
CREATE INDEX IF NOT EXISTS index_statistics_bandwidth_on_account_id_and_timespan_and_at
ON statistics_bandwidth(account_id, timespan, at);
-- Make it so
COMMIT;
EOF
Result=$?
if [ $Result -ne 0 ]; then
Output "Error: Could not correct statistics_bandwidth table (error $Result)"
Output " Please seek additional help"
WriteLog "Deflate: Error $Result during dodeflate."
Fail=1
return $Fail
fi
# Vacuum the DB to the new DB
Output "PMS main database successfully repaired."
Output "Starting Deflate (Part 2 of 2 - Reduce size)"
WriteLog "Deflate - Start Deflate Pass 2"
"$PLEX_SQLITE" "$TMPDIR/$CPPL.db-BACKUP-$TimeStamp" \
"VACUUM main into '$TMPDIR/$CPPL.db-DEFLATE-$TimeStamp'"
Result=$?
# Good result?
if [ $Result -eq 0 ]; then
Output "PMS main database size reduced."
WriteLog "Deflate - PMS main vacuum successful."
Output "Verifying PMS main database."
if CheckDB "$TMPDIR/$CPPL.db-DEFLATE-$TimeStamp" ; then
SizeStart=$(GetSize "$CPPL.db")
SizeFinish=$(GetSize "$TMPDIR/$CPPL.db-DEFLATE-$TimeStamp")
Output "Verification complete. PMS main database is OK."
Output "PMS main database reduced from $SizeStart MB to $SizeFinish MB"
WriteLog "Deflate - Verify main database - PASS (Size: ${SizeStart} MB / ${SizeFinish} MB."
else
Output "Verification complete. PMS main database import failed."
WriteLog "Deflate - Verify main database - FAIL ($SQLerror)"
Fail=1
fi
else
Output "Error: Error code $Result while vacuuming PMS main DB file."
Output " Please seek additional help."
return $Fail
fi
# If not failed, move files normally
if [ $Fail -eq 0 ]; then
Output "Saving current main database with '-BLOATED-$TimeStamp'"
[ -e $CPPL.db ] && mv $CPPL.db "$TMPDIR/$CPPL.db-BLOATED-$TimeStamp"
#[ -e $CPPL.blobs.db ] && mv $CPPL.blobs.db "$TMPDIR/$CPPL.blobs.db-BLOATED-$TimeStamp"
Output "Making deflated database active"
WriteLog "Deflate - Making deflated database active"
mv "$TMPDIR/$CPPL.db-DEFLATE-$TimeStamp" $CPPL.db
# Ensure WAL and SHM are gone
[ -e $CPPL.blobs.db-wal ] && rm -f $CPPL.blobs.db-wal
[ -e $CPPL.blobs.db-shm ] && rm -f $CPPL.blobs.db-shm
[ -e $CPPL.db-wal ] && rm -f $CPPL.db-wal
[ -e $CPPL.db-shm ] && rm -f $CPPL.db-shm
# Set ownership on new files
chmod $Perms $CPPL.db $CPPL.blobs.db
chown $Owner $CPPL.db $CPPL.blobs.db
Result=$?
if [ $Result -ne 0 ]; then
Output "ERROR: Cannot set permissions on new databases. Error $Result"
Output " Please exit tool, keeping temp files, seek assistance."
Output " Use files: $TMPDIR/*-DEFLATE-$TimeStamp"
WriteLog "Deflate - Move files - FAIL"
Fail=1
return 1
fi
# We didn't fail, set CheckedDB status true (passed above checks)
CheckedDB=1
WriteLog "Deflate - Move files - PASS"
WriteLog "Deflate - PASS"
Output "PMS main database deflate completed."
SetLast "Deflate" "$TimeStamp"
return 0
else
rm -f "$TMPDIR/$CPPL.db-REPAIR-$TimeStamp"
rm -f "$TMPDIR/$CPPL.blobs.db-REPAIR-$TimeStamp"
Output "Deflate has failed. No files changed"
WriteLog "Deflate - $TimeStamp - FAIL"
CheckedDB=0
return 1
fi
}
##### VACUUM ##### VACUUM
DoVacuum(){ DoVacuum(){
@ -1655,7 +1832,7 @@ DoStop(){
else else
if IsRunning; then if IsRunning; then
Output "Stopping PMS." Output "Stopping PMS. (60 second max delay)"
else else
Output "PMS already stopped." Output "PMS already stopped."
return 0 return 0
@ -1672,7 +1849,7 @@ DoStop(){
Count=10 Count=10
while IsRunning && [ $Count -gt 0 ] while IsRunning && [ $Count -gt 0 ]
do do
sleep 3 sleep 6
Count=$((Count - 1)) Count=$((Count - 1))
done done
@ -1682,7 +1859,7 @@ DoStop(){
return 0 return 0
else else
WriteLog "Stop - FAIL (Timeout)" WriteLog "Stop - FAIL (Timeout)"
Output "Could not stop PMS. PMS did not shutdown within 30 second limit." Output "Could not stop PMS. PMS did not shutdown within 60 second limit."
fi fi
fi fi
return $Result return $Result
@ -2017,12 +2194,11 @@ do
echo " 10 - 'show' - Show logfile." echo " 10 - 'show' - Show logfile."
echo " 11 - 'status' - Report status of PMS (run-state and databases)." echo " 11 - 'status' - Report status of PMS (run-state and databases)."
echo " 12 - 'undo' - Undo last successful command." echo " 12 - 'undo' - Undo last successful command."
echo "" echo ""
echo " 21 - 'prune' - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS." echo " 21 - 'prune' - Remove old image files from PhotoTranscoder cache & all temp files left by PMS."
echo " 23 - 'deflate' - Deflate a bloated PMS main database."
[ $IgnoreErrors -eq 0 ] && echo " 42 - 'ignore' - Ignore duplicate/constraint errors." [ $IgnoreErrors -eq 0 ] && echo " 42 - 'ignore' - Ignore duplicate/constraint errors."
[ $IgnoreErrors -eq 1 ] && echo " 42 - 'honor' - Honor all database errors." [ $IgnoreErrors -eq 1 ] && echo " 42 - 'honor' - Honor all database errors."
echo "" echo ""
echo " 88 - 'update' - Check for updates." echo " 88 - 'update' - Check for updates."
echo " 98 - 'quit' - Quit immediately. Keep all temporary files." echo " 98 - 'quit' - Quit immediately. Keep all temporary files."
@ -2110,6 +2286,7 @@ do
else else
WriteLog "Check - FAIL" WriteLog "Check - FAIL"
CheckedDB=0 CheckedDB=0
continue
fi fi
# Now Repair # Now Repair
@ -2337,6 +2514,59 @@ do
;; ;;
# Deflate the DB because Plex isn't doing a good job during scheduled tasks.
23|defl*)
# Check if PMS running
if IsRunning; then
WriteLog "Deflate - FAIL - PMS runnning"
Output "Unable to deflate. PMS is running. Please stop PlexMediaServer."
continue
fi
# Is there enough room to work
if ! FreeSpaceAvailable; then
WriteLog "Deflate - FAIL - Insufficient free space on $AppSuppDir"
Output "Error: Unable to deflate. Insufficient free space available on $AppSuppDir"
Output " Space needed = $SpaceNeeded MB, Space available = $SpaceAvailable MB"
continue
fi
# Start auto
Output "Check and Deflate started."
WriteLog "Deflate - START"
# Check the databases (forced)
Output ""
if CheckDatabases "Check " force ; then
WriteLog "Check - PASS"
CheckedDB=1
else
WriteLog "Check - FAIL"
CheckedDB=0
fi
# Now Deflate
Output ""
if ! DoDeflate; then
WriteLog "Deflate - FAIL"
CheckedDB=0
Output "Deflate failed. Please repair using Automatic mode."
continue
else
WriteLog "Deflate - PASS"
CheckedDB=1
fi
# All good to here
WriteLog "Deflate - PASS"
Output "Deflate successful."
Output "Recommend running "Auto" next to complete optimization of new database."
;;
# Records count # Records count
30|coun*) 30|coun*)
@ -2408,7 +2638,7 @@ do
WriteLog "Restarting after upgrade" WriteLog "Restarting after upgrade"
Output "Restarting" Output "Restarting"
export DBRepairRestartedAfterUpdate=1 export DBRepairRestartedAfterUpdate=1
exec "$0" "$@" exec "$ScriptWorkingDirectory/$ScriptName" "$*"
else else
Output "Restart to launch updated DBRepair.sh ($LatestVersion)" Output "Restart to launch updated DBRepair.sh ($LatestVersion)"
WriteLog "Update - Updated to version $LatestVersion." WriteLog "Update - Updated to version $LatestVersion."

View File

@ -1,7 +1,9 @@
Copyright (c) 2022, ChuckPa. Copyright (c) 2025, ChuckPa.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software for personal use only. The Software may not be modified, merged, published, distributed, sublicensed, and/or used in other form without the express written consent of the author. This software is the intellectual property of ChuckPa
and used in conjunction with Plex Media Server (which is Copyright & Trademark of Plex, Inc.)
It may not be copied, modified, or redistributed in any way without expressly written permission of ChuckPa.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

154
README.md
View File

@ -31,6 +31,7 @@ If sufficient privleges exist (root), and supported by the environment, the opti
``` ```
AUTO(matic) - Automatically check, repair/optimize, and reindex the databases in one step. AUTO(matic) - Automatically check, repair/optimize, and reindex the databases in one step.
CHEC(k) - Check the main and blob databases integrity CHEC(k) - Check the main and blob databases integrity
DEFL(ate) - Deflate a bloated PMS database (faulty statistics data)
EXIT - Exit the utility EXIT - Exit the utility
IGNOre/HONOr - Ignore/Honor constraint errors when IMPORTing additional data into DB. IGNOre/HONOr - Ignore/Honor constraint errors when IMPORTing additional data into DB.
IMPO(rt) - Import viewstate / watch history from another database IMPO(rt) - Import viewstate / watch history from another database
@ -72,6 +73,7 @@ If sufficient privleges exist (root), and supported by the environment, the opti
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache. 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
22 - 'purge' - Purge (delete) all temporary files left behind by PMS & the transcoder. 22 - 'purge' - Purge (delete) all temporary files left behind by PMS & the transcoder.
23 - 'deflate' - Deflate a bloated PMS main database.
42 - 'ignore' - Ignore duplicate/constraint errors. 42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates. 88 - 'update' - Check for updates.
@ -113,7 +115,7 @@ Enter command # -or- command name (4 char min) :
-------------------+---------------------+------------------------------------------ -------------------+---------------------+------------------------------------------
Apple | Downloads | ~/Downloads Apple | Downloads | ~/Downloads
Arch Linux | N/A | Anywhere Arch Linux | N/A | Anywhere
ASUSTOR | Public | /volume1/Public ASUSTOR | Plex | /volume1/Plex
Binhex | N/A | Container root (adjacent /config) Binhex | N/A | Container root (adjacent /config)
Docker (Plex,LSIO) | N/A | Container root (adjacent /config) Docker (Plex,LSIO) | N/A | Container root (adjacent /config)
Hotio | N/A | Container root (adjacent /config) Hotio | N/A | Container root (adjacent /config)
@ -226,19 +228,18 @@ These examples
3. (6) Reindex - Generate new indexes so PMS doesn't need to at startup 3. (6) Reindex - Generate new indexes so PMS doesn't need to at startup
4. (99) Exit 4. (99) Exit
C. Database sizes excessively large when compared to amount of media indexed (item count) D. Database sizes excessively large/bloated when compared to amount of media indexed (item count)
1. (3) Check - Make certain both databases are fully intact (repair if needed) 1. (23) Deflate - Correct the known problem with a database table and recover the wasted space.
2. (4) Vacuum - Instruct SQLite to rebuild its tables and recover unused space. 2. (2) Auto - Perform automated check, repair, and reindex of the deflated database
3. (6) Reindex - Rebuild Indexes.
4. (99) Exit 4. (99) Exit
D. User interface has become 'sluggish' as more media was added E. User interface has become 'sluggish' as more media was added
1. (3) Check - Confirm there is no database damage 1. (3) Check - Confirm there is no database damage
2. (5) Repair - You are not really repairing. You are rebuilding the DB in perfect sorted order. 2. (5) Repair - You are not really repairing. You are rebuilding the DB in perfect sorted order.
3. (6) Reindex - Rebuild Indexes. 3. (6) Reindex - Rebuild Indexes.
4. (99) Exit 4. (99) Exit
E. Undo F. Undo
Undo is a special case where you need the utility to backup ONE step. Undo is a special case where you need the utility to backup ONE step.
This is rarely needed. The only time you might want/need to backup one step is if Replace leaves you worse off This is rarely needed. The only time you might want/need to backup one step is if Replace leaves you worse off
than you were before. In this case, UNDO then Repair. Undo can only undo the single most-recent action. than you were before. In this case, UNDO then Repair. Undo can only undo the single most-recent action.
@ -268,14 +269,10 @@ Attention:
-- This is for when DB operations keep getting worse and you don't know what to do. -- This is for when DB operations keep getting worse and you don't know what to do.
"99" is an old 'Get Smart' TV series reference where agent 99 would try to save agent 86 from harm. "99" is an old 'Get Smart' TV series reference where agent 99 would try to save agent 86 from harm.
"99" was originally going to be "Quit immediately save all files" but development feedback Community feedback has resulted in:
resulted in this configuration
"Exit" is the preferred method to leave. "99" or "Exit" - Preferred way to exit and cleanup temp databases
"98" or "Quit" - Get out now without deleting the temp databases (Usually used only during unexpected failures)
"Quit" was desired instead of "99" but there are those who didn't understand the difference or references.
If community feedback wants both "Quit. save temps" and "Exit, delete temps", behavior is easily changed.
Also please be aware the script understands interactive versus scripted mode. Also please be aware the script understands interactive versus scripted mode.
@ -352,7 +349,9 @@ Select
11 - 'status' - Report status of PMS (run-state and databases). 11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command. 12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache. 21 - 'prune' - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS.
22 - 'purge' - Remove unused temp files.
23 - 'deflate' - Deflate a bloated PMS main database.
42 - 'ignore' - Ignore duplicate/constraint errors. 42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates. 88 - 'update' - Check for updates.
@ -380,7 +379,9 @@ Select
11 - 'status' - Report status of PMS (run-state and databases). 11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command. 12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache. 21 - 'prune' - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS.
22 - 'purge' - Remove unused temp files.
23 - 'deflate' - Deflate a bloated PMS main database.
42 - 'ignore' - Ignore duplicate/constraint errors. 42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates. 88 - 'update' - Check for updates.
@ -434,7 +435,9 @@ Select
11 - 'status' - Report status of PMS (run-state and databases). 11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command. 12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache. 21 - 'prune' - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS.
22 - 'purge' - Remove unused temp files.
23 - 'deflate' - Deflate a bloated PMS main database.
42 - 'ignore' - Ignore duplicate/constraint errors. 42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates. 88 - 'update' - Check for updates.
@ -462,7 +465,9 @@ Select
11 - 'status' - Report status of PMS (run-state and databases). 11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command. 12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache. 21 - 'prune' - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS.
22 - 'purge' - Remove unused temp files.
23 - 'deflate' - Deflate a bloated PMS main database.
42 - 'ignore' - Ignore duplicate/constraint errors. 42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates. 88 - 'update' - Check for updates.
@ -493,7 +498,9 @@ Select
11 - 'status' - Report status of PMS (run-state and databases). 11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command. 12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache. 21 - 'prune' - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS.
22 - 'purge' - Remove unused temp files.
23 - 'deflate' - Deflate a bloated PMS main database.
42 - 'ignore' - Ignore duplicate/constraint errors. 42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates. 88 - 'update' - Check for updates.
@ -640,6 +647,13 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases#
Checks the integrity of the Plex main and blobs databases. Checks the integrity of the Plex main and blobs databases.
### Deflate
Repairs a known error in the PMS main database "statistics_bandwidth" table.
After repairing it, it purges all the errant data from the table (reducing DB size)
This task can take a significant amount of time. It's frequently used when the DB size is an order of magnitude above what it should be (e.g. 31 GB vs 206 MB). Reductions from 134 GB to 210 MB have been realized.
### Exit ### Exit
Exits the utility and removes all temporary database files created during processing. Exits the utility and removes all temporary database files created during processing.
@ -817,55 +831,77 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases#
1. Remove the environment variable. 1. Remove the environment variable.
2. Run DBRepair again using "automatic". Your databases will revert to the host OS's default. 2. Run DBRepair again using "automatic". Your databases will revert to the host OS's default.
### Usage: (Linux example shown) ### Usage: (QNAP example shown)
``` ```
# export DBREPAIR_PAGESIZE=65534 # export DBREPAIR_PAGESIZE=65534
# ./DBRepair.sh stop auto start exit # ./DBRepair.sh stop deflate auto start exit
Database Repair Utility for Plex Media Server (Ubuntu 22.04.3 LTS) Database Repair Utility for Plex Media Server (QNAP)
Version v1.03.01 Version v1.12.00
[2024-01-14 17.25.35] Stopping PMS. [2025-10-21 16.54.00] PMS already stopped.
[2024-01-14 17.25.35] Stopped PMS.
[2024-01-14 17.25.35] Automatic Check,Repair,Index started. [2025-10-21 16.54.00] Check and Deflate started.
[2024-01-14 17.25.35] [2025-10-21 16.54.00]
[2024-01-14 17.25.35] Checking the PMS databases [2025-10-21 16.54.00] Checking the PMS databases
[2024-01-14 17.25.48] Check complete. PMS main database is OK. [2025-10-21 16.54.19] Check complete. PMS main database is OK.
[2024-01-14 17.25.48] Check complete. PMS blobs database is OK. [2025-10-21 16.54.21] Check complete. PMS blobs database is OK.
[2024-01-14 17.25.48] [2025-10-21 16.54.21]
[2024-01-14 17.25.48] Exporting current databases using timestamp: 2024-01-14_17.25.35 [2025-10-21 16.54.21] Backup current databases with '-BACKUP-2025-10-21_16.54.21' timestamp.
[2024-01-14 17.25.48] Exporting Main DB [2025-10-21 16.56.29] Starting Deflate (Part 1 of 2 - Repair database table)
[2024-01-14 17.25.59] Exporting Blobs DB [2025-10-21 16.56.29] Estimated completion is approx 6 minutes but is CPU & I/O speed dependent
[2024-01-14 17.26.00] Successfully exported the main and blobs databases. Proceeding to import into new databases. [2025-10-21 16.56.29]
[2024-01-14 17.26.00] Importing Main DB. [2025-10-21 16.56.30] PMS main database successfully repaired.
[2024-01-14 17.26.00] Setting Plex SQLite page size (65536) [2025-10-21 16.56.30] Starting Deflate (Part 2 of 2 - Reduce size)
[2024-01-14 17.26.29] Importing Blobs DB. [2025-10-21 16.56.35] PMS main database size reduced.
[2024-01-14 17.26.29] Setting Plex SQLite page size (65536) [2025-10-21 16.56.35] Verifying PMS main database.
[2024-01-14 17.26.30] Successfully imported databases. [2025-10-21 16.56.50] Verification complete. PMS main database is OK.
[2024-01-14 17.26.30] Verifying databases integrity after importing. [2025-10-21 16.56.50] PMS main database reduced from 31586 MB to 206 MB
[2024-01-14 17.27.43] Verification complete. PMS main database is OK. [2025-10-21 16.56.51] Saving current main database with '-BLOATED-2025-10-21_16.54.21'
[2024-01-14 17.27.43] Verification complete. PMS blobs database is OK. [2025-10-21 16.56.51] Making deflated database active
[2024-01-14 17.27.43] Saving current databases with '-BACKUP-2024-01-14_17.25.35' [2025-10-21 16.56.51] PMS main database deflate completed.
[2024-01-14 17.27.43] Making repaired databases active [2025-10-21 16.56.51] Deflate successful.
[2024-01-14 17.27.43] Repair complete. Please check your library settings and contents for completeness. [2025-10-21 16.56.51] Recommend running Auto next to complete optimization of new database.
[2024-01-14 17.27.43] Recommend: Scan Files and Refresh all metadata for each library section.
[2024-01-14 17.27.43]
[2024-01-14 17.27.43] Backing up of databases
[2024-01-14 17.27.43] Backup current databases with '-BACKUP-2024-01-14_17.27.43' timestamp.
[2024-01-14 17.27.44] Reindexing main database
[2024-01-14 17.28.08] Reindexing main database successful.
[2024-01-14 17.28.08] Reindexing blobs database
[2024-01-14 17.28.08] Reindexing blobs database successful.
[2024-01-14 17.28.08] Reindex complete.
[2024-01-14 17.28.08] Automatic Check, Repair/optimize, & Index successful.
[2024-01-14 17.28.08] Starting PMS. [2025-10-21 16.56.51] Automatic Check,Repair,Index started.
[2024-01-14 17.28.08] Started PMS [2025-10-21 16.56.51]
[2025-10-21 16.56.51] Checking the PMS databases
[2025-10-21 16.57.04] Check complete. PMS main database is OK.
[2025-10-21 16.57.05] Check complete. PMS blobs database is OK.
[2025-10-21 16.57.05]
[2025-10-21 16.57.05] Exporting current databases using timestamp: 2025-10-21_16.56.51
[2025-10-21 16.57.05] Exporting Main DB
[2025-10-21 16.57.24] Exporting Blobs DB
[2025-10-21 16.59.18] Successfully exported the main and blobs databases.
[2025-10-21 16.59.18] Start importing into new databases.
[2025-10-21 16.59.18] Importing Main DB.
[2025-10-21 16.59.18] Setting Plex SQLite page size (65536)
[2025-10-21 17.00.19] Importing Blobs DB.
[2025-10-21 17.00.19] Setting Plex SQLite page size (65536)
[2025-10-21 17.00.32] Successfully imported databases.
[2025-10-21 17.00.32] Verifying databases integrity after importing.
[2025-10-21 17.01.59] Verification complete. PMS main database is OK.
[2025-10-21 17.02.01] Verification complete. PMS blobs database is OK.
[2025-10-21 17.02.01] Saving current databases with '-BACKUP-2025-10-21_16.56.51'
[2025-10-21 17.02.01] Making repaired databases active
[2025-10-21 17.02.01] Repair complete. Please check your library settings and contents for completeness.
[2025-10-21 17.02.01] Recommend: Scan Files and Refresh all metadata for each library section.
[2025-10-21 17.02.01]
[2025-10-21 17.02.01] Backing up of databases
[2025-10-21 17.02.01] Backup current databases with '-BACKUP-2025-10-21_17.02.01' timestamp.
[2025-10-21 17.02.02] Reindexing main database
[2025-10-21 17.02.13] Reindexing main database successful.
[2025-10-21 17.02.13] Reindexing blobs database
[2025-10-21 17.02.14] Reindexing blobs database successful.
[2025-10-21 17.02.14] Reindex complete.
[2025-10-21 17.02.14] Automatic Check, Repair/optimize, & Index successful.
[2025-10-21 17.02.14] Starting PMS.
[2025-10-21 17.02.14] Started PMS
# #
``` ```
@ -939,6 +975,8 @@ Select
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache older than specific age. 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache older than specific age.
22 - 'purge' - Purge (remove) all temporary files left by PMS & Transcoder in Temp Dir.' 22 - 'purge' - Purge (remove) all temporary files left by PMS & Transcoder in Temp Dir.'
23 - 'deflate' - Deflate a bloated PMS main database.
42 - 'ignore' - Ignore duplicate/constraint errors. 42 - 'ignore' - Ignore duplicate/constraint errors.

View File

@ -8,6 +8,25 @@
![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.12.00
1. Deflate capability - Deflate a bloated PMS main database and retain bandwidth statistics.
Recommended usage: "Deflate" followed by "Auto" to optimize the DB after reduction.
- Method changed to reconstruction of bandwidth table versus selective copy.
This results in correct operation of bandwidth statistics functionality
as well as significantly improved performance.
2. ASUSTOR - Documentation error README.md corrected
v1.11.09
1. HotIO Paths - Path defined for Cache dir (and PhotoTranscoder) incorrect. Fixed.
v1.11.08
1. Restart after update - Sometimes restart after update would reference the wrong path. Fixed.
v1.11.07 v1.11.07
1. Add support FreeBSD - Add support for FreeBSD (14+) 1. Add support FreeBSD - Add support for FreeBSD (14+)