Add enhanced backup and restoration scripts for Plex Media Server with validation and monitoring features

This commit is contained in:
Peter Wood
2025-05-25 19:53:23 -04:00
parent aa854588a5
commit a68a1cc4ba
4 changed files with 1012 additions and 2 deletions

105
README.md
View File

@@ -6,9 +6,109 @@ This repository contains various shell scripts for managing media-related tasks
- [Backup Media Script](docs/backup-media.md): Documentation for the `backup-media.sh` script.
- `plex.sh`: Script to manage the Plex Media Server (start, stop, restart, status).
- `backup-plex.sh`: Script to back up Plex Media Server databases and related files.
- `backup-plex.sh`: Enhanced Plex backup script with integrity verification, incremental backups, and advanced features.
- `restore-plex.sh`: Script to restore Plex data from backups with safety checks.
- `validate-plex-backups.sh`: Script to validate backup integrity and monitor backup health.
- `folder-metrics.sh`: Script to calculate disk usage and file count for a directory and its subdirectories.
## Enhanced Plex Backup System
This repository includes an enhanced backup system for Plex Media Server with multiple components:
### Scripts
- **`backup-plex.sh`**: Advanced backup script with integrity verification, incremental backups, and automatic cleanup
- **`restore-plex.sh`**: Safe restoration script with dry-run mode and current data backup
- **`validate-plex-backups.sh`**: Backup validation and health monitoring script
### Key Features
- **Incremental backups**: Only backs up files that have changed since last backup
- **File integrity verification**: Uses MD5 checksums to verify backup integrity
- **Automatic cleanup**: Configurable retention policies for old backups
- **Disk space monitoring**: Checks available space before starting backup
- **Safe restoration**: Backs up current data before restoring from backup
- **Comprehensive logging**: Detailed logs with color-coded output
- **Service management**: Safely stops/starts Plex during backup operations
### Usage Examples
#### Enhanced Backup Script
```bash
# Run the enhanced backup (recommended)
./backup-plex.sh
```
#### Backup Validation
```bash
# Validate all backups and generate report
./validate-plex-backups.sh --report
# Validate backups and attempt to fix common issues
./validate-plex-backups.sh --fix
# Quick validation check
./validate-plex-backups.sh
```
#### Restore from Backup
```bash
# List available backups
./restore-plex.sh
# Test restore without making changes (dry run)
./restore-plex.sh 20250125 --dry-run
# Actually restore from a specific backup
./restore-plex.sh 20250125
```
### Automation Examples
#### Daily Backup with Validation
```bash
# Add to crontab for daily backup at 3 AM
0 3 * * * /home/acedanger/shell/backup-plex.sh
# Add daily validation at 7 AM
0 7 * * * /home/acedanger/shell/validate-plex-backups.sh --fix
```
#### Weekly Full Validation Report
```bash
# Generate detailed weekly report (Sundays at 8 AM)
0 8 * * 0 /home/acedanger/shell/validate-plex-backups.sh --report
```
### Configuration
The enhanced backup script includes configurable parameters at the top of the file:
- `MAX_BACKUP_AGE_DAYS=30`: Remove backups older than 30 days
- `MAX_BACKUPS_TO_KEEP=10`: Keep maximum of 10 backup sets
- `BACKUP_ROOT`: Location for backup storage
- `LOG_ROOT`: Location for backup logs
### Backup Strategy
The system implements a robust 3-2-1 backup strategy:
1. **3 copies**: Original data + local backup + compressed archive
2. **2 different media**: Local disk + network storage
3. **1 offsite**: Consider syncing to remote location
For offsite backup, add to cron:
```bash
# Sync backups to remote server daily at 6 AM
0 6 * * * rsync -av /mnt/share/media/backups/plex/ user@remote-server:/backups/plex/
```
## Documentation
- [Plex Backup Script Documentation](./docs/plex-backup.md): Detailed documentation for the `backup-plex.sh` script.
@@ -72,6 +172,7 @@ Test your setup in isolated Docker containers with:
- Run comprehensive checks before committing changes
The test environment checks:
- Package availability and installation
- Core components (git, curl, wget, etc.)
- Additional packages from `setup/packages.list`
@@ -80,7 +181,7 @@ The test environment checks:
Tests will continue even when some packages fail to install, reporting all issues in a comprehensive summary.
# plex.sh
## plex.sh
This script is used to manage the Plex Media Server service on a systemd-based Linux distribution. It provides the following functionalities: