feat: Refactor backup script to initialize performance log file and ensure full backups every time

This commit is contained in:
Peter Wood
2025-05-26 09:13:32 -04:00
parent 1149e9656c
commit 1d01ca8c61
2 changed files with 50 additions and 93 deletions

View File

@@ -1,24 +1,34 @@
# Enhanced Plex Backup Script Documentation
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.
This document provides comprehensive documentation for the enhanced `backup-plex.sh` script. This advanced backup solution includes performance monitoring, parallel processing, intelligent notifications, and WAL file handling.
## Script Overview
The enhanced script performs the following advanced tasks:
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
2. **Full Backup Operations**: Performs complete backups of all Plex files every time
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
7. **Enhanced Service Management**: Safe Plex service management with progress indicators
8. **Comprehensive Logging**: Detailed logs with color-coded output and timestamps
9. **Safe Automated Cleanup**: Retention policies based on age and backup count
## Enhanced Features
### Full Backup Operation
The script performs complete backups every time it runs:
- **What it does**: Backs up all Plex files regardless of modification status
- **Benefits**:
- Guarantees every backup is a complete restoration point
- Eliminates risk of file loss from incomplete backup coverage
- Simplifies backup management and restoration
- **Usage**: `./backup-plex.sh` (no options needed)
### Performance Tracking
- **JSON Performance Logs**: All operations are timed and logged to `logs/plex-backup-performance.json`
@@ -208,17 +218,6 @@ The performance log (`logs/plex-backup-performance.json`) contains entries like:
]
```
### Backup Tracking Log
The backup tracking log (`logs/plex-backup.json`) tracks last backup times:
```json
{
"/var/lib/plexmediaserver/.../com.plexapp.plugins.library.db": 1732567523,
"/var/lib/plexmediaserver/.../Preferences.xml": 1732567523
}
```
## Usage Examples
### Basic Backup
@@ -406,15 +405,14 @@ The enhanced script implements a robust backup strategy with a streamlined tar.g
The new backup system eliminates intermediate dated directories and stores only compressed archives:
```bash
```text
/mnt/share/media/backups/plex/
├── plex-backup-20250125_143022.tar.gz # Latest backup
├── plex-backup-20250124_143011.tar.gz # Previous backup
├── plex-backup-20250123_143008.tar.gz # Older backup
└── logs/
├── backup_log_20250125_143022.md
── plex-backup-performance.json
└── plex-backup.json
── plex-backup-performance.json
```
### Archive Naming Convention
@@ -434,15 +432,14 @@ Backup files follow the naming convention `plex-backup-YYYYMMDD_HHMMSS.tar.gz` f
## Final Directory Structure
```
```text
/mnt/share/media/backups/plex/
├── plex-backup-20250125_143022.tar.gz # Latest backup
├── plex-backup-20250124_143011.tar.gz # Previous backup
├── plex-backup-20250123_143008.tar.gz # Older backup
└── logs/
├── backup_log_20250125_143022.md
── plex-backup-performance.json
└── plex-backup.json
── plex-backup-performance.json
```
Backup files follow the pattern: `plex-backup-YYYYMMDD_HHMMSS.tar.gz`