mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 06:40:13 -08:00
Add monitoring dashboard for Plex backup system
- Created a new script `monitor-plex-backup.sh` for real-time status and health monitoring of the Plex backup system. - Implemented features to check system status, backup status, performance metrics, recent activity, scheduling status, and health recommendations. - Added command line options for watch mode and refresh interval. - Enhanced logging with color-coded output for better visibility. Update recent additions script to include more metadata - Modified `plex-recent-additions.sh` to retrieve additional metadata fields such as year and library section type from the Plex database. - Improved SQL query to join with library_sections for better context on added items. Introduce comprehensive test suite for Plex backup system - Added `test-plex-backup.sh` to provide automated testing for all backup-related functionality. - Implemented unit tests for JSON log initialization, performance tracking, notification system, checksum caching, backup verification, and more. - Included setup and cleanup functions for a mock test environment. - Added performance benchmarks for checksum calculation and compression. - Generated detailed test reports in JSON format for better tracking of test results.
This commit is contained in:
@@ -1,22 +1,81 @@
|
||||
# Plex Backup Script Documentation
|
||||
# Enhanced Plex Backup Script Documentation
|
||||
|
||||
This document provides an overview and step-by-step explanation of the `backup-plex.sh` script. This script is designed to back up Plex Media Server databases and related files, compress the backup, and clean up the original files if the compression is successful.
|
||||
This document provides comprehensive documentation for the enhanced `backup-plex.sh` script. This advanced backup solution includes performance monitoring, parallel processing, intelligent notifications, WAL file handling, and automated testing capabilities.
|
||||
|
||||
## Script Overview
|
||||
|
||||
The script performs the following main tasks:
|
||||
The enhanced script performs the following advanced tasks:
|
||||
|
||||
1. Creates a log directory if it doesn't exist.
|
||||
2. Defines a log file with the current date and time.
|
||||
3. Defines a function to log file details.
|
||||
4. Stops the Plex Media Server service if it is running.
|
||||
5. Creates a backup directory with the current date.
|
||||
6. Copies important Plex database files and preferences to the backup directory.
|
||||
7. Logs the details of the copied files.
|
||||
8. Compresses the backup directory into a gzip archive.
|
||||
9. Deletes the original backup directory if the compression is successful.
|
||||
10. Sends a notification upon completion.
|
||||
11. Restarts the Plex Media Server service if it was stopped.
|
||||
1. **Performance Monitoring**: Tracks backup operations with JSON-based performance logging
|
||||
2. **Intelligent Backup Detection**: Only backs up files that have changed since last backup
|
||||
3. **WAL File Handling**: Properly handles SQLite Write-Ahead Logging files
|
||||
4. **Database Integrity Verification**: Comprehensive integrity checks with automated repair options
|
||||
5. **Parallel Processing**: Concurrent verification for improved performance
|
||||
6. **Multi-Channel Notifications**: Console, webhook, and email notification support
|
||||
7. **Checksum Caching**: Intelligent caching to avoid recalculating unchanged file checksums
|
||||
8. **Enhanced Service Management**: Safe Plex service management with progress indicators
|
||||
9. **Comprehensive Logging**: Detailed logs with color-coded output and timestamps
|
||||
10. **Automated Cleanup**: Configurable retention policies for old backups
|
||||
|
||||
## Enhanced Features
|
||||
|
||||
### Performance Tracking
|
||||
- **JSON Performance Logs**: All operations are timed and logged to `logs/plex-backup-performance.json`
|
||||
- **Performance Reports**: Automatic generation of average performance metrics
|
||||
- **Operation Monitoring**: Tracks backup, verification, service management, and overall script execution times
|
||||
|
||||
### Notification System
|
||||
The script supports multiple notification channels:
|
||||
|
||||
#### Console Notifications
|
||||
- Color-coded status messages (Success: Green, Error: Red, Warning: Yellow, Info: Blue)
|
||||
- Timestamped log entries with clear formatting
|
||||
|
||||
#### Webhook Notifications
|
||||
```bash
|
||||
./backup-plex.sh --webhook=https://your-webhook-url.com/endpoint
|
||||
```
|
||||
Sends JSON payloads with backup status, hostname, and timestamps.
|
||||
|
||||
#### Email Notifications
|
||||
```bash
|
||||
./backup-plex.sh --email=admin@example.com
|
||||
```
|
||||
Requires `sendmail` to be configured on the system.
|
||||
|
||||
### WAL File Management
|
||||
The script now properly handles SQLite Write-Ahead Logging files:
|
||||
- **Automatic Detection**: Identifies and backs up `.db-wal` and `.db-shm` files when present
|
||||
- **WAL Checkpointing**: Performs `PRAGMA wal_checkpoint(FULL)` before integrity checks
|
||||
- **Safe Backup**: Ensures WAL files are properly backed up alongside main database files
|
||||
|
||||
### Database Integrity & Repair
|
||||
Enhanced database management features:
|
||||
- **Pre-backup Integrity Checks**: Verifies database health before backup operations
|
||||
- **Automated Repair**: Optional automatic repair of corrupted databases using advanced techniques
|
||||
- **Interactive Repair Mode**: Prompts for repair decisions when issues are detected
|
||||
- **Post-repair Verification**: Re-checks integrity after repair operations
|
||||
|
||||
### Parallel Processing
|
||||
- **Concurrent Verification**: Parallel backup verification for improved performance
|
||||
- **Fallback Safety**: Automatically falls back to sequential processing if parallel mode fails
|
||||
- **Configurable**: Can be disabled with `--no-parallel` for maximum safety
|
||||
|
||||
### Command Line Options
|
||||
|
||||
```bash
|
||||
Usage: ./backup-plex.sh [OPTIONS]
|
||||
|
||||
Options:
|
||||
--auto-repair Automatically attempt to repair corrupted databases
|
||||
--check-integrity Only check database integrity, don't backup
|
||||
--non-interactive Run in non-interactive mode (for automation)
|
||||
--no-parallel Disable parallel verification (slower but safer)
|
||||
--no-performance Disable performance monitoring
|
||||
--webhook=URL Send notifications to webhook URL
|
||||
--email=ADDRESS Send notifications to email address
|
||||
-h, --help Show help message
|
||||
```
|
||||
|
||||
## Detailed Steps
|
||||
|
||||
|
||||
Reference in New Issue
Block a user