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

@@ -78,7 +78,8 @@ mkdir -p "$(dirname "$RECOVERY_LOG")"
log_message() {
local level="$1"
local message="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $message" | tee -a "$RECOVERY_LOG"
}
@@ -180,7 +181,8 @@ find_best_backup() {
# Find the most recent backup that exists and has reasonable size
for backup_file in "${PLEX_DB_DIR}/${backup_type}"-????-??-??*; do
if [[ -f "$backup_file" ]]; then
local file_size=$(stat -f%z "$backup_file" 2>/dev/null || stat -c%s "$backup_file" 2>/dev/null)
local file_size
file_size=$(stat -f%z "$backup_file" 2>/dev/null || stat -c%s "$backup_file" 2>/dev/null)
# Check if file size is reasonable (> 100MB for main DB, > 500MB for blobs)
if [[ "$backup_type" == "com.plexapp.plugins.library.db" && $file_size -gt 104857600 ]] || \
@@ -198,7 +200,8 @@ restore_from_backup() {
print_status "$YELLOW" "Finding and restoring from best available backups..."
# Find best main database backup
local main_backup=$(find_best_backup "com.plexapp.plugins.library.db")
local main_backup
main_backup=$(find_best_backup "com.plexapp.plugins.library.db")
if [[ -n "$main_backup" ]]; then
print_status "$GREEN" "Found main database backup: $(basename "$main_backup")"
@@ -219,7 +222,8 @@ restore_from_backup() {
fi
# Find best blobs database backup
local blobs_backup=$(find_best_backup "com.plexapp.plugins.library.blobs.db")
local blobs_backup
blobs_backup=$(find_best_backup "com.plexapp.plugins.library.blobs.db")
if [[ -n "$blobs_backup" ]]; then
print_status "$GREEN" "Found blobs database backup: $(basename "$blobs_backup")"
@@ -275,7 +279,8 @@ fix_ownership() {
local blobs_db="${PLEX_DB_DIR}/com.plexapp.plugins.library.blobs.db"
if [[ -f "$main_db" ]]; then
local main_owner=$(stat -f%Su:%Sg "$main_db" 2>/dev/null || stat -c%U:%G "$main_db" 2>/dev/null)
local main_owner
main_owner=$(stat -f%Su:%Sg "$main_db" 2>/dev/null || stat -c%U:%G "$main_db" 2>/dev/null)
if [[ "$main_owner" == "$PLEX_USER:$PLEX_GROUP" ]]; then
print_status "$GREEN" "Main database ownership: CORRECT ($main_owner)"
else