mirror of
https://github.com/ChuckPa/PlexDBRepair.git
synced 2025-11-06 03:08:55 -05:00
Merge pull request #180 from ChuckPa/chuckpa/cleanup-purge
Minor cleanup from 1.10 release
This commit is contained in:
commit
804c9014d1
104
DBRepair.sh
104
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.09.00 #
|
# Version: v1.10.01 #
|
||||||
# Date: 06-Nov-2024 #
|
# Date: 02-Jan-2025 #
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
# Version for display purposes
|
# Version for display purposes
|
||||||
Version="v1.09.00"
|
Version="v1.10.01"
|
||||||
|
|
||||||
# Have the databases passed integrity checks
|
# Have the databases passed integrity checks
|
||||||
CheckedDB=0
|
CheckedDB=0
|
||||||
@ -1146,14 +1146,14 @@ DoRepair() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
##### DoReplace
|
##### Replace current DB with a valid backup DB (if available)
|
||||||
DoReplace() {
|
DoReplace() {
|
||||||
|
|
||||||
# If Databases already checked, confirm the user really wants to do this
|
# If Databases already checked, confirm the user really wants to do this
|
||||||
Confirmed=0
|
Confirmed=0
|
||||||
Fail=0
|
Fail=0
|
||||||
if CheckDatabases "Replace"; then
|
if CheckDatabases "Replace"; then
|
||||||
if ConfirmYesNo "Are you sure you want to restore a previous database backup"; then
|
if ConfirmYesNo "Are you sure you want to restore a previous database backup "; then
|
||||||
Confirmed=1
|
Confirmed=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -1181,23 +1181,69 @@ DoReplace() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
Output "Database backups available are: $Dates"
|
Output "Database backups available are: $Dates"
|
||||||
|
Output " "
|
||||||
|
Count=0
|
||||||
|
Selection=0
|
||||||
|
Candidate=""
|
||||||
|
Valid=0
|
||||||
|
|
||||||
|
# Print the list of dates
|
||||||
for i in $Dates
|
for i in $Dates
|
||||||
do
|
do
|
||||||
|
Count=$((Count + 1))
|
||||||
|
echo " ${Count}) - $i"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Get the selection
|
||||||
|
Selection=""
|
||||||
|
Output " "
|
||||||
|
echo -n "Select backup date by number or date name (blank = return to menu) "
|
||||||
|
read Selection
|
||||||
|
|
||||||
|
# If no selection - return
|
||||||
|
[ "$Selection" = "" ] && return
|
||||||
|
|
||||||
|
# Search for match
|
||||||
|
Candidate=""
|
||||||
|
Count=0
|
||||||
|
for i in $Dates; do
|
||||||
|
Count=$((Count + 1))
|
||||||
|
if [ "$Selection" = "$Count" ] || [ "$Selection" = "$i" ]; then
|
||||||
|
Candidate="$i"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If no match, return
|
||||||
|
if [ "$Candidate" = "" ]; then
|
||||||
|
Output "Error. No valid matching main and blobs database pairs. Cannot replace."
|
||||||
|
WriteLog "Replace - Select candidate - FAIL"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Check candidate
|
# Check candidate
|
||||||
if [ -e $CPPL.db-$i ] && \
|
if [ -e $CPPL.db-$Candidate ] && \
|
||||||
[ -e $CPPL.blobs.db-$i ] && \
|
[ -e $CPPL.blobs.db-$Candidate ] ; then
|
||||||
Output "Checking database $i" && \
|
|
||||||
CheckDB $CPPL.db-$i && \
|
|
||||||
CheckDB $CPPL.blobs.db-$i ; then
|
|
||||||
|
|
||||||
Output "Found valid database backup date: $i"
|
Fail=0
|
||||||
Candidate=$i
|
Output "Checking backup candidate $Candidate"
|
||||||
|
! CheckDB $CPPL.db-$Candidate && Fail=1
|
||||||
|
! CheckDB $CPPL.blobs.db-$Candidate && Fail=1
|
||||||
|
|
||||||
|
[ $Fail -eq 1 ] && Output "Backup from $Candidate is not usable. Try again" && return
|
||||||
|
|
||||||
|
Output "Database backup $Candidate is valid."
|
||||||
UseThis=0
|
UseThis=0
|
||||||
if ConfirmYesNo "Use backup '$Candidate' ?"; then
|
Output " "
|
||||||
|
|
||||||
|
if ConfirmYesNo "Use backup dated: '$Candidate' ?"; then
|
||||||
UseThis=1
|
UseThis=1
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# Did not pass checks
|
||||||
|
Output "One of the backup files is missing. Please make another selection"
|
||||||
|
Fail=1
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# OK, use this one
|
# OK, use this one
|
||||||
if [ $UseThis -eq 1 ]; then
|
if [ $UseThis -eq 1 ]; then
|
||||||
@ -1212,7 +1258,7 @@ DoReplace() {
|
|||||||
WriteLog "Replace - Move Files - PASS"
|
WriteLog "Replace - Move Files - PASS"
|
||||||
|
|
||||||
# Copy this backup into position as primary
|
# Copy this backup into position as primary
|
||||||
Output "Copying backup database $Candidate to use as new database."
|
Output "Copying backup database from $Candidate to use as new database."
|
||||||
|
|
||||||
cp -p $CPPL.db-$Candidate $CPPL.db-REPLACE-$TimeStamp
|
cp -p $CPPL.db-$Candidate $CPPL.db-REPLACE-$TimeStamp
|
||||||
Result=$?
|
Result=$?
|
||||||
@ -1251,6 +1297,7 @@ DoReplace() {
|
|||||||
mv $CPPL.blobs.db-REPLACE-$TimeStamp $CPPL.blobs.db
|
mv $CPPL.blobs.db-REPLACE-$TimeStamp $CPPL.blobs.db
|
||||||
|
|
||||||
# done
|
# done
|
||||||
|
Output " "
|
||||||
Output "Database recovery and verification complete."
|
Output "Database recovery and verification complete."
|
||||||
WriteLog "Replace - Verify databases - PASS"
|
WriteLog "Replace - Verify databases - PASS"
|
||||||
|
|
||||||
@ -1278,15 +1325,6 @@ DoReplace() {
|
|||||||
|
|
||||||
# If successful, save
|
# If successful, save
|
||||||
[ $Fail -eq 0 ] && SetLast "Replace" "$TimeStamp"
|
[ $Fail -eq 0 ] && SetLast "Replace" "$TimeStamp"
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Error check if no Candidate found
|
|
||||||
if [ "$Candidate" = "" ]; then
|
|
||||||
Output "Error. No valid matching main and blobs database pairs. Cannot replace."
|
|
||||||
WriteLog "Replace - Select candidate - FAIL"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -1906,8 +1944,7 @@ do
|
|||||||
echo " 12 - 'undo' - Undo last successful command."
|
echo " 12 - 'undo' - Undo last successful command."
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo " 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache."
|
echo " 21 - 'prune' - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS."
|
||||||
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 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."
|
||||||
|
|
||||||
@ -2213,7 +2250,8 @@ do
|
|||||||
|
|
||||||
|
|
||||||
# Remove (prune) unused image files from PhotoTranscoder Cache > 30 days old.
|
# Remove (prune) unused image files from PhotoTranscoder Cache > 30 days old.
|
||||||
21|prun*|remo*)
|
# Also remove all PMS temp files left behind in TMP. (combine both into one action)
|
||||||
|
21|22|prun*|remo*|purg*)
|
||||||
|
|
||||||
# Check if PMS running
|
# Check if PMS running
|
||||||
if IsRunning; then
|
if IsRunning; then
|
||||||
@ -2227,20 +2265,6 @@ do
|
|||||||
WriteLog "Prune - PASS"
|
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
|
# Ignore/Honor errors
|
||||||
42|igno*|hono*)
|
42|igno*|hono*)
|
||||||
|
|
||||||
|
|||||||
12
ReleaseNotes
12
ReleaseNotes
@ -8,6 +8,18 @@
|
|||||||

|

|
||||||
|
|
||||||
# Release Info:
|
# Release Info:
|
||||||
|
v1.10.01
|
||||||
|
|
||||||
|
1. Minor cleanup - Cleanup purge/prune handling after merging commands into one.
|
||||||
|
|
||||||
|
v1.10.00
|
||||||
|
|
||||||
|
1. Refactor REPLACE - Processing of DB Replace was awkward.
|
||||||
|
List of available databases will now be printed in a menu
|
||||||
|
After selecting the desired DB, the candidate will be checked.
|
||||||
|
(Selection may be by list item # or date printed)
|
||||||
|
If valid (DB and Blobs) replacement will proceed normally.
|
||||||
|
|
||||||
v1.09.00
|
v1.09.00
|
||||||
|
|
||||||
1. Purge command - Add 'purge' command to clean up all temporary transcoder and image files.
|
1. Purge command - Add 'purge' command to clean up all temporary transcoder and image files.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user