Files
shell/plex/BACKUP-SYSTEM-TRANSITION.md
Peter Wood 9b83924597 Add advanced Plex database recovery and restoration scripts
- 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.
2025-06-21 07:23:33 -04:00

6.1 KiB

Plex Backup System Transition Summary

Date: June 21, 2025
Author: Peter Wood peter@peterwood.dev

🔄 Transition Overview

The Plex backup system has been transitioned from custom scripts to Plex's built-in scheduled backup functionality to reduce complexity and improve reliability.

Changes Made

1. Disabled Custom Backup Cron Jobs

  • Removed daily Plex backup job (4:15 AM)
  • Removed daily integrity check job (6:00 AM)
  • Removed daily backup validation job (7:00 AM)
  • Removed weekly backup report job (Sunday 8:00 AM)

2. Plex Built-in Backup System Active

  • Frequency: Every 3 days (automatic)
  • Location: Database directory + NAS mount /mnt/share/media/backups/plex
  • Pattern: *.backup.YYYYMMDD_HHMMSS
  • Current Status: Active with 1 backup file found

3. Updated Documentation

  • Updated README.md to reflect backup system changes
  • Marked custom backup scripts as disabled/limited use
  • Added new utility script: check-plex-builtin-backups.sh
  • Updated Quick Start and Best Practices sections

4. Scripts Status Change

Script Previous Status New Status
backup-plex.sh Active (daily cron) DISABLED (emergency manual use only)
validate-plex-backups.sh Active (daily cron) ⚠️ LIMITED USE (legacy backups only)
monitor-plex-backup.sh Active monitoring ⚠️ LIMITED USE (basic system monitoring)
plex-db-manager.sh Active ACTIVE (manual health checks)
nuclear-plex-recovery.sh Emergency use ACTIVE (emergency recovery)
plex.sh Service management ACTIVE (service management)
check-plex-builtin-backups.sh N/A NEW (monitor built-in backups)

Daily Operations (Automated)

  • Plex Built-in Backups: Run automatically every 3 days
  • No manual intervention required

Weekly Operations (Manual)

# Health check
./plex-db-manager.sh check

# Check backup status  
./check-plex-builtin-backups.sh

# Service status
./plex.sh status

Emergency Procedures (Unchanged)

# Database issues
./plex-db-manager.sh check
./plex.sh restart
sudo ./nuclear-plex-recovery.sh --dry-run
sudo ./nuclear-plex-recovery.sh --auto

# Validation after recovery
./validate-plex-recovery.sh

📊 Benefits of This Change

Advantages

  1. Reduced Complexity: Fewer moving parts and scripts to maintain
  2. Native Integration: Plex handles its own backup timing and lifecycle
  3. Elimination of Conflicts: No risk of custom scripts interfering with Plex
  4. Simplified Monitoring: One tool (check-plex-builtin-backups.sh) for status
  5. Lower Maintenance: No custom cron schedules to manage

⚠️ Considerations

  1. Less Control: Cannot customize backup frequency (fixed at 3 days)
  2. Limited Validation: Cannot validate Plex backups with external tools
  3. Dependency: Reliant on Plex's backup implementation working correctly

🔍 Monitoring Built-in Backups

New Utility Script

./check-plex-builtin-backups.sh          # Basic status
./check-plex-builtin-backups.sh --detailed # Detailed information

Manual Commands

# Check latest backup
ls -lath "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"*.backup.* | head -1

# List all backups
find "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases" -name "*.backup.*" -exec ls -lah {} \;

# Check backup age
stat "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"*.backup.* | grep Modify

📁 File System Changes

Cron Configuration

  • File: /home/acedanger/shell/crontab/crontab-europa.txt
  • Status: Plex backup entries commented out/disabled
  • Applied: Yes (via manage-enhanced-crontab.sh install)

Custom Backup Files

  • Location: /mnt/share/media/backups/plex/plex-backup-*.tar.gz
  • Status: Legacy files preserved for historical reference
  • Count: 5 files found (from previous custom backup system)

Built-in Backup Files

  • Location: /var/lib/plexmediaserver/.../Databases/*.backup.*
  • Current: 1 active backup file found
  • Latest: com.plexapp.plugins.library.db.backup.20250621_063833 (149M)

🚨 Emergency Access

If Built-in Backups Fail

Custom backup scripts remain available for emergency use:

# Emergency backup creation
./backup-plex.sh --non-interactive --disable-auto-repair

# Emergency validation
./validate-plex-backups.sh --latest

Recovery Procedures

  • Nuclear recovery: nuclear-plex-recovery.sh unchanged
  • Service management: plex.sh unchanged
  • Health checks: plex-db-manager.sh unchanged

📋 Testing Results

Backup Status Check (June 21, 2025)

✅ Plex database directory found
✅ Found 1 built-in backup file(s)
📅 Latest backup: 2025-06-21 06:38:56 (149M)
✅ NAS backup directory accessible
📦 Found 5 legacy custom backup files
✅ Custom backup system: DISABLED
✅ Plex built-in backups: ACTIVE

Cron Verification

$ sudo crontab -l | grep -E "(plex|backup)"
# Returns: No active Plex backup cron jobs (successfully disabled)

📞 Rollback Plan

If Plex built-in backups prove unreliable, the custom system can be re-enabled:

  1. Uncomment cron entries in /home/acedanger/shell/crontab/crontab-europa.txt
  2. Re-apply crontab: ./manage-enhanced-crontab.sh install
  3. Update README.md to reflect re-enabled status
  4. Monitor both systems until transition is complete

🏁 Conclusion

The transition to Plex built-in backups simplifies the backup architecture while maintaining all emergency recovery capabilities. The system is now more aligned with Plex's native functionality and reduces the risk of script conflicts that contributed to previous database corruption issues.

Status: TRANSITION COMPLETE
Next Review: July 21, 2025 (1 month follow-up)