mirror of
https://github.com/ChuckPa/PlexDBRepair.git
synced 2025-11-06 03:08:55 -05:00
Merge pull request #124 from ChuckPa/chuckpa/pagesize-constraint-check
Correct case where PAGESIZE != 2^n where n={10,11,12,13,14,15,16}
This commit is contained in:
commit
e02e5bc398
53
DBRepair.sh
53
DBRepair.sh
@ -2,12 +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.03.00 #
|
# Version: v1.03.01 #
|
||||||
# Date: 17-Jan-2024 #
|
# Date: 17-Jan-2024 #
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
# Version for display purposes
|
# Version for display purposes
|
||||||
Version="v1.03.00"
|
Version="v1.03.01"
|
||||||
|
|
||||||
# Flag when temp files are to be retained
|
# Flag when temp files are to be retained
|
||||||
Retain=0
|
Retain=0
|
||||||
@ -335,7 +335,7 @@ GetOverride() {
|
|||||||
cd /etc/systemd/system/plexmediaserver.service.d
|
cd /etc/systemd/system/plexmediaserver.service.d
|
||||||
|
|
||||||
# Glob up all 'conf files' found
|
# 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 there is one, search it
|
||||||
if [ "$ConfFile" != "" ]; then
|
if [ "$ConfFile" != "" ]; then
|
||||||
@ -815,19 +815,50 @@ DoSetPageSize() {
|
|||||||
# Is it a valid positive integer ?
|
# Is it a valid positive integer ?
|
||||||
if [ "$DBREPAIR_PAGESIZE" != "$(echo "$DBREPAIR_PAGESIZE" | sed 's/[^0-9]*//g')" ]; then
|
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'"
|
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
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make certain it's a multiple of 1024 and gt 0
|
# Make certain it's a multiple of 1024 and gt 0
|
||||||
DbPageSize=$(expr $DBREPAIR_PAGESIZE + 1023)
|
DbPageSize=$DBREPAIR_PAGESIZE
|
||||||
DbPageSize=$(expr $DbPageSize / 1024)
|
[ $DbPageSize -le 0 ] && return
|
||||||
DbPageSize=$(expr $DbPageSize \* 1024)
|
|
||||||
|
|
||||||
|
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
|
# Must be compliant
|
||||||
[ $DbPageSize -le 0 ] && return
|
if [ $DbPageSize -gt 65536 ]; then
|
||||||
[ $DbPageSize -gt 65536 ] && DbPageSize=65536 && WriteLog "SetPageSize - DBREPAIR_PAGESIZE too large. Reducing."
|
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)"
|
Output "Setting Plex SQLite page size ($DbPageSize)"
|
||||||
WriteLog "SetPageSize - 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" != "" ]; then
|
||||||
if [ "$DBREPAIR_CACHEAGE" != "$(echo "$DBREPAIR_CACHEAGE" | sed 's/[^0-9]*//g')" ]; 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'"
|
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
|
return
|
||||||
else
|
else
|
||||||
CacheAge=$DBREPAIR_CACHEAGE
|
CacheAge=$DBREPAIR_CACHEAGE
|
||||||
@ -1563,7 +1594,7 @@ DoPrunePhotoTranscoder() {
|
|||||||
if [ $PruneIt -eq 1 ]; then
|
if [ $PruneIt -eq 1 ]; then
|
||||||
Output "Pruning started."
|
Output "Pruning started."
|
||||||
WriteLog "Prune - Removing $FileCount files over $CacheAge days old."
|
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."
|
Output "Pruning completed."
|
||||||
WriteLog "Prune - PASS."
|
WriteLog "Prune - PASS."
|
||||||
fi
|
fi
|
||||||
|
|||||||
74
README.md
74
README.md
@ -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.
|
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
|
||||||
EXIT - Exit the utility
|
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
|
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
|
REIN(dex) - Rebuild the database indexes
|
||||||
REPL(ace) - Replace the existing databases with a PMS-generated backup
|
REPL(ace) - Replace the existing databases with a PMS-generated backup
|
||||||
SHOW - Show the log file
|
SHOW - Show the log file
|
||||||
@ -50,31 +52,32 @@ If sufficient privleges exist (root), and supported by the environment, the opti
|
|||||||
|
|
||||||
```
|
```
|
||||||
Plex Media Server Database Repair Utility (_host_configuration_name_)
|
Plex Media Server Database Repair Utility (_host_configuration_name_)
|
||||||
Version v1.02.00
|
Version v1.03.00
|
||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
1 - 'stop' - Stop PMS.
|
1 - 'stop' - Stop PMS.
|
||||||
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
|
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
|
||||||
3 - 'check' - Perform integrity check of database.
|
3 - 'check' - Perform integrity check of database.
|
||||||
4 - 'vacuum' - Remove empty space from database without optimizing.
|
4 - 'vacuum' - Remove empty space from database without optimizing.
|
||||||
5 - 'repair' - Repair/Optimize databases.
|
5 - 'repair' - Repair/Optimize databases.
|
||||||
6 - 'reindex' - Rebuild database database indexes.
|
6 - 'reindex' - Rebuild database database indexes.
|
||||||
7 - 'start' - Start PMS
|
7 - 'start' - Start PMS
|
||||||
|
|
||||||
8 - 'import' - Import watch history from another database independent of Plex. (risky).
|
8 - 'import' - Import watch history from another database independent of Plex. (risky).
|
||||||
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
|
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
|
||||||
10 - 'show' - Show logfile.
|
10 - 'show' - Show logfile.
|
||||||
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.
|
||||||
|
|
||||||
42 - 'ignore' - Ignore duplicate/constraint errors.
|
21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache.
|
||||||
|
42 - 'ignore' - Ignore duplicate/constraint errors.
|
||||||
|
|
||||||
88 - 'update' - Check for updates.
|
88 - 'update' - Check for updates.
|
||||||
99 - 'quit' - Quit immediately. Keep all temporary files.
|
99 - 'quit' - Quit immediately. Keep all temporary files.
|
||||||
'exit' - Exit with cleanup options.
|
'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)
|
Plex Media Server Database Repair Utility (Ubuntu 20.04.6 LTS)
|
||||||
Version v1.02.00
|
Version v1.03.01
|
||||||
|
|
||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
@ -319,6 +321,7 @@ 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.
|
||||||
42 - 'ignore' - Ignore duplicate/constraint errors.
|
42 - 'ignore' - Ignore duplicate/constraint errors.
|
||||||
|
|
||||||
88 - 'update' - Check for updates.
|
88 - 'update' - Check for updates.
|
||||||
@ -346,6 +349,7 @@ 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.
|
||||||
42 - 'ignore' - Ignore duplicate/constraint errors.
|
42 - 'ignore' - Ignore duplicate/constraint errors.
|
||||||
|
|
||||||
88 - 'update' - Check for updates.
|
88 - 'update' - Check for updates.
|
||||||
@ -399,6 +403,7 @@ 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.
|
||||||
42 - 'ignore' - Ignore duplicate/constraint errors.
|
42 - 'ignore' - Ignore duplicate/constraint errors.
|
||||||
|
|
||||||
88 - 'update' - Check for updates.
|
88 - 'update' - Check for updates.
|
||||||
@ -426,6 +431,7 @@ 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.
|
||||||
42 - 'ignore' - Ignore duplicate/constraint errors.
|
42 - 'ignore' - Ignore duplicate/constraint errors.
|
||||||
|
|
||||||
88 - 'update' - Check for updates.
|
88 - 'update' - Check for updates.
|
||||||
@ -456,6 +462,7 @@ 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.
|
||||||
42 - 'ignore' - Ignore duplicate/constraint errors.
|
42 - 'ignore' - Ignore duplicate/constraint errors.
|
||||||
|
|
||||||
88 - 'update' - Check for updates.
|
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)
|
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.
|
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.
|
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)"
|
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.
|
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:
|
### Constraints:
|
||||||
|
|
||||||
1. Must be a multiple of 1024 (per SQLite 3.12.0 documentation).
|
1. Must be a power of 2, with 1024 (2^10) as the Plex default. (per SQLite 3.12.0 documentation).
|
||||||
Any value provided willl be forced to be a multiple of 1024.
|
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.
|
This may or may not be the value you intended. Caution is advised.
|
||||||
|
|
||||||
2. May not exceed 65536 (per SQLite 3.12.0 documentation).
|
2. May not exceed 65536 (per SQLite 3.12.0 documentation).
|
||||||
Any value exceeding 65536 will be truncated to 65536.
|
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
|
### Management
|
||||||
|
|
||||||
If you attempt to optimize your database but find the resultant performance is not to your liking,
|
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.
|
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.
|
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.
|
||||||
|
|
||||||
@ -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)
|
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.
|
[2024-01-14 17.25.35] Stopping PMS.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user