mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 03:20:12 -08:00
- Introduced `recover-plex-database.sh` for comprehensive database recovery with multiple strategies, logging, and rollback capabilities. - Added `restore-plex.sh` for safe restoration of Plex backups, including validation and dry-run options. - Created `plex-db-manager.sh` to consolidate database management functionalities, including integrity checks and service management. - Enhanced logging and error handling across all scripts for better user feedback and troubleshooting. - Implemented safety measures to prevent running scripts as root and ensure proper service management during operations.
4.1 KiB
4.1 KiB
Plex Database Corruption Resolution Summary
✅ ISSUE RESOLVED: Auto-Repair Cycle Causing Corruption
Root Cause Identified
The primary cause of your Plex database corruption was an aggressive auto-repair schedule running every 30 minutes via cron:
# PROBLEMATIC (FIXED):
*/30 * * * * /home/acedanger/shell/plex/backup-plex.sh --check-integrity --auto-repair
This caused:
- 48+ service stops/starts per day
- WAL file manipulation conflicts
- Repair cascading failures
- Race conditions during service transitions
✅ Changes Applied
1. Fixed Crontab Schedule
- Before: Auto-repair every 30 minutes + daily backup with auto-repair
- After:
- Daily read-only integrity check (6 AM)
- Daily backup with auto-repair disabled (4:15 AM)
- Manual repair intervention required
2. Disabled Auto-Repair Default
- Changed
backup-plex.shdefault fromAUTO_REPAIR=truetoAUTO_REPAIR=false - Prevents automatic repair loops that were causing corruption
3. Created Consolidated Management Tool
- New script:
plex-db-manager.sh - Safe, read-only integrity checking
- Manual repair intervention (currently disabled for safety)
- Proper service management with synchronization
4. Database Status ✅
Current check shows: ALL DATABASES HEALTHY
- Main database: integrity check PASSED
- Blobs database: integrity check PASSED
📋 Script Redundancy Analysis
Scripts with Overlapping Functionality
plex.sh- Service management + basic repairbackup-plex.sh- Backup + auto-repair logicplex-database-repair.sh- Dedicated repair functionsrecover-plex-database.sh- Advanced recovery methodsnuclear-plex-recovery.sh- Nuclear recoveryrestore-plex.sh- Backup restoration
Consolidation Recommendations
Keep Active:
backup-plex.sh- Primary backup (with auto-repair disabled)plex-db-manager.sh- New consolidated management toolplex.sh- Basic service managementnuclear-plex-recovery.sh- Last resort recovery
Consider Deprecating:
plex-database-repair.sh- Functionality moved toplex-db-manager.shrecover-plex-database.sh- Similar functionality in other scriptsrestore-plex.sh- Basic functionality covered elsewhere
🛡️ Prevention Measures Implemented
1. Conservative Backup Schedule
# Read-only check (daily at 6 AM)
0 6 * * * backup-plex.sh --check-integrity --disable-auto-repair
# Backup without auto-repair (daily at 4:15 AM)
15 4 * * * backup-plex.sh --non-interactive --disable-auto-repair
2. Manual Intervention Required
- No automatic repairs unless explicitly requested
- All repair operations require manual approval
- Comprehensive logging for audit trail
3. Safe Service Management
- Proper service stop/start synchronization
- Extended timeouts for clean shutdowns
- Race condition prevention
📊 Expected Improvements
- Stability: Eliminated 47 daily service interruptions
- Reliability: No more auto-repair corruption loops
- Performance: Reduced I/O load on database files
- Maintainability: Centralized database management
🔧 Usage Going Forward
Regular Monitoring:
# Check database health (safe, read-only)
./plex-db-manager.sh check
If Issues Detected:
# View detailed logs
tail -f /home/acedanger/shell/plex/logs/plex-backup-$(date +%Y-%m-%d).log
# Manual repair (when re-enabled)
./plex-db-manager.sh repair
Emergency Recovery:
# Only if all else fails
sudo ./nuclear-plex-recovery.sh --auto
⚠️ Critical Notes
- Auto-repair is temporarily disabled until stability is confirmed
- Manual intervention required for any database issues
- Monitor logs closely for the next week to ensure stability
- Backup integrity should improve significantly
Date Fixed: June 21, 2025
Issue: 30-minute auto-repair cycle causing database corruption
Resolution: Disabled aggressive auto-repair, implemented safe backup schedule
Status: ✅ RESOLVED - Databases currently healthy