Peter Wood 7e2bfd451b 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.
2025-05-25 23:07:37 -04:00
2023-07-20 00:49:15 +00:00

Shell Scripts and Dotfiles Repository

This repository contains various shell scripts for managing media-related tasks and dotfiles for system configuration.

Available Scripts

  • Backup Media Script: Documentation for the backup-media.sh script.
  • plex.sh: Script to manage the Plex Media Server (start, stop, restart, status).
  • 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

# Run the enhanced backup (recommended)
./backup-plex.sh

Backup Validation

# 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

# 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

# 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

# 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:

# Sync backups to remote server daily at 6 AM
0 6 * * * rsync -av /mnt/share/media/backups/plex/ user@remote-server:/backups/plex/

Documentation

Dotfiles

The repository includes dotfiles for system configuration in the dotfiles directory. These can be automatically set up using the bootstrap script:

curl -fsSL https://raw.githubusercontent.com/acedanger/shell/main/bootstrap.sh | bash

For more information about the dotfiles, see Dotfiles README.

Testing

This repository includes Docker-based testing to validate the setup process across different environments:

  • test-setup.sh: Script that validates the bootstrap and setup process
  • run-docker-tests.sh: Runner script that executes tests in Docker containers
  • Dockerfile: Defines test environments (Ubuntu, Debian)

Running Tests

Test your setup in isolated Docker containers with:

# Test in Ubuntu container
./run-docker-tests.sh ubuntu

# Test in Debian container
./run-docker-tests.sh debian

# Run full bootstrap test in Ubuntu
./run-docker-tests.sh full-ubuntu

# Run full bootstrap test in Debian
./run-docker-tests.sh full-debian

# Test in both Ubuntu and Debian
./run-docker-tests.sh all

When to Use Each Testing Option

  • Use ./run-docker-tests.sh ubuntu or ./run-docker-tests.sh debian when you want to:

    • Quickly validate if packages in packages.list are available and installed
    • Test if your test-setup.sh script is working correctly
    • Check for issues with specific components without performing a full setup
  • Use ./run-docker-tests.sh full-ubuntu or ./run-docker-tests.sh full-debian when you want to:

    • Test the complete bootstrap installation process end-to-end
    • Validate that all installation steps work correctly on a fresh system
    • Simulate what users will experience when running the bootstrap script
  • Use ./run-docker-tests.sh all when you want to:

    • Ensure your test-setup.sh works across both Ubuntu and Debian
    • 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
  • Oh My Zsh and plugin installation
  • Dotfile symlinks

Tests will continue even when some packages fail to install, reporting all issues in a comprehensive summary.

plex.sh

This script is used to manage the Plex Media Server service on a systemd-based Linux distribution. It provides the following functionalities:

  • start: Starts the Plex Media Server.
  • stop: Stops the Plex Media Server.
  • restart: Restarts the Plex Media Server.
  • status: Displays the current status of the Plex Media Server.

Usage

Note that these commands will run as root.

./shell/plex.sh {start|stop|restart|status}
Description
No description provided
Readme 16 MiB
Languages
Shell 84.6%
PowerShell 5.3%
Go 3.2%
HTML 3.2%
Python 2.2%
Other 1.5%