Add comprehensive Plex backup management scripts

- Introduced `restore-plex.sh` for restoring Plex backups with logging and validation.
- Created `test-plex-backup.sh` for automated testing of backup functionalities.
- Developed `validate-plex-backups.sh` for validating backup integrity and monitoring.
- Updated `update.sh` to reference the correct path for Plex service management.
This commit is contained in:
Peter Wood
2025-05-26 13:20:12 -04:00
parent a91fc79449
commit c9b69ea789
30 changed files with 702 additions and 25 deletions

10
.gitignore vendored
View File

@@ -20,9 +20,13 @@ _book
# Runtime generated files # Runtime generated files
logs/ logs/
crontab-backups/ # Backup files - ignore most backups but keep current state files
# But keep the current state backups for each system crontab/crontab-backups/*
!crontab-backups/*/current-crontab.backup !crontab/crontab-backups/europa/
!crontab/crontab-backups/io/
!crontab/crontab-backups/racknerd/
crontab/crontab-backups/*/archive/
!crontab/crontab-backups/*/current-crontab.backup
# Temporary files # Temporary files
*.tmp *.tmp

View File

@@ -241,15 +241,18 @@ For comprehensive disaster recovery, sync backups to remote locations:
## Documentation ## Documentation
### Directory-Specific Documentation
- **[Plex Scripts Documentation](./plex/README.md)**: Comprehensive documentation for all Plex backup, restoration, validation, and management scripts.
- **[Crontab Management Documentation](./crontab/README.md)**: Complete guide for crontab management, backup systems, and multi-system administration.
### Backup System Documentation ### Backup System Documentation
- [Enhanced Media Backup Documentation](./docs/enhanced-media-backup.md): Comprehensive guide for the enhanced `backup-media.sh` script with enterprise features. - [Enhanced Media Backup Documentation](./docs/enhanced-media-backup.md): Comprehensive guide for the enhanced `backup-media.sh` script with enterprise features.
- [Media Backup Enhancement Summary](./docs/backup-media-enhancement-summary.md): Summary of enhancements and feature comparisons. - [Media Backup Enhancement Summary](./docs/backup-media-enhancement-summary.md): Summary of enhancements and feature comparisons.
- [Plex Backup Script Documentation](./docs/plex-backup.md): Detailed documentation for the `backup-plex.sh` script.
### Script Documentation ### Script Documentation
- [Plex Management Script Documentation](./docs/plex-management.md): Detailed documentation for the `plex.sh` script.
- [Folder Metrics Script Documentation](./docs/folder-metrics.md): Detailed documentation for the `folder-metrics.sh` script. - [Folder Metrics Script Documentation](./docs/folder-metrics.md): Detailed documentation for the `folder-metrics.sh` script.
- [Testing Framework Documentation](./docs/testing.md): Detailed documentation for the Docker-based testing system. - [Testing Framework Documentation](./docs/testing.md): Detailed documentation for the Docker-based testing system.

View File

@@ -207,7 +207,7 @@ check_backup_health() {
"/home/acedanger/shell/backup-plex.sh" "/home/acedanger/shell/backup-plex.sh"
"/home/acedanger/shell/move-backups.sh" "/home/acedanger/shell/move-backups.sh"
"/home/acedanger/shell/validate-plex-backups.sh" "/home/acedanger/shell/validate-plex-backups.sh"
"/home/acedanger/shell/crontab-backup-system.sh" "/home/acedanger/shell/crontab/crontab-backup-system.sh"
) )
for script in "${backup_scripts[@]}"; do for script in "${backup_scripts[@]}"; do

376
crontab/README.md Normal file
View File

@@ -0,0 +1,376 @@
# Crontab Management and Backup Scripts
This directory contains all scripts and documentation related to crontab management, backup, monitoring, and multi-system administration.
## Scripts Overview
### Core Management Scripts
#### `crontab-backup-system.sh`
**Comprehensive crontab backup and recovery system**
- **Multi-system support** with hostname-based organization
- **Automated backup creation** with timestamped archives
- **Syntax validation** and integrity checking
- **Cross-system comparison** and restoration
- **Legacy migration** from old backup structures
- **Automated cleanup** with configurable retention
**Usage:**
```bash
./crontab-backup-system.sh backup manual # Create manual backup
./crontab-backup-system.sh list # List backups for current system
./crontab-backup-system.sh list io # List backups for specific system
./crontab-backup-system.sh status all # View all systems status
./crontab-backup-system.sh restore backup-file # Restore from backup
./crontab-backup-system.sh compare current old.backup # Compare configurations
```
#### `manage-enhanced-crontab.sh`
**Enhanced crontab installation and management**
- **System-specific crontab installation** with validation
- **Pre/post-install backups** for safety
- **Script verification** and executable checking
- **Logrotate setup** for log management
- **Integration** with backup and monitoring systems
**Usage:**
```bash
./manage-enhanced-crontab.sh install # Install enhanced crontab system
./manage-enhanced-crontab.sh verify # Verify all scripts exist
./manage-enhanced-crontab.sh status # Check system health
./manage-enhanced-crontab.sh backup # Backup current crontab only
```
#### `fix-crontab-merging.sh`
**Crontab merge conflict resolution**
- **Conflict detection** and resolution
- **Safe merging** of crontab entries
- **Backup preservation** during merge operations
- **Interactive conflict resolution**
### System-Specific Configuration Files
#### `crontab-europa.txt`
Production crontab configuration for the Europa system:
```bash
# Move docker backups (01:00)
0 1 * * * /home/acedanger/shell/move-backups.sh 2>&1 | logger -t backup-move -p user.info
# Plex backup (04:15)
15 4 * * * /home/acedanger/shell/plex/backup-plex.sh 2>&1 | logger -t plex-backup -p user.info
# Validate plex backups (07:00)
0 7 * * * /home/acedanger/shell/validate-plex-backups.sh --fix 2>&1 | logger -t plex-validation -p user.info
```
#### `crontab-io.txt`
Crontab configuration for the IO system with media-focused operations.
#### `crontab-racknerd.txt`
Crontab configuration for the RackNerd system with backup synchronization.
#### `crontab.txt.bak`
Backup of legacy crontab configuration for reference.
## Directory Structure
```
crontab-backups/
├── europa/ # Current system (example)
│ ├── current-crontab.backup
│ └── archive/
│ ├── europa-crontab-initial-20250526_101354.backup
│ └── europa-crontab-pre-install-20250526_100622.backup
├── io/ # Remote system backups
│ ├── current-crontab.backup
│ └── archive/
│ └── io-crontab-sample-20250526_101558.backup
└── racknerd/ # Another remote system
├── current-crontab.backup
└── archive/
└── racknerd-crontab-sample-20250526_101558.backup
```
## Enhanced Features
### Multi-System Support
- **Hostname-based organization**: Each system gets its own directory
- **Cross-system operations**: View, compare, and restore backups from any system
- **Centralized management**: Manage all systems from a single location
- **Legacy migration**: Automatic migration from old backup structures
### System Logging Integration
All crontab operations integrate with system logging using specific tags:
- `crontab-backup`: Crontab backup operations
- `plex-backup`: Plex database backup operations
- `backup-move`: Docker backup file transfers
- `plex-validation`: Backup integrity checks
- `backup-cleanup`: Cleanup operations
### Automated Operations
- **Daily automated backups** at midnight
- **Syntax validation** before installing changes
- **Automatic cleanup** of old backups (30-day retention)
- **Health monitoring** and status reporting
- **Error handling** with comprehensive logging
## Configuration
### Environment Variables
Key configuration parameters in the backup system:
```bash
# Retention settings
BACKUP_RETENTION_DAYS=30 # Keep backups for 30 days
AUTO_CLEANUP=true # Enable automatic cleanup
# Directory settings
BACKUP_ROOT="./crontab-backups"
LOG_DIR="./logs"
# System identification
HOSTNAME=$(hostname) # Automatic system identification
```
### File Naming Convention
Backup files follow the pattern: `{hostname}-crontab-{type}-{timestamp}.backup`
Examples:
- `europa-crontab-manual-20250526_101354.backup`
- `io-crontab-pre-upgrade-20250526_120000.backup`
- `racknerd-crontab-auto-20250526_000001.backup`
## Automation and Scheduling
### Automated Backup Setup
```bash
# Setup automated daily backups
./crontab-backup-system.sh setup-auto
```
This adds a daily backup entry to the system crontab:
```bash
0 0 * * * /path/to/crontab-backup-system.sh backup auto --auto-cleanup 2>&1 | logger -t crontab-backup -p user.info
```
### Cross-System Synchronization
For distributed environments, set up backup synchronization:
```bash
# Sync backups from remote systems
rsync -avz europa:/home/acedanger/shell/crontab-backups/europa/ ./crontab-backups/europa/
rsync -avz io:/home/acedanger/shell/crontab-backups/io/ ./crontab-backups/io/
```
## Monitoring and Health Checks
### System Status Monitoring
```bash
# View status for current system
./crontab-backup-system.sh status
# View status for specific system
./crontab-backup-system.sh status io
# View status for all systems
./crontab-backup-system.sh status all
```
### Log Monitoring
```bash
# View all backup-related logs
journalctl -t crontab-backup -t plex-backup -t backup-move -f
# View logs for specific operation
journalctl -t plex-backup --since "1 hour ago"
# Check for errors in the last 24 hours
journalctl --since '24 hours ago' --priority=err -t plex-backup
```
### Health Check Commands
```bash
# Check backup system health
./crontab-backup-system.sh status all
# Verify all scripts exist and are executable
./manage-enhanced-crontab.sh verify
# View recent backup activity
grep "SUCCESS" logs/crontab-management.log | tail -20
```
## Troubleshooting
### Common Issues
#### Permission Errors
Ensure proper file permissions on backup directories:
```bash
chmod 755 crontab-backups/
chmod 644 crontab-backups/*/*.backup
```
#### Missing Backups
Check automated backup cron entries:
```bash
sudo crontab -l | grep crontab-backup
```
#### Syntax Errors
Validate crontab syntax before applying:
```bash
./crontab-backup-system.sh validate new-crontab.txt
```
### Debug Mode
Enable verbose logging for troubleshooting:
```bash
./crontab-backup-system.sh status all 2>&1 | tee debug.log
```
### Recovery Procedures
#### Emergency Crontab Restoration
```bash
# List available backups
./crontab-backup-system.sh list
# Compare current with backup
./crontab-backup-system.sh compare current backup-file.backup
# Restore from specific backup
./crontab-backup-system.sh restore backup-file.backup
```
#### Disaster Recovery
```bash
# Restore from specific system backup during emergency
./crontab-backup-system.sh restore io-crontab-pre-incident-20250526_101354.backup
# Compare pre-incident and post-incident configurations
./crontab-backup-system.sh compare io-crontab-pre-incident-20250526_101354.backup current
```
## Advanced Use Cases
### Configuration Management
```bash
# Standardize crontab across multiple systems
./crontab-backup-system.sh compare europa-crontab-standard-20250526_101354.backup io-crontab-current-20250526_120000.backup
# Validate configurations before deployment
./crontab-backup-system.sh validate new-crontab-config.txt
```
### Compliance and Auditing
- **Change tracking**: Complete history of all crontab changes across systems
- **Audit trails**: System logs provide comprehensive audit information
- **Compliance reporting**: Generate reports showing backup frequency and success rates
### Cross-System Comparison
```bash
# Compare current crontab with backup from another system
./crontab-backup-system.sh compare current io-crontab-sample-20250526_101558.backup
# Compare two backups from different systems
./crontab-backup-system.sh compare europa-crontab-manual-20250526_101354.backup racknerd-crontab-sample-20250526_101558.backup
```
## Security Considerations
### File Permissions
- **Backup directories**: Restrict access to authorized users only
- **Log files**: Ensure proper log rotation and access controls
- **Remote access**: Use secure methods (SSH, rsync) for cross-system operations
### Backup Integrity
- **Validation**: Regular syntax validation of backup files
- **Checksums**: Consider adding checksum verification for critical backups
- **Retention**: Implement appropriate backup retention policies
### Access Control
- Scripts require appropriate sudo permissions for crontab operations
- Backup locations should have restricted access
- Log files contain operational data only (no sensitive information)
## Documentation
### Detailed Documentation
- **[enhanced-crontab-system.md](./enhanced-crontab-system.md)**: Comprehensive crontab system documentation
- **[multi-system-crontab-management.md](./multi-system-crontab-management.md)**: Multi-system management guide
- **[crontab-merging-issue-resolution.md](./crontab-merging-issue-resolution.md)**: Conflict resolution procedures
### Integration Notes
- All scripts follow repository coding standards
- Consistent logging and error handling
- Color-coded output for readability
- Comprehensive help systems
- System logging integration
## Best Practices
1. **Regular Testing**: Periodically test backup restoration procedures
2. **Documentation**: Keep records of system configurations and backup schedules
3. **Automation**: Use automated cleanup to prevent disk space issues
4. **Monitoring**: Implement comprehensive monitoring and alerting
5. **Security**: Regularly review and update access controls
## Migration Notes
When migrating from legacy crontab systems:
1. **Backup current configuration**: Create manual backup before changes
2. **Test new system**: Use validation and dry-run features
3. **Gradual migration**: Migrate one system at a time
4. **Monitor performance**: Check logs for any issues post-migration
The system automatically detects and migrates legacy backup structures while preserving all existing data.
---
*This crontab management system provides robust, scalable backup management for distributed environments while maintaining simplicity and reliability.*

View File

@@ -1,5 +1,5 @@
0 1 * * * /home/acedanger/shell/move-backups.sh 2>&1 | logger -t backup-move -p user.info 0 1 * * * /home/acedanger/shell/move-backups.sh 2>&1 | logger -t backup-move -p user.info
15 4 * * * { echo "Starting Plex backup"; /home/acedanger/shell/backup-plex.sh --non-interactive --auto-repair; echo "Plex backup completed with exit code: $?"; } 2>&1 | logger -t plex-backup -p user.info 15 4 * * * { echo "Starting Plex backup"; /home/acedanger/shell/plex/backup-plex.sh --non-interactive --auto-repair; echo "Plex backup completed with exit code: $?"; } 2>&1 | logger -t plex-backup -p user.info
0 7 * * * { echo "Starting Plex backup validation"; /home/acedanger/shell/validate-plex-backups.sh --fix; echo "Validation completed with exit code: $?"; } 2>&1 | logger -t plex-validation -p user.info 0 7 * * * { echo "Starting Plex backup validation"; /home/acedanger/shell/validate-plex-backups.sh --fix; echo "Validation completed with exit code: $?"; } 2>&1 | logger -t plex-validation -p user.info
0 5 * * 1 { echo "Starting Immich database backup move"; if mv /mnt/share/media/immich/uploads/backups/immich-db-backup* /mnt/share/media/backups/immich 2>/dev/null; then echo "Immich backup move completed successfully"; else echo "No Immich backup files found or move failed"; fi; } 2>&1 | logger -t immich-backup -p user.info 0 5 * * 1 { echo "Starting Immich database backup move"; if mv /mnt/share/media/immich/uploads/backups/immich-db-backup* /mnt/share/media/backups/immich 2>/dev/null; then echo "Immich backup move completed successfully"; else echo "No Immich backup files found or move failed"; fi; } 2>&1 | logger -t immich-backup -p user.info
0 8 * * 0 { echo "Starting weekly Plex backup report generation"; /home/acedanger/shell/validate-plex-backups.sh --report; echo "Weekly report generation completed with exit code: $?"; } 2>&1 | logger -t plex-report -p user.info 0 8 * * 0 { echo "Starting weekly Plex backup report generation"; /home/acedanger/shell/validate-plex-backups.sh --report; echo "Weekly report generation completed with exit code: $?"; } 2>&1 | logger -t plex-report -p user.info

View File

@@ -1,5 +1,5 @@
0 2 * * * { echo "Starting Docker backup"; /home/acedanger/shell/backup-docker.sh; echo "Docker backup completed with exit code: $?"; } 2>&1 | logger -t docker-backup -p user.info 0 2 * * * { echo "Starting Docker backup"; /home/acedanger/shell/backup-docker.sh; echo "Docker backup completed with exit code: $?"; } 2>&1 | logger -t docker-backup -p user.info
0 4 * * * /home/acedanger/shell/crontab-backup-system.sh backup auto --auto-cleanup 2>&1 | logger -t crontab-backup -p user.info 0 4 * * * /home/acedanger/shell/crontab/crontab-backup-system.sh backup auto --auto-cleanup 2>&1 | logger -t crontab-backup -p user.info
# Daily backups at 2 AM # Daily backups at 2 AM
0 2 * * * /home/acedanger/shell/backup-media.sh >/dev/null 2>&1 0 2 * * * /home/acedanger/shell/backup-media.sh >/dev/null 2>&1
# #

View File

@@ -9,7 +9,7 @@
# Daily Plex backup at 0415 with enhanced logging # Daily Plex backup at 0415 with enhanced logging
# Includes execution status and performance metrics # Includes execution status and performance metrics
15 4 * * * { echo "Starting Plex backup"; /home/acedanger/shell/backup-plex.sh --non-interactive --auto-repair; echo "Plex backup completed with exit code: $?"; } 2>&1 | logger -t plex-backup -p user.info 15 4 * * * { echo "Starting Plex backup"; /home/acedanger/shell/plex/backup-plex.sh --non-interactive --auto-repair; echo "Plex backup completed with exit code: $?"; } 2>&1 | logger -t plex-backup -p user.info
# Daily validation at 0700 with detailed logging # Daily validation at 0700 with detailed logging
# Logs validation results and any auto-fixes performed # Logs validation results and any auto-fixes performed

View File

@@ -184,7 +184,7 @@ verify_scripts_exist() {
local scripts=( local scripts=(
"/home/acedanger/shell/move-backups.sh" "/home/acedanger/shell/move-backups.sh"
"/home/acedanger/shell/backup-plex.sh" "/home/acedanger/shell/plex/backup-plex.sh"
"/home/acedanger/shell/validate-plex-backups.sh" "/home/acedanger/shell/validate-plex-backups.sh"
) )

View File

@@ -107,7 +107,7 @@ All backup operations now integrate with system logging:
```bash ```bash
# Plex backup with comprehensive logging # Plex backup with comprehensive logging
15 4 * * * /home/acedanger/shell/backup-plex.sh 2>&1 | logger -t plex-backup -p user.info 15 4 * * * /home/acedanger/shell/plex/backup-plex.sh 2>&1 | logger -t plex-backup -p user.info
# Backup move operation with error handling # Backup move operation with error handling
0 1 * * * /home/acedanger/shell/move-backups.sh 2>&1 | logger -t backup-move -p user.info 0 1 * * * /home/acedanger/shell/move-backups.sh 2>&1 | logger -t backup-move -p user.info

View File

@@ -7,12 +7,12 @@ alias gcm="git commit -m"
alias ll="ls -laFh --group-directories-first --color=auto" alias ll="ls -laFh --group-directories-first --color=auto"
alias findzombie="ps -A -ostat,pid,ppid | grep -e '[zZ]'" alias findzombie="ps -A -ostat,pid,ppid | grep -e '[zZ]'"
# 🎬 Plex Media Server Management - Sexy Edition # 🎬 Plex Media Server Management - Sexy Edition
alias plex="/home/acedanger/shell/plex.sh" alias plex="/home/acedanger/shell/plex/plex.sh"
alias px="/home/acedanger/shell/plex.sh" # Quick shortcut alias px="/home/acedanger/shell/plex/plex.sh" # Quick shortcut
alias plex-start="/home/acedanger/shell/plex.sh start" # Start Plex alias plex-start="/home/acedanger/shell/plex/plex.sh start" # Start Plex
alias plex-stop="/home/acedanger/shell/plex.sh stop" # Stop Plex alias plex-stop="/home/acedanger/shell/plex/plex.sh stop" # Stop Plex
alias plex-restart="/home/acedanger/shell/plex.sh restart" # Restart Plex alias plex-restart="/home/acedanger/shell/plex/plex.sh restart" # Restart Plex
alias plex-status="/home/acedanger/shell/plex.sh status" # Status check alias plex-status="/home/acedanger/shell/plex/plex.sh status" # Status check
alias plex-web="xdg-open http://localhost:32400/web" # Open web UI in browser alias plex-web="xdg-open http://localhost:32400/web" # Open web UI in browser
alias update="/home/acedanger/shell/update.sh" alias update="/home/acedanger/shell/update.sh"
alias dcdn="docker compose down" alias dcdn="docker compose down"

View File

@@ -7,10 +7,10 @@ alias gcm="git commit -m"
alias ll="ls -laFh --group-directories-first --color=auto" alias ll="ls -laFh --group-directories-first --color=auto"
alias findzombie="ps -A -ostat,pid,ppid | grep -e '[zZ]'" alias findzombie="ps -A -ostat,pid,ppid | grep -e '[zZ]'"
# 🎬 Plex Media Server Management - Sexy Edition # 🎬 Plex Media Server Management - Sexy Edition
alias plex="/home/acedanger/shell/plex.sh" alias plex="/home/acedanger/shell/plex/plex.sh"
alias px="/home/acedanger/shell/plex.sh" # Quick shortcut alias px="/home/acedanger/shell/plex/plex.sh" # Quick shortcut
alias plex-start="/home/acedanger/shell/plex.sh start" # Start Plex alias plex-start="/home/acedanger/shell/plex/plex.sh start" # Start Plex
alias plex-stop="/home/acedanger/shell/plex.sh stop" # Stop Plex alias plex-stop="/home/acedanger/shell/plex/plex.sh stop" # Stop Plex
alias plex-restart="/home/acedanger/shell/plex.sh restart" # Restart Plex alias plex-restart="/home/acedanger/shell/plex.sh restart" # Restart Plex
alias plex-status="/home/acedanger/shell/plex.sh status" # Status check alias plex-status="/home/acedanger/shell/plex.sh status" # Status check
alias plex-web="xdg-open http://localhost:32400/web" # Open web UI in browser alias plex-web="xdg-open http://localhost:32400/web" # Open web UI in browser

294
plex/README.md Normal file
View File

@@ -0,0 +1,294 @@
# Plex Backup and Management Scripts
This directory contains all scripts and documentation related to Plex Media Server backup, restoration, validation, and management.
## Scripts Overview
### Core Backup Scripts
#### `backup-plex.sh`
**Enhanced Plex backup script with advanced features**
- **Full backup operations** with integrity verification
- **Performance monitoring** with JSON-based logging
- **WAL file handling** for SQLite databases
- **Database integrity checks** with automated repair options
- **Parallel processing** for improved performance
- **Multi-channel notifications** (console, webhook, email)
- **Comprehensive logging** with color-coded output
**Usage:**
```bash
./backup-plex.sh # Standard backup
./backup-plex.sh --check-integrity # Integrity check only
./backup-plex.sh --non-interactive # Automated mode
./backup-plex.sh --auto-repair # Auto-repair database issues
```
#### `restore-plex.sh`
**Safe restoration script with validation**
- **Backup validation** before restoration
- **Dry-run mode** for testing
- **Current data backup** before restoration
- **Interactive backup selection**
**Usage:**
```bash
./restore-plex.sh # List available backups
./restore-plex.sh plex-backup-20250125_143022.tar.gz # Restore specific backup
./restore-plex.sh --dry-run backup-file.tar.gz # Test restoration
```
#### `validate-plex-backups.sh`
**Backup validation and health monitoring**
- **Archive integrity checking**
- **Backup freshness validation**
- **Comprehensive reporting**
- **Automated fix suggestions**
**Usage:**
```bash
./validate-plex-backups.sh # Validate all backups
./validate-plex-backups.sh --report # Generate detailed report
./validate-plex-backups.sh --fix # Auto-fix issues where possible
```
### Testing and Monitoring
#### `test-plex-backup.sh`
**Comprehensive testing framework**
- **Unit tests** for core functionality
- **Integration tests** for full system testing
- **Performance benchmarks**
**Usage:**
```bash
./test-plex-backup.sh all # Run all tests
./test-plex-backup.sh unit # Unit tests only
./test-plex-backup.sh performance # Performance benchmarks
```
#### `integration-test-plex.sh`
**Integration testing for Plex backup system**
- **End-to-end testing**
- **System integration validation**
- **Environment compatibility checks**
#### `monitor-plex-backup.sh`
**Real-time backup monitoring**
- **Live backup status**
- **Performance metrics**
- **Error detection and alerting**
### Utility Scripts
#### `plex.sh`
**Plex Media Server service management**
- **Service start/stop/restart**
- **Status monitoring**
- **Safe service management**
#### `plex-recent-additions.sh`
**Recent media additions reporting**
- **New content detection**
- **Addition summaries**
- **Media library analytics**
## Configuration
### Environment Variables
Key configuration parameters in `backup-plex.sh`:
```bash
# Retention settings
MAX_BACKUP_AGE_DAYS=30 # Remove backups older than 30 days
MAX_BACKUPS_TO_KEEP=10 # Keep maximum of 10 backup archives
# Directory settings
BACKUP_ROOT="/mnt/share/media/backups/plex"
LOG_ROOT="/mnt/share/media/backups/logs"
# Feature toggles
PARALLEL_VERIFICATION=true # Enable parallel verification
PERFORMANCE_MONITORING=true # Track performance metrics
AUTO_REPAIR=false # Automatic database repair
```
### Backup Strategy
The enhanced backup system implements:
- **Archive-only structure**: Direct `.tar.gz` storage
- **Timestamp naming**: `plex-backup-YYYYMMDD_HHMMSS.tar.gz`
- **Automatic cleanup**: Age and count-based retention
- **Integrity validation**: Comprehensive archive verification
## Directory Structure
```
/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
```
## Enhanced Features
### Performance Monitoring
- **JSON performance logs**: All operations timed and logged
- **Performance reports**: Automatic generation of metrics
- **Operation tracking**: Backup, verification, service management times
### Database Management
- **Integrity checking**: Comprehensive SQLite database validation
- **Automated repair**: Optional auto-repair of corruption
- **WAL file handling**: Proper SQLite Write-Ahead Logging management
### Notification System
- **Console output**: Color-coded status messages
- **Webhook notifications**: Custom webhook URL support
- **Email notifications**: SMTP-based email alerts
- **Default webhook**: Automatic notifications to configured endpoint
### Safety Features
- **Pre-flight checks**: Disk space and system validation
- **Service management**: Safe Plex service start/stop
- **Backup verification**: Checksum and integrity validation
- **Error handling**: Comprehensive error detection and recovery
## Automation and Scheduling
### Cron Integration
Example crontab entries for automated operations:
```bash
# Daily Plex backup at 04:15
15 4 * * * /home/acedanger/shell/plex/backup-plex.sh --non-interactive --auto-repair 2>&1 | logger -t plex-backup -p user.info
# Daily validation at 07:00
0 7 * * * /home/acedanger/shell/plex/validate-plex-backups.sh --fix 2>&1 | logger -t plex-validation -p user.info
```
### Log Monitoring
Monitor backup operations with:
```bash
# Real-time monitoring
sudo journalctl -f -t plex-backup -t plex-validation
# Historical analysis
sudo journalctl --since '24 hours ago' -t plex-backup
# Performance analysis
jq '.[] | select(.operation == "backup") | .duration_seconds' logs/plex-backup-performance.json
```
## Troubleshooting
### Common Issues
1. **Database corruption**: Use `--auto-repair` flag or manual repair
2. **Insufficient disk space**: Check space requirements (2x backup size)
3. **Service management**: Ensure Plex service accessibility
4. **Archive validation**: Use validation script for integrity checks
### Debug Mode
Enable verbose logging:
```bash
# Add environment variable for debug output
PLEX_DEBUG=true ./backup-plex.sh
```
### Log Analysis
```bash
# Check backup success rate
grep "SUCCESS" logs/plex-backup-*.log | wc -l
# Analyze errors
grep "ERROR" logs/plex-backup-*.log | tail -10
# Performance trends
jq '[.[] | select(.operation == "backup") | .duration_seconds] | add/length' logs/plex-backup-performance.json
```
## Security Considerations
### File Permissions
- Backup files created with appropriate permissions
- Sensitive files maintain original ownership
- Temporary files properly cleaned up
### Access Control
- Script requires appropriate sudo permissions
- Backup locations should have restricted access
- Log files contain operational data only
### Network Security
- Webhook notifications use HTTPS when possible
- No sensitive data included in notifications
- Email notifications respect system configuration
## Documentation
### Detailed Documentation
- **[plex-backup.md](./plex-backup.md)**: Comprehensive backup script documentation
- **[plex-management.md](./plex-management.md)**: Plex management and administration guide
### Integration Notes
- All scripts follow repository coding standards
- Consistent logging and error handling
- Color-coded output for readability
- Comprehensive help systems
## Migration Notes
When migrating from legacy backup scripts:
1. **Backup current configuration**: Save any custom modifications
2. **Test new scripts**: Run with `--check-integrity` first
3. **Update automation**: Modify cron jobs to use new options
4. **Monitor performance**: Check performance logs for optimization
The enhanced scripts maintain backward compatibility while adding significant new capabilities.
---
*For additional support and advanced configuration options, refer to the detailed documentation files in this directory.*

View File

@@ -125,7 +125,7 @@ This line defines the log file path, including the current date and time in the
```bash ```bash
if systemctl is-active --quiet plexmediaserver.service; then if systemctl is-active --quiet plexmediaserver.service; then
/home/acedanger/shell/plex.sh stop || { echo "Failed to stop plexmediaserver.service"; exit 1; } /home/acedanger/shell/plex/plex.sh stop || { echo "Failed to stop plexmediaserver.service"; exit 1; }
fi fi
``` ```
@@ -184,7 +184,7 @@ This command sends a notification upon completion of the backup process, indicat
```bash ```bash
if systemctl is-enabled --quiet plexmediaserver.service; then if systemctl is-enabled --quiet plexmediaserver.service; then
/home/acedanger/shell/plex.sh start || { echo "Failed to start plexmediaserver.service"; exit 1; } /home/acedanger/shell/plex/plex.sh start || { echo "Failed to start plexmediaserver.service"; exit 1; }
fi fi
``` ```

View File

@@ -31,7 +31,7 @@ echo -e "${GREEN}Using package manager: $PKG_MANAGER${NC}"
# checks if the plexmediaserver.service is defined on this machine. stop it if it is. # checks if the plexmediaserver.service is defined on this machine. stop it if it is.
if systemctl is-active --quiet plexmediaserver.service 2>/dev/null; then if systemctl is-active --quiet plexmediaserver.service 2>/dev/null; then
sudo /home/acedanger/shell/plex.sh stop sudo /home/acedanger/shell/plex/plex.sh stop
fi fi
omz_upgrade_script=~/.oh-my-zsh/tools/upgrade.sh omz_upgrade_script=~/.oh-my-zsh/tools/upgrade.sh
@@ -63,5 +63,5 @@ esac
# checks if the plexmediaserver.service is defined on this machine. start it if it is. # checks if the plexmediaserver.service is defined on this machine. start it if it is.
if systemctl is-enabled --quiet plexmediaserver.service 2>/dev/null; then if systemctl is-enabled --quiet plexmediaserver.service 2>/dev/null; then
sudo /home/acedanger/shell/plex.sh start sudo /home/acedanger/shell/plex/plex.sh start
fi fi