Refactor variable assignments and improve script readability in validate-plex-backups.sh and validate-plex-recovery.sh

- Changed inline variable assignments to separate declaration and assignment for clarity.
- Updated condition checks and log messages for better readability and consistency.
- Added a backup of validate-plex-recovery.sh for safety.
- Introduced a new script run-docker-tests.sh for testing setup in Docker containers.
- Enhanced ssh-login.sh to improve condition checks and logging functionality.
This commit is contained in:
Peter Wood
2025-06-05 17:14:02 -04:00
parent c3f237a321
commit 58b5dea8b4
31 changed files with 5024 additions and 539 deletions

View File

@@ -82,11 +82,13 @@ check_service_status() {
print_status "$GREEN" "✓ Plex Media Server is running"
# Get service uptime
local uptime=$(systemctl show plexmediaserver --property=ActiveEnterTimestamp --value)
local uptime
uptime=$(systemctl show plexmediaserver --property=ActiveEnterTimestamp --value)
print_status "$GREEN" " Started: $uptime"
# Get memory usage
local memory=$(systemctl show plexmediaserver --property=MemoryCurrent --value)
local memory
memory=$(systemctl show plexmediaserver --property=MemoryCurrent --value)
if [[ -n "$memory" && "$memory" != "[not set]" ]]; then
local memory_mb=$((memory / 1024 / 1024))
print_status "$GREEN" " Memory usage: ${memory_mb}MB"
@@ -109,12 +111,14 @@ check_database_integrity() {
# Check main database
if [[ -f "$main_db" ]]; then
local main_size=$(du -h "$main_db" | cut -f1)
local main_size
main_size=$(du -h "$main_db" | cut -f1)
print_status "$GREEN" "✓ Main database exists (${main_size})"
# Try basic database operations
if sqlite3 "$main_db" "SELECT COUNT(*) FROM sqlite_master WHERE type='table';" >/dev/null 2>&1; then
local table_count=$(sqlite3 "$main_db" "SELECT COUNT(*) FROM sqlite_master WHERE type='table';" 2>/dev/null)
local table_count
table_count=$(sqlite3 "$main_db" "SELECT COUNT(*) FROM sqlite_master WHERE type='table';" 2>/dev/null)
print_status "$GREEN" " Contains $table_count tables"
else
print_status "$YELLOW" " Warning: Cannot query database tables"
@@ -127,13 +131,15 @@ check_database_integrity() {
# Check blobs database
if [[ -f "$blobs_db" ]]; then
local blobs_size=$(du -h "$blobs_db" | cut -f1)
local blobs_size
blobs_size=$(du -h "$blobs_db" | cut -f1)
print_status "$GREEN" "✓ Blobs database exists (${blobs_size})"
# Check if it's not empty (previous corruption was 0 bytes)
local blobs_bytes=$(stat -c%s "$blobs_db" 2>/dev/null || stat -f%z "$blobs_db" 2>/dev/null)
local blobs_bytes
blobs_bytes=$(stat -c%s "$blobs_db" 2>/dev/null || stat -f%z "$blobs_db" 2>/dev/null)
if [[ $blobs_bytes -gt 1000000 ]]; then
print_status "$GREEN" " File size is healthy ($(numfmt --to=iec $blobs_bytes))"
print_status "$GREEN" " File size is healthy ($(numfmt --to=iec "$blobs_bytes"))"
else
print_status "$RED" " Warning: File size is too small ($blobs_bytes bytes)"
all_good=false
@@ -144,8 +150,10 @@ check_database_integrity() {
fi
# Check file ownership
local main_owner=$(stat -c%U:%G "$main_db" 2>/dev/null)
local blobs_owner=$(stat -c%U:%G "$blobs_db" 2>/dev/null)
local main_owner
main_owner=$(stat -c%U:%G "$main_db" 2>/dev/null)
local blobs_owner
blobs_owner=$(stat -c%U:%G "$blobs_db" 2>/dev/null)
if [[ "$main_owner" == "plex:plex" && "$blobs_owner" == "plex:plex" ]]; then
print_status "$GREEN" "✓ Database ownership is correct (plex:plex)"
@@ -154,7 +162,11 @@ check_database_integrity() {
print_status "$YELLOW" " Main DB: $main_owner, Blobs DB: $blobs_owner"
fi
return $([[ "$all_good" == "true" ]] && echo 0 || echo 1)
if [[ "$all_good" == "true" ]]; then
return 0
else
return 1
fi
}
# Check web interface
@@ -185,7 +197,8 @@ check_api_functionality() {
print_header "API FUNCTIONALITY CHECK"
# Test root API endpoint
local api_response=$(curl -s "http://localhost:32400/" 2>/dev/null)
local api_response
api_response=$(curl -s "http://localhost:32400/" 2>/dev/null)
if echo "$api_response" | grep -q "Unauthorized\|web/index.html"; then
print_status "$GREEN" "✓ API is responding (redirect to web interface)"
@@ -194,7 +207,8 @@ check_api_functionality() {
fi
# Try to get server identity (this might work without auth)
local identity_response=$(curl -s "http://localhost:32400/identity" 2>/dev/null)
local identity_response
identity_response=$(curl -s "http://localhost:32400/identity" 2>/dev/null)
if echo "$identity_response" | grep -q "MediaContainer"; then
print_status "$GREEN" "✓ Server identity endpoint working"