mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 05:40:11 -08:00
docs: Remove outdated Docker-based testing framework documentation
This commit is contained in:
@@ -73,7 +73,7 @@ Enhanced database management features:
|
||||
- **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
|
||||
## Command Line Options
|
||||
|
||||
```bash
|
||||
Usage: ./backup-plex.sh [OPTIONS]
|
||||
@@ -89,7 +89,9 @@ Options:
|
||||
-h, --help Show help message
|
||||
```
|
||||
|
||||
## Detailed Steps
|
||||
## Detailed Backup Process Steps
|
||||
|
||||
The backup script follows these detailed steps to ensure data integrity and reliability:
|
||||
|
||||
### 1. Create Log Directory
|
||||
|
||||
@@ -107,22 +109,7 @@ LOG_FILE="/mnt/share/media/backups/logs/backup_log_$(date +%Y%m%d_%H%M%S).md"
|
||||
|
||||
This line defines the log file path, including the current date and time in the filename to ensure uniqueness.
|
||||
|
||||
### 3. Define Log File Details Function
|
||||
|
||||
```bash
|
||||
log_file_details() {
|
||||
local src=$1
|
||||
local dest=$2
|
||||
local size=$(du -sh "$dest" | cut -f1)
|
||||
echo "Source: $src" >> "$LOG_FILE"
|
||||
echo "Destination: $dest" >> "$LOG_FILE"
|
||||
echo "Size: $size" >> "$LOG_FILE"
|
||||
}
|
||||
```
|
||||
|
||||
This function logs the details of the copied files, including the source, destination, and size.
|
||||
|
||||
### 4. Stop Plex Media Server Service
|
||||
### 3. Stop Plex Media Server Service
|
||||
|
||||
```bash
|
||||
if systemctl is-active --quiet plexmediaserver.service; then
|
||||
@@ -132,25 +119,20 @@ fi
|
||||
|
||||
This block checks if the Plex Media Server service is running. If it is, the script stops the service using a custom script (`plex.sh`).
|
||||
|
||||
### 5. Backup Plex Database Files and Preferences
|
||||
### 4. Backup Plex Database Files and Preferences
|
||||
|
||||
The enhanced backup system now creates compressed archives directly, eliminating intermediate directories:
|
||||
The enhanced backup system creates compressed archives directly, eliminating intermediate directories:
|
||||
|
||||
```bash
|
||||
# Files are copied to temporary staging area for verification
|
||||
cp "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$BACKUP_PATH/"
|
||||
log_file_details "com.plexapp.plugins.library.db" "$BACKUP_PATH/"
|
||||
|
||||
cp "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.blobs.db" "$BACKUP_PATH/"
|
||||
log_file_details "com.plexapp.plugins.library.blobs.db" "$BACKUP_PATH/"
|
||||
|
||||
cp "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Preferences.xml" "$BACKUP_PATH/"
|
||||
log_file_details "Preferences.xml" "$BACKUP_PATH/"
|
||||
```
|
||||
|
||||
These commands copy the Plex database files and preferences directly to the backup root directory. Each file copy operation includes integrity verification and checksum validation.
|
||||
|
||||
### 6. Create Compressed Archive
|
||||
### 5. Create Compressed Archive
|
||||
|
||||
```bash
|
||||
# Create archive directly with timestamp naming convention
|
||||
@@ -158,15 +140,14 @@ final_archive="${BACKUP_ROOT}/plex-backup-$(date '+%Y%m%d_%H%M%S').tar.gz"
|
||||
tar -czf "$final_archive" -C "$temp_staging_dir" .
|
||||
```
|
||||
|
||||
The system now creates compressed archives directly using a timestamp-based naming convention (`plex-backup-YYYYMMDD_HHMMSS.tar.gz`), eliminating the need for intermediate dated directories.
|
||||
The system creates compressed archives directly using a timestamp-based naming convention (`plex-backup-YYYYMMDD_HHMMSS.tar.gz`), eliminating the need for intermediate dated directories.
|
||||
|
||||
### 7. Archive Validation and Cleanup
|
||||
### 6. Archive Validation and Cleanup
|
||||
|
||||
```bash
|
||||
# Validate archive integrity
|
||||
if tar -tzf "$final_archive" >/dev/null 2>&1; then
|
||||
log_success "Archive created and validated: $(basename "$final_archive")"
|
||||
# Clean up temporary staging files
|
||||
rm -rf "$temp_staging_dir"
|
||||
else
|
||||
log_error "Archive validation failed"
|
||||
@@ -176,7 +157,7 @@ fi
|
||||
|
||||
The system validates the created archive and removes temporary staging files, ensuring only valid compressed backups are retained in the backup root directory.
|
||||
|
||||
### 8. Send Notification
|
||||
### 7. Send Notification
|
||||
|
||||
```bash
|
||||
curl \
|
||||
@@ -185,9 +166,9 @@ curl \
|
||||
https://notify.peterwood.rocks/lab || { echo "Failed to send notification"; exit 1; }
|
||||
```
|
||||
|
||||
This command sends a notification upon completion of the backup process, indicating the compressed archive has been created. If the notification fails, the script exits with an error message.
|
||||
This command sends a notification upon completion of the backup process, indicating the compressed archive has been created.
|
||||
|
||||
### 9. Restart Plex Media Server Service
|
||||
### 8. Restart Plex Media Server Service
|
||||
|
||||
```bash
|
||||
if systemctl is-enabled --quiet plexmediaserver.service; then
|
||||
@@ -197,7 +178,7 @@ fi
|
||||
|
||||
This block checks if the Plex Media Server service is enabled. If it is, the script restarts the service using a custom script (`plex.sh`).
|
||||
|
||||
### 10. Legacy Cleanup
|
||||
### 9. Legacy Cleanup
|
||||
|
||||
```bash
|
||||
# Clean up any remaining dated directories from old backup structure
|
||||
@@ -206,6 +187,240 @@ find "${BACKUP_ROOT}" -maxdepth 1 -type d -name "????????" -exec rm -rf {} \; 2>
|
||||
|
||||
The enhanced system includes cleanup of legacy dated directories from previous backup structure versions, ensuring a clean tar.gz-only backup directory.
|
||||
|
||||
## Configuration Files
|
||||
|
||||
### Performance Log Format
|
||||
|
||||
The performance log (`logs/plex-backup-performance.json`) contains entries like:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"operation": "backup",
|
||||
"duration_seconds": 45.3,
|
||||
"timestamp": "2025-05-25T19:45:23-05:00"
|
||||
},
|
||||
{
|
||||
"operation": "verification",
|
||||
"duration_seconds": 12.8,
|
||||
"timestamp": "2025-05-25T19:46:08-05:00"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### 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
|
||||
|
||||
```bash
|
||||
./backup-plex.sh
|
||||
```
|
||||
|
||||
Performs a standard backup with all enhanced features enabled.
|
||||
|
||||
### Integrity Check Only
|
||||
|
||||
```bash
|
||||
./backup-plex.sh --check-integrity
|
||||
```
|
||||
|
||||
Only checks database integrity without performing backup.
|
||||
|
||||
### Automated Backup with Notifications
|
||||
|
||||
```bash
|
||||
./backup-plex.sh --non-interactive --auto-repair --webhook=https://notify.example.com/backup
|
||||
```
|
||||
|
||||
Runs in automated mode with auto-repair and webhook notifications.
|
||||
|
||||
### Performance-Optimized Backup
|
||||
|
||||
```bash
|
||||
./backup-plex.sh --no-parallel --no-performance
|
||||
```
|
||||
|
||||
Runs with parallel processing and performance monitoring disabled for maximum compatibility.
|
||||
|
||||
## Automation and Scheduling
|
||||
|
||||
### Cron Job Setup
|
||||
|
||||
For daily automated backups at 2 AM:
|
||||
|
||||
```bash
|
||||
# Edit crontab
|
||||
crontab -e
|
||||
|
||||
# Add this line for daily backup
|
||||
0 2 * * * /home/acedanger/shell/backup-plex.sh --non-interactive --auto-repair --email=admin@example.com 2>&1 | logger -t plex-backup
|
||||
```
|
||||
|
||||
### Systemd Service
|
||||
|
||||
Create a systemd service for more control:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Plex Backup Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=root
|
||||
ExecStart=/home/acedanger/shell/backup-plex.sh --non-interactive --auto-repair
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
### Systemd Timer
|
||||
|
||||
Create a timer for regular execution:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Daily Plex Backup
|
||||
Requires=plex-backup.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
## Monitoring and Alerts
|
||||
|
||||
### Performance Monitoring
|
||||
|
||||
The script automatically tracks:
|
||||
|
||||
- Backup operation duration
|
||||
- Verification times
|
||||
- Service start/stop times
|
||||
- Overall script execution time
|
||||
|
||||
### Health Checks
|
||||
|
||||
Regular health monitoring can be implemented by checking:
|
||||
|
||||
```bash
|
||||
# Check last backup success
|
||||
jq -r '.[-1] | select(.operation == "total_script") | .timestamp' logs/plex-backup-performance.json
|
||||
|
||||
# Check average backup performance
|
||||
jq '[.[] | select(.operation == "backup") | .duration_seconds] | add/length' logs/plex-backup-performance.json
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Permission Denied Errors**
|
||||
- Ensure script runs with appropriate sudo permissions
|
||||
- Check Plex file ownership and permissions
|
||||
|
||||
2. **WAL File Warnings**
|
||||
- Now handled automatically by the enhanced script
|
||||
- WAL checkpointing ensures data consistency
|
||||
|
||||
3. **Performance Issues**
|
||||
- Use `--no-parallel` if concurrent operations cause problems
|
||||
- Monitor performance logs for bottlenecks
|
||||
|
||||
4. **Notification Failures**
|
||||
- Verify webhook URLs are accessible
|
||||
- Check sendmail configuration for email notifications
|
||||
|
||||
### Debug Mode
|
||||
|
||||
Enable verbose logging by modifying the script or using:
|
||||
|
||||
```bash
|
||||
bash -x ./backup-plex.sh --check-integrity
|
||||
```
|
||||
|
||||
## Testing Framework
|
||||
|
||||
The script includes a comprehensive testing framework (`test-plex-backup.sh`):
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
# Run all tests
|
||||
./test-plex-backup.sh all
|
||||
|
||||
# Run only unit tests
|
||||
./test-plex-backup.sh unit
|
||||
|
||||
# Run performance benchmarks
|
||||
./test-plex-backup.sh performance
|
||||
```
|
||||
|
||||
### Test Categories
|
||||
|
||||
- **Unit Tests**: Core functionality verification
|
||||
- **Integration Tests**: Full system testing (requires Plex installation)
|
||||
- **Performance Tests**: Benchmarking and performance validation
|
||||
|
||||
## Security Considerations
|
||||
|
||||
### File Permissions
|
||||
|
||||
- Backup files are created with appropriate permissions
|
||||
- Sensitive files maintain original ownership and permissions
|
||||
- Temporary files are properly cleaned up
|
||||
|
||||
### Network Security
|
||||
|
||||
- Webhook notifications use HTTPS when possible
|
||||
- Email notifications respect system sendmail configuration
|
||||
- No sensitive data is included in notifications
|
||||
|
||||
### Access Control
|
||||
|
||||
- Script requires appropriate sudo permissions
|
||||
- Backup locations should have restricted access
|
||||
- Log files contain operational data, not sensitive information
|
||||
|
||||
## Backup Strategy
|
||||
|
||||
The enhanced script implements a robust backup strategy with a streamlined tar.gz-only structure:
|
||||
|
||||
### Archive-Only Directory Structure
|
||||
|
||||
The new backup system eliminates intermediate dated directories and stores only compressed archives:
|
||||
|
||||
```bash
|
||||
/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
|
||||
```
|
||||
|
||||
### Archive Naming Convention
|
||||
|
||||
Backup files follow the naming convention `plex-backup-YYYYMMDD_HHMMSS.tar.gz` for easy identification and sorting.
|
||||
|
||||
## Important Information
|
||||
|
||||
- Ensure that the [`plex.sh`](https://github.com/acedanger/shell/blob/main/plex.sh) script is available and executable. This script is used to stop and start the Plex Media Server service.
|
||||
@@ -221,12 +436,54 @@ The enhanced system includes cleanup of legacy dated directories from previous b
|
||||
|
||||
```
|
||||
/mnt/share/media/backups/plex/
|
||||
├── plex-backup-20250125_143022.tar.gz
|
||||
├── plex-backup-20250124_143011.tar.gz
|
||||
├── plex-backup-20250123_143008.tar.gz
|
||||
├── 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-performance.json
|
||||
└── plex-backup.json
|
||||
```
|
||||
|
||||
By following this documentation, you should be able to understand and use the enhanced `backup-plex.sh` script effectively with its new streamlined tar.gz-only structure.
|
||||
Backup files follow the pattern: `plex-backup-YYYYMMDD_HHMMSS.tar.gz`
|
||||
|
||||
- **YYYYMMDD**: Date of backup (e.g., 20250125)
|
||||
- **HHMMSS**: Time of backup (e.g., 143022)
|
||||
- **tar.gz**: Compressed archive format
|
||||
|
||||
### Key Improvements
|
||||
|
||||
1. **Direct Archive Creation**: No intermediate directories required
|
||||
2. **Efficient Storage**: Only compressed files stored permanently
|
||||
3. **Easy Identification**: Timestamp-based naming for sorting
|
||||
4. **Legacy Cleanup**: Automatic removal of old dated directories
|
||||
5. **Archive Validation**: Integrity checking of compressed files
|
||||
|
||||
### 3-2-1 Backup Rule
|
||||
|
||||
1. **3 Copies**: Original data + local backup + compressed archive
|
||||
2. **2 Different Media**: Local disk + network storage capability
|
||||
3. **1 Offsite**: Ready for remote synchronization
|
||||
|
||||
### Retention Policy
|
||||
|
||||
- Configurable maximum backup age (default: 30 days)
|
||||
- Configurable maximum backup count (default: 10 backups)
|
||||
- Automatic cleanup of old backups
|
||||
|
||||
### Verification Strategy
|
||||
|
||||
- Checksum verification for all backed up files
|
||||
- Database integrity checks before and after operations
|
||||
- Optional parallel verification for improved performance
|
||||
|
||||
## Migration from Legacy Script
|
||||
|
||||
To migrate from the original backup script:
|
||||
|
||||
1. **Backup Current Configuration**: Save any custom modifications
|
||||
2. **Test New Script**: Run with `--check-integrity` first
|
||||
3. **Update Automation**: Modify cron jobs to use new options
|
||||
4. **Monitor Performance**: Check performance logs for optimization opportunities
|
||||
|
||||
The enhanced script maintains backward compatibility while adding significant new capabilities.
|
||||
|
||||
Reference in New Issue
Block a user