Merge pull request #178 from ChuckPa/chuckpa/Add-Purge

add purge
This commit is contained in:
Chuck 2024-12-29 00:57:57 -05:00 committed by GitHub
commit 1737631454
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 95 additions and 13 deletions

View File

@ -2,12 +2,12 @@
#########################################################################
# Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa #
# Version: v1.07.00 #
# Date: 14-Jun-2024 #
# Version: v1.09.00 #
# Date: 06-Nov-2024 #
#########################################################################
# Version for display purposes
Version="v1.07.00"
Version="v1.09.00"
# Have the databases passed integrity checks
CheckedDB=0
@ -29,6 +29,10 @@ RemoveDuplicates=0
# Keep track of how many times the user's hit enter with no command (implied EOF)
NullCommands=0
# Default TMP dir for most hosts
TMPDIR="/tmp"
SYSTMP="/tmp"
# Global variable - main database
CPPL=com.plexapp.plugins.library
@ -220,8 +224,8 @@ FreeSpaceAvailable() {
SpaceNeeded=$((LibSize + BlobsSize))
# Compute need (minimum $Multiplier existing; current, backup, temp and room to write new)
SpaceNeeded="$(expr $SpaceNeeded '*' $Multiplier)"
SpaceNeeded="$(expr $SpaceNeeded / 1000000)"
SpaceNeeded=$(($SpaceNeeded * $Multiplier))
SpaceNeeded=$(($SpaceNeeded / 1000000))
# If need < available, all good
[ $SpaceNeeded -lt $SpaceAvailable ] && return 0
@ -396,6 +400,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid"
LOGFILE="$DBDIR/DBRepair.log"
TMPDIR="$AppSuppDir/Plex Media Server/tmp"
SYSTMP="$TMPDIR"
# We are done
HostType="Synology (DSM 7)"
@ -426,6 +432,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid"
LOGFILE="$DBDIR/DBRepair.log"
TMPDIR="$AppSuppDir/Plex Media Server/tmp"
SYSTMP="$TMPDIR"
HostType="Synology (DSM 6)"
@ -451,6 +459,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid"
LOGFILE="$DBDIR/DBRepair.log"
TMPDIR="$AppSuppDir/tmp"
SYSTMP="$TMPDIR"
# Start/Stop
if [ -e /etc/init.d/plex.sh ]; then
@ -476,6 +486,8 @@ HostConfig() {
DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
TMPDIR="/var/snap/plexmediaserver/common/tmp"
SYSTMP="$TMPDIR"
HaveStartStop=1
StartCommand="snap start plexmediaserver"
@ -522,6 +534,8 @@ HostConfig() {
HaveStartStop=1
StartCommand="systemctl start plexmediaserver"
StopCommand="systemctl stop plexmediaserver"
TMPDIR="/tmp"
SYSTMP="$TMPDIR"
return 0
# Netgear ReadyNAS
@ -540,6 +554,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
TMPDIR="$PKGDIR/temp"
SYSTMP="$TMPDIR"
HaveStartStop=1
StartCommand="systemctl start fvapp-plexmediaserver"
@ -561,6 +577,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
TMPDIR="/tmp"
SYSTMP="$TMPDIR"
HostType="ASUSTOR"
return 0
@ -577,6 +595,8 @@ HostConfig() {
CACHEDIR="$HOME/Library/Caches/PlexMediaServer/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
TMPDIR="/tmp"
SYSTMP="$TMPDIR"
# MacOS uses pgrep and uses different stat options
PIDOF="pgrep"
@ -608,7 +628,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
TMPDIR="$(dirname $AppSuppDir)/plexmediaserver/tmp_transcoding"
SYSTMP="$TMPDIR"
HostType="Western Digital"
return 0
@ -619,6 +640,9 @@ HostConfig() {
elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] || [ "$(grep 0::/ /proc/1/cgroup)" = "0::/" ] ||
[ "$(grep libpod /proc/1/cgroup | wc -l)" -gt 0 ] || [ "$(grep kube /proc/1/cgroup | wc -l)" -gt 0 ]; then
TMPDIR="/tmp"
SYSTMP="/tmp"
# HOTIO Plex image structure is non-standard (contains symlink which breaks detection)
if [ -n "$(grep -irslm 1 hotio /etc/s6-overlay/s6-rc.d)" ]; then
PLEX_SQLITE=$(find /app/bin/usr/lib/plexmediaserver /app/usr/lib/plexmediaserver /usr/lib/plexmediaserver -maxdepth 0 -type d -print -quit 2>/dev/null); PLEX_SQLITE="$PLEX_SQLITE/Plex SQLite"
@ -628,6 +652,7 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
if [ -d "/run/service/plex" ] || [ -d "/run/service/service-plex" ]; then
SERVICE_PATH=$([ -d "/run/service/plex" ] && echo "/run/service/plex" || [ -d "/run/service/service-plex" ] && echo "/run/service/service-plex")
HaveStartStop=1
@ -657,6 +682,12 @@ HostConfig() {
StopCommand="s6-svc -d /var/run/service/svc-plex"
fi
if [ -d "/run/service/svc-plex" ]; then
HaveStartStop=1
StartCommand="s6-svc -u /run/service/svc-plex"
StopCommand="s6-svc -d /run/service/svc-plex"
fi
if [ -d "/var/run/s6/services/plex" ]; then
HaveStartStop=1
StartCommand="s6-svc -u /var/run/s6/services/plex"
@ -718,6 +749,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
TMPDIR="/tmp"
SYSTMP="/tmp"
HostType="$(grep PRETTY_NAME /etc/os-release | sed -e 's/^.*="//' | tr -d \" )"
HaveStartStop=1
@ -1600,6 +1633,7 @@ DownloadAndUpdate() {
}
# Prune old jpg files from the PhotoTranscoder directory (> 30 days -or- DBREPAIR_CACHEAGE days)
# and purge files from the TMP and Transcoder_Temp directories
DoPrunePhotoTranscoder() {
PruneIt=0
@ -1622,8 +1656,10 @@ DoPrunePhotoTranscoder() {
if [ $Scripted -eq 1 ]; then
PruneIt=1
else
Output "Counting how many files are more than $CacheAge days old."
Output "Counting how many files can be removed."
FileCount=$(find "$CACHEDIR" \( -name \*.jpg -o -name \*.jpeg -o -name \*.png -o -name \*.ppm \) -mtime +${CacheAge} -print | wc -l)
FileCount=$(( $FileCount + $(find "/tmp" -name pms-\* -mtime +1 -print | grep -v systemd | grep -v Easy | wc -l)))
FileCount=$(( $FileCount + $(find "/tmp" \( -name \*.jpg -o -name \*.jpeg -o -name \*.png \) -mtime +1 | wc -l )))
# If nothing found, continue back to the menu
[ $FileCount -eq 0 ] && Output "No files found to prune." && return
@ -1634,17 +1670,30 @@ DoPrunePhotoTranscoder() {
fi
fi
# Prune old the jpgs/jpegs ?
# Prune old the jpgs/jpegs from Cache and clean up /tmp
if [ $PruneIt -eq 1 ]; then
Output "Pruning started."
WriteLog "Prune - Removing $FileCount files over $CacheAge days old."
WriteLog "Prune - START"
find "$CACHEDIR" \( -name \*.jpg -o -name \*.jpeg -o -name \*.png \) -mtime +${CacheAge} -delete
PurgeFiles="/tmp/PurgeList.$$"
find "$TMPDIR" /tmp -name pms-\* -mtime +1 -print | grep -v systemd | grep -v Easy -print > "$PurgeFiles" 2>> /dev/null
find "$TMPDIR" /tmp \( -name \*.jpg -o -name \*.jpeg -o -name \*.png \) -mtime +1 -print >> "$PurgeFiles" 2>> /dev/null
WriteLog "Prune - Removing $FileCount files."
while read Path
do
rm -rf "$Path" >> /dev/null 2>> /dev/null
done < "$PurgeFiles"
rm -f "$PurgeFiles"
Output "Pruning completed."
WriteLog "Prune - PASS."
fi
}
#############################################################
# Main utility begins here #
#############################################################
@ -1660,7 +1709,7 @@ 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="$(echo $1 | awk '{print $1}' | tr [A-Z] [a-z])"
[ "$Opt" = "-i" ] && shift
[ "$Opt" = "-f" ] && shift
[ "$Opt" = "-p" ] && shift
@ -1772,6 +1821,8 @@ fi
# Set tmp dir so we don't use RAM when in DBDIR
DBTMP="./dbtmp"
mkdir -p "$DBDIR/$DBTMP"
# Now set as DBTMP
export TMPDIR="$DBTMP"
export TMP="$DBTMP"
@ -1856,6 +1907,7 @@ do
echo ""
echo " 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache."
echo " 22 - 'purge' - Purge (remove) all temporary files left by PMS & Transcoder in Temp Dir."
[ $IgnoreErrors -eq 0 ] && echo " 42 - 'ignore' - Ignore duplicate/constraint errors."
[ $IgnoreErrors -eq 1 ] && echo " 42 - 'honor' - Honor all database errors."
@ -2175,6 +2227,19 @@ do
WriteLog "Prune - PASS"
;;
22|purg*)
# Check if PMS running
if IsRunning; then
WriteLog "Purge - FAIL - PMS runnning"
Output "Unable to purge temp files. PMS is running."
continue
fi
WriteLog "Purge - START"
DoPurgeTmp
WriteLog "Purge - PASS"
;;
# Ignore/Honor errors
42|igno*|hono*)

View File

@ -35,6 +35,7 @@ If sufficient privleges exist (root), and supported by the environment, the opti
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
PURG(e) - Purge (delete) all temporary files left behind by PMS & the transcoder from the temp directory
REIN(dex) - Rebuild the database indexes
REPL(ace) - Replace the existing databases with a PMS-generated backup
SHOW - Show the log file
@ -51,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.03.00
Version v1.09.00
Select
@ -70,6 +71,7 @@ If sufficient privleges exist (root), and supported by the environment, the opti
12 - 'undo' - Undo last successful command.
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.
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.
@ -126,6 +128,9 @@ Enter command # -or- command name (4 char min) :
```
Plex,inc and LSIO docker images are included in "Docker" platform category independent of the actual host.
Additional hosts and docker images can easily be supported in almost all cases with appropriate path
information. Please contact me as needed.
### General installation and usage instructions
@ -909,7 +914,7 @@ root@Jasper:/mnt/user/appdata/PlexMediaServer# /tmp/DBRepair.sh --databases /mnt
Plex Media Server Database Repair Utility (User Defined)
Version v1.06.00
Version v1.09.00
PlexSQLite = '/var/lib/docker/btrfs/subvolumes/4bb78fb70589d4d2ba56754f4d6bc0edd4cdaa8eab7986943767e09a66cefd19/usr/lib/plexmediaserver//Plex SQLite'
Databases = '/mnt/user/appdata/PlexMediaServer/Library/Application Support/Plex Media Server/Plug-in Support/Databases/'
@ -930,7 +935,9 @@ 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.
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.'
42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates.

View File

@ -8,6 +8,16 @@
![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg)
# Release Info:
v1.09.00
1. Purge command - Add 'purge' command to clean up all temporary transcoder and image files.
(usually found in /tmp)
v1.08.00
1. Linuxserver.io - Add support for new start/stop path.
Silently support both previous and new path start/stop mechanisms.
v1.07.00
1. Mac start/stop - DBRepair now supports start/stop from the menu.