From a34511a2190bedf5dc36cbd0fbfce3c7b3a915a1 Mon Sep 17 00:00:00 2001 From: ChuckPa Date: Fri, 16 May 2025 16:29:36 -0400 Subject: [PATCH] May 2025 cleanup Minor DB Cleanup extras. --- DBRepair.sh | 43 +++++++++++++++++++++++++++++++++++++++---- ReleaseNotes | 5 +++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/DBRepair.sh b/DBRepair.sh index 77164ae..07ac292 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -2,12 +2,12 @@ ######################################################################### # Plex Media Server database check and repair utility script. # # Maintainer: ChuckPa # -# Version: v1.10.03 # -# Date: 17-Mar-2025 # +# Version: v1.10.05 # +# Date: 20-May-2025 # ######################################################################### # Version for display purposes -Version="v1.10.03" +Version="v1.10.05" # Have the databases passed integrity checks CheckedDB=0 @@ -976,6 +976,9 @@ DoRepair() { return 1 fi + # Temporary DB actions + "$PLEX_SQLITE" $CPPL.db "DELETE from statistics_bandwidth where account_id is NULL;" + # Continue Output "Exporting current databases using timestamp: $TimeStamp" Fail=0 @@ -2098,7 +2101,6 @@ do fi ;; - # Vacuum 4|vacu*) @@ -2268,6 +2270,39 @@ do WriteLog "Prune - PASS" ;; + + # Records count + 30|coun*) + + Temp="$DBDIR/DBRepair.tab1" + Temp2="$DBDIR/DBRepair.tab2" + + # Ensure clean + rm -f "$Temp" "$Temp2" + + # Get list of tables + Tables="$("$PLEX_SQLITE" "$DBDIR/com.plexapp.plugins.library.db" .tables | sed 's/ /\n/g')" + + # Separate and sort tables + for i in $Tables + do + echo $i >> "$Temp" + done + sort < "$Temp" > "$Temp2" + + Tables="$(cat "$Temp2")" + + # Get counts + for Table in $Tables + do + Records=$("$PLEX_SQLITE" "$DBDIR/com.plexapp.plugins.library.db" "select count(*) from $Table;") + printf "%36s %-15d\n" $Table $Records + done + + # Cleanup + rm -f "$Temp" "$Temp2" + ;; + # Ignore/Honor errors 42|igno*|hono*) diff --git a/ReleaseNotes b/ReleaseNotes index ea5e50b..e228503 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -8,6 +8,11 @@ ![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg) # Release Info: +v1.10.05 + + 1. DB Cleanup - Temporary assist with PMS database cleanups + 2. Record Count report - Report the number of records in each main DB table. (Monitoring growth) + v1.10.03 1. LC_ALL - When LC_ALL="", set LC_ALL=C (MacOS now needs this)