mirror of
https://github.com/ChuckPa/PlexDBRepair.git
synced 2025-11-06 03:08:55 -05:00
Merge pull request #105 from ChuckPa/chuckpa/UpdateDBRepair
v1.01.00 - Add self-update capability
This commit is contained in:
commit
2958fb5c26
109
DBRepair.sh
109
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.0.13 #
|
# Version: v1.01.00 #
|
||||||
# Date: 23-Sep-2023 #
|
# Date: 16-Oct-2023 #
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
# Version for display purposes
|
# Version for display purposes
|
||||||
Version="v1.0.13"
|
Version="v1.01.00"
|
||||||
|
|
||||||
# Flag when temp files are to be retained
|
# Flag when temp files are to be retained
|
||||||
Retain=0
|
Retain=0
|
||||||
@ -303,6 +303,13 @@ RestoreSaved() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Return only the digits in the given version string
|
||||||
|
VersionDigits() {
|
||||||
|
local ver
|
||||||
|
ver=$(echo "$1" | tr -d [v\.] )
|
||||||
|
echo $ver
|
||||||
|
}
|
||||||
|
|
||||||
# Get the size of the given DB in MB
|
# Get the size of the given DB in MB
|
||||||
GetSize() {
|
GetSize() {
|
||||||
|
|
||||||
@ -1430,40 +1437,50 @@ DoOptions() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
##### UpdateTimestamp
|
# UpdateTimestamp
|
||||||
DoUpdateTimestamp() {
|
DoUpdateTimestamp() {
|
||||||
TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")"
|
TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get latest version from Github
|
# Get latest version from Github
|
||||||
GetLatestRelease() {
|
GetLatestRelease() {
|
||||||
response=$(curl -s "https://api.github.com/repos/ChuckPa/PlexDBRepair/tags")
|
Response=$(curl -s "https://api.github.com/repos/ChuckPa/PlexDBRepair/tags")
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
LatestVersion=$(echo "$response" | grep -oP '"name":\s*"\K[^"]*' | sed -n '1p')
|
LatestVersion="$(echo "$Response" | grep -oP '"name":\s*"\K[^"]*' | sed -n '1p' | tr -d '[v\.]')"
|
||||||
else
|
else
|
||||||
LatestVersion=$Version
|
LatestVersion="$Version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download and update script
|
# Download and update script
|
||||||
DownloadAndUpdate() {
|
DownloadAndUpdate() {
|
||||||
url="$1"
|
Url="$1"
|
||||||
filename="$2"
|
Filename="$2"
|
||||||
|
|
||||||
# Download the file and check if the download was successful
|
# Download the file and check if the download was successful
|
||||||
if curl -s "$url" --output "$filename"; then
|
if curl -s "$Url" --output "${Filename}.tmp"; then
|
||||||
Output "Update downloaded successfully"
|
# Check if the file was written to and at least 50000 bytes
|
||||||
|
if [ -f "${Filename}.tmp" ]; then
|
||||||
# Check if the file was written to
|
if [ $(stat $STATFMT $STATBYTES "${Filename}.tmp") -gt 50000 ]; then
|
||||||
if [ -f "$filename" ]; then
|
Output "Update downloaded successfully"
|
||||||
Output "Update written successfully"
|
mv "$Filename" "${Filename}.bak"
|
||||||
|
mv "${Filename}.tmp" "$Filename"
|
||||||
|
chmod +x "$Filename"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
Output "Error: Downloaded file incomplete."
|
||||||
|
rm -f "${Filename}.tmp"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
Output "Error: File not written"
|
Output "Error: Unable to download update."
|
||||||
|
rm -f "${Filename}.tmp"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
Output "Error: Download failed"
|
Output "Error: Download failed."
|
||||||
|
rm -f "${Filename}.tmp"
|
||||||
fi
|
fi
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################################################
|
#############################################################
|
||||||
@ -1471,7 +1488,7 @@ DownloadAndUpdate() {
|
|||||||
#############################################################
|
#############################################################
|
||||||
|
|
||||||
# Set Script Path
|
# Set Script Path
|
||||||
ScriptPath="$( readlink -f "$0")"
|
ScriptPath="$(readlink -f "$0")"
|
||||||
ScriptName="$(basename "$ScriptPath")"
|
ScriptName="$(basename "$ScriptPath")"
|
||||||
ScriptWorkingDirectory="$(dirname "$ScriptPath")"
|
ScriptWorkingDirectory="$(dirname "$ScriptPath")"
|
||||||
|
|
||||||
@ -1588,24 +1605,24 @@ do
|
|||||||
echo ""
|
echo ""
|
||||||
echo "Select"
|
echo "Select"
|
||||||
echo ""
|
echo ""
|
||||||
[ $HaveStartStop -gt 0 ] && echo " 1 - 'stop' - Stop PMS"
|
[ $HaveStartStop -gt 0 ] && echo " 1 - 'stop' - Stop PMS."
|
||||||
[ $HaveStartStop -eq 0 ] && echo " 1 - 'stop' - (Not available. Stop manually)"
|
[ $HaveStartStop -eq 0 ] && echo " 1 - 'stop' - (Not available. Stop manually.)"
|
||||||
echo " 2 - 'automatic' - database check, repair/optimize, and reindex in one step."
|
echo " 2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step."
|
||||||
echo " 3 - 'check' - Perform integrity check of database"
|
echo " 3 - 'check' - Perform integrity check of database."
|
||||||
echo " 4 - 'vacuum' - Remove empty space from database"
|
echo " 4 - 'vacuum' - Remove empty space from database without optimizing."
|
||||||
echo " 5 - 'repair' - Repair/Optimize databases"
|
echo " 5 - 'repair' - Repair/Optimize databases."
|
||||||
echo " 6 - 'reindex' - Rebuild database database indexes"
|
echo " 6 - 'reindex' - Rebuild database database indexes."
|
||||||
|
|
||||||
[ $HaveStartStop -gt 0 ] && echo " 7 - 'start' - Start PMS"
|
[ $HaveStartStop -gt 0 ] && echo " 7 - 'start' - Start PMS"
|
||||||
[ $HaveStartStop -eq 0 ] && echo " 7 - 'start' - (Not available. Start manually)"
|
[ $HaveStartStop -eq 0 ] && echo " 7 - 'start' - (Not available. Start manually)"
|
||||||
echo ""
|
echo ""
|
||||||
echo " 8 - 'import' - Import watch history from another database independent of Plex. (risky)"
|
echo " 8 - 'import' - Import watch history from another database independent of Plex. (risky)."
|
||||||
echo " 9 - 'replace' - Replace current databases with newest usable backup copy (interactive)"
|
echo " 9 - 'replace' - Replace current databases with newest usable backup copy (interactive)."
|
||||||
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 " 88 - 'update' - Check for script update"
|
echo " 88 - 'update' - Check for updates."
|
||||||
echo " 99 - 'quit' - Quit immediately. Keep all temporary files."
|
echo " 99 - 'quit' - Quit immediately. Keep all temporary files."
|
||||||
echo " 'exit' - Exit with cleanup options."
|
echo " 'exit' - Exit with cleanup options."
|
||||||
fi
|
fi
|
||||||
@ -1910,29 +1927,33 @@ do
|
|||||||
88|upda*)
|
88|upda*)
|
||||||
|
|
||||||
DoUpdate=0
|
DoUpdate=0
|
||||||
Output "Checking for script update"
|
Output "Checking for update"
|
||||||
GetLatestRelease
|
GetLatestRelease
|
||||||
if [ $LatestVersion != $Version ] && ([ $Scripted -eq 1 ] || ConfirmYesNo "Download and update script?"); then
|
if [ $(VersionDigits $LatestVersion) -gt $(VersionDigits $Version) ]; then
|
||||||
DoUpdate=1
|
[ $Scripted -eq 1 ] && DoUpdate=1
|
||||||
Output "Version update available"
|
[ ConfirmYesNo "Download $Latest and update?" ] && DoUpdate=1
|
||||||
else
|
else
|
||||||
Output "No update available or user declined update"
|
Output "No update available."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if script path is writable
|
# Check if script path is writable
|
||||||
if [ $DoUpdate -eq 1 ]; then
|
if [ $DoUpdate -eq 1 ]; then
|
||||||
if [ -w "$ScriptWorkingDirectory" ]; then
|
if [ -w "$ScriptWorkingDirectory" ]; then
|
||||||
Output "Performing update"
|
Output "Updating from $Version to $LatestVersion"
|
||||||
DownloadAndUpdate "https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh" "$ScriptWorkingDirectory/$ScriptName"
|
DownloadAndUpdate "https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh" "$ScriptWorkingDirectory/$ScriptName"
|
||||||
exit 0
|
Result=$?
|
||||||
|
if [ $Result -eq 0 ]; then
|
||||||
|
chmod +x "$ScriptWorkingDirectory/$ScriptName"
|
||||||
|
Output "Restart to launch updated DBRepair.sh ($LatestVersion)"
|
||||||
|
WriteLog "Update - Updated to version $LatestVersion."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
Output "Script path is not writable."
|
Output "Script path '${ScriptName}' is not writable."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $Scripted -eq 1 ]; then
|
[ $Scripted -eq 1 ] && [ $DoUpdate -eq 1 ] && exit 0
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Quit
|
# Quit
|
||||||
|
|||||||
179
README.md
179
README.md
@ -50,24 +50,27 @@ 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.0
|
Version v1.01.00
|
||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
1 - 'stop' PMS (if available)
|
1 - 'stop' - Stop PMS.
|
||||||
2 - 'automatic' database check, repair/optimize, and reindex in one step.
|
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
|
||||||
3 - 'check' database
|
3 - 'check' - Perform integrity check of database.
|
||||||
4 - 'vacuum' database
|
4 - 'vacuum' - Remove empty space from database without optimizing.
|
||||||
5 - 'repair' / 'optimize' database
|
5 - 'repair' - Repair/Optimize databases.
|
||||||
6 - 'reindex' database
|
6 - 'reindex' - Rebuild database database indexes.
|
||||||
7 - 'start' PMS (if available)
|
7 - 'start' - Start PMS
|
||||||
8 - 'import' viewstate (Watch history) from another PMS database
|
|
||||||
9 - 'replace' current database with newest usable backup copy (interactive)
|
|
||||||
10 - 'show' logfile
|
|
||||||
11 - 'status' of PMS (Stop/Run and databases)
|
|
||||||
12 - 'undo' - Undo last successful command
|
|
||||||
|
|
||||||
99 - exit
|
8 - 'import' - Import watch history from another database independent of Plex. (risky).
|
||||||
|
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
|
||||||
|
10 - 'show' - Show logfile.
|
||||||
|
11 - 'status' - Report status of PMS (run-state and databases).
|
||||||
|
12 - 'undo' - Undo last successful command.
|
||||||
|
|
||||||
|
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) :
|
||||||
|
|
||||||
@ -294,50 +297,54 @@ bash-4.4# ./DBRepair.sh
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Plex Media Server Database Repair Utility (Synology (DSM 7))
|
Plex Media Server Database Repair Utility (Ubuntu 20.04.6 LTS)
|
||||||
Version v1.0.0
|
Version v1.01.00
|
||||||
|
|
||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
1 - 'stop' - Stop PMS
|
1 - 'stop' - Stop PMS.
|
||||||
2 - 'automatic' - database check, repair/optimize, and reindex 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
|
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.
|
||||||
|
|
||||||
99 - exit
|
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) : 1
|
Enter command # -or- command name (4 char min) : 1
|
||||||
|
|
||||||
Stopping PMS.
|
Stopping PMS.
|
||||||
Stopped PMS.
|
Stopped PMS.
|
||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
1 - 'stop' - Stop PMS
|
1 - 'stop' - Stop PMS.
|
||||||
2 - 'automatic' - database check, repair/optimize, and reindex 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
|
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.
|
||||||
|
|
||||||
99 - exit
|
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) : auto
|
Enter command # -or- command name (4 char min) : auto
|
||||||
|
|
||||||
@ -372,19 +379,23 @@ Automatic Check,Repair/optimize,Index successful.
|
|||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
1 - 'stop' PMS
|
1 - 'stop' - Stop PMS.
|
||||||
2 - 'automatic' database check, repair/optimize, and reindex in one step.
|
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
|
||||||
3 - 'check' database
|
3 - 'check' - Perform integrity check of database.
|
||||||
4 - 'vacuum' database
|
4 - 'vacuum' - Remove empty space from database without optimizing.
|
||||||
5 - 'repair' / 'optimize' database
|
5 - 'repair' - Repair/Optimize databases.
|
||||||
6 - 'reindex' database
|
6 - 'reindex' - Rebuild database database indexes.
|
||||||
7 - 'start' PMS
|
7 - 'start' - Start PMS
|
||||||
8 - 'import' viewstate (Watch history) from another PMS database
|
|
||||||
9 - 'replace' current database with newest usable backup copy (interactive)
|
8 - 'import' - Import watch history from another database independent of Plex. (risky).
|
||||||
10 - 'show' logfile
|
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
|
||||||
11 - 'status' of PMS (Stop/Run and databases)
|
10 - 'show' - Show logfile.
|
||||||
12 - 'undo' - Undo last successful command
|
11 - 'status' - Report status of PMS (run-state and databases).
|
||||||
99 - exit
|
12 - 'undo' - Undo last successful command.
|
||||||
|
|
||||||
|
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) : start
|
Enter command # -or- command name (4 char min) : start
|
||||||
|
|
||||||
@ -393,19 +404,23 @@ Started PMS
|
|||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
1 - 'stop' PMS
|
1 - 'stop' - Stop PMS.
|
||||||
2 - 'automatic' database check, repair/optimize, and reindex in one step.
|
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
|
||||||
3 - 'check' database
|
3 - 'check' - Perform integrity check of database.
|
||||||
4 - 'vacuum' database
|
4 - 'vacuum' - Remove empty space from database without optimizing.
|
||||||
5 - 'repair' / 'optimize' database
|
5 - 'repair' - Repair/Optimize databases.
|
||||||
6 - 'reindex' database
|
6 - 'reindex' - Rebuild database database indexes.
|
||||||
7 - 'start' PMS
|
7 - 'start' - Start PMS
|
||||||
8 - 'import' viewstate (Watch history) from another PMS database
|
|
||||||
9 - 'replace' current database with newest usable backup copy (interactive)
|
8 - 'import' - Import watch history from another database independent of Plex. (risky).
|
||||||
10 - 'show' logfile
|
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
|
||||||
11 - 'status' of PMS (Stop/Run and databases)
|
10 - 'show' - Show logfile.
|
||||||
12 - 'undo' - Undo last successful command
|
11 - 'status' - Report status of PMS (run-state and databases).
|
||||||
99 - exit
|
12 - 'undo' - Undo last successful command.
|
||||||
|
|
||||||
|
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) : stat
|
Enter command # -or- command name (4 char min) : stat
|
||||||
|
|
||||||
@ -417,19 +432,23 @@ Status report: Sat Feb 25 04:38:50 PM EST 2023
|
|||||||
|
|
||||||
Select
|
Select
|
||||||
|
|
||||||
1 - 'stop' PMS
|
1 - 'stop' - Stop PMS.
|
||||||
2 - 'automatic' database check, repair/optimize, and reindex in one step.
|
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
|
||||||
3 - 'check' database
|
3 - 'check' - Perform integrity check of database.
|
||||||
4 - 'vacuum' database
|
4 - 'vacuum' - Remove empty space from database without optimizing.
|
||||||
5 - 'repair' / 'optimize' database
|
5 - 'repair' - Repair/Optimize databases.
|
||||||
6 - 'reindex' database
|
6 - 'reindex' - Rebuild database database indexes.
|
||||||
7 - 'start' PMS
|
7 - 'start' - Start PMS
|
||||||
8 - 'import' viewstate (Watch history) from another PMS database
|
|
||||||
9 - 'replace' current database with newest usable backup copy (interactive)
|
8 - 'import' - Import watch history from another database independent of Plex. (risky).
|
||||||
10 - 'show' logfile
|
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
|
||||||
11 - 'status' of PMS (Stop/Run and databases)
|
10 - 'show' - Show logfile.
|
||||||
12 - 'undo' - Undo last successful command
|
11 - 'status' - Report status of PMS (run-state and databases).
|
||||||
99 - exit
|
12 - 'undo' - Undo last successful command.
|
||||||
|
|
||||||
|
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) : exit
|
Enter command # -or- command name (4 char min) : exit
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,10 @@
|
|||||||

|

|
||||||
|
|
||||||
# Release Info:
|
# Release Info:
|
||||||
|
v1.01.00
|
||||||
|
|
||||||
|
- Adds ability to self download and install latest version of DBRepair.sh
|
||||||
|
- Slightly changes numbering style to accommodate future updates with new update capability.
|
||||||
|
|
||||||
v1.0.13
|
v1.0.13
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user