From de8bb489013c524862cafa0e2a95eec082b238c1 Mon Sep 17 00:00:00 2001 From: ChuckPa Date: Wed, 14 Dec 2022 01:42:44 -0500 Subject: [PATCH] Improve database backup selection logic, Add BINHEX support Added informative output and correct issue selecting final available backup. Added binhex (Arch) docker support Updated READMEmd Add support for all Docker variants Change detection to use cgroup Add BINHEX support, Update README.md --- DBRepair.sh | 35 +++++++++++++++++++++++++---------- README.md | 45 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/DBRepair.sh b/DBRepair.sh index 9a0bd89..1678e44 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -396,8 +396,8 @@ HostConfig() { return 0 - # Docker - elif [ -f /bin/s6-svscan ] && [ -d "/config/Library/Application Support" ]; then + # Docker (All main docker variants except binhex) + elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] && [ -d "/config/Library/Application Support" ]; then PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite" AppSuppDir="/config/Library/Application Support" @@ -409,6 +409,19 @@ HostConfig() { HostType="Docker" return 0 + # BINHEX Plex container + elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] && [ -d "/config/Plex Media Server" ]; then + + PLEX_SQLITE="/usr/lib/plexmediaserver/Plex SQLite" + AppSuppDir="/config" + PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" + DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases" + LOGFILE="$DBDIR/DBRepair.log" + LOG_TOOL="logger" + + HostType="BINHEX" + return 0 + # Western Digital (OS5) elif [ -f /etc/system.conf ] && [ -d /mnt/HD/HD_a2/Nas_Prog/plexmediaserver ] && \ grep "Western Digital Corp" /etc/system.conf >/dev/null; then @@ -959,14 +972,16 @@ do Output "Checking for a usable backup." Candidate="" + Output "Database backups available are: $Dates" for i in $Dates do # Check candidate - if [ -e $CPPL.db-$i ] && \ - [ -e $CPPL.blobs.db-$i ] && \ - CheckDB $CPPL.db-$i && \ - CheckDB $CPPL.blobs.db-$i ; then + if [ -e $CPPL.db-$i ] && \ + [ -e $CPPL.blobs.db-$i ] && \ + Output "Checking database $i" && \ + CheckDB $CPPL.db-$i && \ + CheckDB $CPPL.blobs.db-$i ; then Output "Found valid database backup date: $i" Candidate=$i @@ -1052,11 +1067,11 @@ do WriteLog "Replace - Verify databases - FAIL" Fail=1 fi - fi - # If successful, save - [ $Fail -eq 0 ] && SetLast "Replace" "$TimeStamp" - break + # If successful, save + [ $Fail -eq 0 ] && SetLast "Replace" "$TimeStamp" + break + fi fi done diff --git a/README.md b/README.md index cb9b909..61816a9 100644 --- a/README.md +++ b/README.md @@ -49,15 +49,18 @@ It is a simple menu-driven utility with a command line backend. ``` Vendor | Shared folder name | directory -------------------+---------------------+------------------------------------------ + Apple | Downloads | ~/Downloads ASUSTOR | Public | /volume1/Public - Netgear (ReadyNAS) | "your_choice" | "/data/your_choice" - Synology (DSM 6) | Plex | /volume1/Plex (change volume as required) - Synology (DSM 7) | PlexMediaServer | /volume1/PlexMediaServer (change volume as required) - QNAP (QTS/QuTS) | Public | /share/Public - Western Digital | Public | /mnt/HD/HD_a2/Public (Does not support 'MyCloudHome' series) + binhex | N/A | Container root (adjacent /config) Docker | N/A | Container root (adjacent /config) Linux (wkstn/svr) | N/A | Anywhere - Apple | Downloads | ~/Downloads + Netgear (ReadyNAS) | "your_choice" | "/data/your_choice" + QNAP (QTS/QuTS) | Public | /share/Public + Synology (DSM 6) | Plex | /volume1/Plex (change volume as required) + Synology (DSM 7) | PlexMediaServer | /volume1/PlexMediaServer (change volume as required) + Western Digital | Public | /mnt/HD/HD_a2/Public (Does not support 'MyCloudHome' series) + + ``` ### To install & launch on general Linux or most Linux NAS platforms: 1. Place the tar/zip/sh file in the appropriate directory @@ -70,7 +73,7 @@ It is a simple menu-driven utility with a command line backend. ``` cd /volume1/Plex sudo bash - tar xf DBRepair.tar + tar xf DBRepair.tar.gz chmod +x DBRepair.sh ./DBRepair.sh ``` @@ -84,9 +87,13 @@ It is a simple menu-driven utility with a command line backend. --or-- # Stop Plex when using Linuxserver.io Plex image s6-svc -d /var/run/service/svc-plex +--or-- + # Stop Plex in binhex containers + kill -15 $(pidof 'Plex Media Server') - tar xf DBRepair.tar + + tar xf DBRepair.tar.gz chmod +x DBRepair.sh ./DBRepair.sh ``` @@ -95,7 +102,7 @@ It is a simple menu-driven utility with a command line backend. sudo bash systemctl stop plexmediaserver cd /path/to/DBRepair.tar - tar xf DBRepair.tar + tar xf DBRepair.tar.gz ./DBRepair.sh ``` @@ -179,6 +186,22 @@ Special considerations: if desired for special / manual recovery cases. ``` +## Scripting support + + Certain platforms don't provide for each command line access. + To support those products, this utility can be operated by adding command line arguments. + + Another use of this feature is to automate Plex Database maintenance + ( Stop Plex, Run this sequence, Start Plex ) at a time when the server isn't busy + + + The command line arguments are the same as if typing at the menu. + + Example: ./DBRepair.sh 1 4 3 9 + + This executes: Check, Repair, Reindex, and Exit commands + + ## Exiting When exiting, you will be asked whether to keep the interim temp files created during this session. @@ -188,7 +211,9 @@ Special considerations: ## Sample session - This sample session shows: + + + This sample session shows all the features present. You won't use : 1. PMS exclusive access to the databases interlock protecting your data 2. Basic checks, vacuum, and reindex 3. Full export/import (repair) which also reloads the database in perfect order