Correct case where PAGESIZE != 2^n where n={10,11,12,13,14,15,16}

1.  Correct PAGESIZE allowed values
2.  Improved performance of prune
3.  Cosmetic output cleanup
4.  Improve error messaging and handling
5.  Update documentation
This commit is contained in:
ChuckPa 2024-01-17 21:15:01 -05:00
parent a489a7f9e6
commit 6ebb342973
No known key found for this signature in database
GPG Key ID: 3CE28A0F6BC31B5B
2 changed files with 89 additions and 38 deletions

View File

@ -2,12 +2,12 @@
#########################################################################
# Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa #
# Version: v1.03.00 #
# Version: v1.03.01 #
# Date: 17-Jan-2024 #
#########################################################################
# Version for display purposes
Version="v1.03.00"
Version="v1.03.01"
# Flag when temp files are to be retained
Retain=0
@ -335,7 +335,7 @@ GetOverride() {
cd /etc/systemd/system/plexmediaserver.service.d
# Glob up all 'conf files' found
ConfFile="$(find override.conf local.conf *.conf 2>/dev/null | uniq)"
ConfFile="$(find override.conf local.conf *.conf 2>/dev/null | head -1)"
# If there is one, search it
if [ "$ConfFile" != "" ]; then
@ -815,19 +815,50 @@ DoSetPageSize() {
# Is it a valid positive integer ?
if [ "$DBREPAIR_PAGESIZE" != "$(echo "$DBREPAIR_PAGESIZE" | sed 's/[^0-9]*//g')" ]; then
WriteLog "SetPageSize - ERROR: DBREPAIR_PAGESIZE is not a valid integer. Ignoring '$DBREPAIR_PAGESIZE'"
Output "SetPageSize - ERROR: DBREPAIR_PAGESIZE is not a valid integer. Ignoring '$DBREPAIR_PAGESIZE'"
Output "ERROR: DBREPAIR_PAGESIZE is not a valid integer. Ignoring '$DBREPAIR_PAGESIZE'"
return
fi
# Make certain it's a multiple of 1024 and gt 0
DbPageSize=$DBREPAIR_PAGESIZE
[ $DbPageSize -le 0 ] && return
if [ $(expr $DbPageSize % 1024) -ne 0 ]; then
DbPageSize=$(expr $DBREPAIR_PAGESIZE + 1023)
DbPageSize=$(expr $DbPageSize / 1024)
DbPageSize=$(expr $DbPageSize \* 1024)
WriteLog "DoSetPageSize - ERROR: DBREPAIR_PAGESIZE ($DBREPAIR_PAGESIZE) not a multiple of 1024. New value = $DbPageSize."
Output "WARNING: DBREPAIR_PAGESIZE ($DBREPAIR_PAGESIZE) not a multiple of 1024. New value = $DbPageSize."
fi
# Must be compliant
[ $DbPageSize -le 0 ] && return
[ $DbPageSize -gt 65536 ] && DbPageSize=65536 && WriteLog "SetPageSize - DBREPAIR_PAGESIZE too large. Reducing."
if [ $DbPageSize -gt 65536 ]; then
Output "WARNING: DBREPAIR_PAGESIZE ($DbPageSize) too large. Reducing to 65536."
WriteLog "SetPageSize - DBREPAIR_PAGESIZE ($DbPageSize) too large. Reducing."
DbPageSize=65536
fi
# Confirm a valid power of two.
IsPowTwo=0
for i in 1024 2048 4096 8192 16384 32768 65536
do
[ $i -eq $DbPageSize ] && IsPowTwo=1 && break
done
if [ $IsPowTwo -eq 0 ] && [ $DbPageSize -lt 65536 ]; then
for i in 1024 2048 4096 8192 16384 32768 65536
do
if [ $i -gt $DbPageSize ]; then
Output "ERROR: DBREPAIR_SIZE ($DbPageSize) not a power of 2 between 1024 and 65536. Value selected = $i."
WriteLog "SetPageSize - DBREPAIR_PAGESIZE ($DbPageSize) not a power of 2. New value selected = $i"
DbPageSize=$i
IsPowTwo=1
fi
[ $IsPowTwo -eq 1 ] && break
done
fi
Output "Setting Plex SQLite page size ($DbPageSize)"
WriteLog "SetPageSize - Setting Plex SQLite page_size: $DbPageSize"
@ -1536,7 +1567,7 @@ DoPrunePhotoTranscoder() {
if [ "$DBREPAIR_CACHEAGE" != "" ]; then
if [ "$DBREPAIR_CACHEAGE" != "$(echo "$DBREPAIR_CACHEAGE" | sed 's/[^0-9]*//g')" ]; then
WriteLog "PrunePhotoTranscoder - ERROR: DBREPAIR_CACHEAGE is not a valid integer. Ignoring '$DBREPAIR_CACHEAGE'"
Output "PrunePhotoTranscoder - ERROR: DBREPAIR_CACHEAGE is not a valid integer. Ignoring '$DBREPAIR_CACHEAGE'"
Output "ERROR: DBREPAIR_CACHEAGE is not a valid integer. Ignoring '$DBREPAIR_CACHEAGE'"
return
else
CacheAge=$DBREPAIR_CACHEAGE
@ -1563,7 +1594,7 @@ DoPrunePhotoTranscoder() {
if [ $PruneIt -eq 1 ]; then
Output "Pruning started."
WriteLog "Prune - Removing $FileCount files over $CacheAge days old."
find "$TransCacheDir" \( -name \*.jpg -o -name \*.jpeg -o -name \*.png \) -mtime +${CacheAge} -exec rm -f {} \;
find "$TransCacheDir" \( -name \*.jpg -o -name \*.jpeg -o -name \*.png \) -mtime +${CacheAge} -delete
Output "Pruning completed."
WriteLog "Prune - PASS."
fi

View File

@ -33,7 +33,9 @@ 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.
CHEC(k) - Check the main and blob databases integrity
EXIT - Exit the utility
IGNOre/HONOr - Ignore/Honor constraint errors when IMPORTing additional data into DB.
IMPO(rt) - Import viewstate / watch history from another database
PRUN(e) - Prune (remove) old image files from transcoder cache diretory
REIN(dex) - Rebuild the database indexes
REPL(ace) - Replace the existing databases with a PMS-generated backup
SHOW - Show the log file
@ -50,7 +52,7 @@ If sufficient privleges exist (root), and supported by the environment, the opti
```
Plex Media Server Database Repair Utility (_host_configuration_name_)
Version v1.02.00
Version v1.03.00
Select
@ -68,13 +70,14 @@ If sufficient privleges exist (root), and supported by the environment, the opti
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) :
Enter command # -or- command name (4 char min) :
@ -300,8 +303,7 @@ bash-4.4# ./DBRepair.sh
Plex Media Server Database Repair Utility (Ubuntu 20.04.6 LTS)
Version v1.02.00
Version v1.03.01
Select
@ -319,6 +321,7 @@ Select
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
@ -346,6 +349,7 @@ Select
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
@ -399,6 +403,7 @@ Select
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
@ -426,6 +431,7 @@ Select
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
@ -456,6 +462,7 @@ Select
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
@ -626,7 +633,10 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases#
Under certain conditions, PMS will fail to prune them (which is run during Scheduled Maintenance)
This command allows you to manually remove what PMS would do normally during that Scheduled Maintenance.
Use of this command will depend on the usage.
#### Warning: Initial pruning might take longer than expected.
Execution time, using a Synology DS418 as benchmark, is approximately 100,000 image files per 2 minutes.
For now, Both forms "Prune" and "Remove" are accepted.
@ -745,24 +755,34 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases#
When in use, you will see the message: "Setting Plex SQLite page size ($DbPageSize)"
This will be shown on the console output and reported in the logfile.
If the value is invalid, an error will be printed and recorded in the logfile.
If the value is too large, it will be reduced to the SQLite maximum of 65536.
### Constraints:
1. Must be a multiple of 1024 (per SQLite 3.12.0 documentation).
Any value provided willl be forced to be a multiple of 1024.
1. Must be a power of 2, with 1024 (2^10) as the Plex default. (per SQLite 3.12.0 documentation).
Any invalid value provided will be rounded up to the next integral value (1024, 2048, 4096 ... 65536)
This may or may not be the value you intended. Caution is advised.
2. May not exceed 65536 (per SQLite 3.12.0 documentation).
Any value exceeding 65536 will be truncated to 65536.
### Validation
If the value of DBREPAIR_PAGESIZE is not compliant with requirements, a new value will be selected.
Typing errors will be rounded up (e.g 65535 vs 65536) to the next multiple of 1024 before validation
is performed.
If the value is invalid, an error will be printed and recorded in the logfile. The next higher power
of two will be selected.
If the value is too large, it will be reduced to the SQLite maximum of 65536.
### Management
If you attempt to optimize your database but find the resultant performance is not to your liking,
you may try another value and run "automatic" again.
If you ultimately decide to run with the default values,
If you ultimately decide to run with the default values (4096),
1. Remove the environment variable.
2. Run DBRepair again using "automatic". Your databases will revert to the host OS's default.
@ -775,7 +795,7 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases#
Plex Media Server Database Repair Utility (Ubuntu 22.04.3 LTS)
Version v1.02.99
Version v1.03.01
[2024-01-14 17.25.35] Stopping PMS.