From e6aec6dd5d6102b2fa7af236ac8bb28b6dd0fce3 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Mon, 26 May 2025 12:10:15 -0400 Subject: [PATCH] feat: Migrate to system-specific crontab files with enhanced logging and management --- README.md | 61 +++++++++++++++++++ ...d-crontab-europa.txt => crontab-europa.txt | 0 enhanced-crontab-io.txt => crontab-io.txt | 0 ...ontab-racknerd.txt => crontab-racknerd.txt | 0 docs/crontab-merging-issue-resolution.md | 0 docs/enhanced-crontab-system.md | 2 +- enhanced-crontab.txt | 28 --------- fix-crontab-merging.sh | 8 +-- manage-enhanced-crontab.sh | 15 ++--- 9 files changed, 70 insertions(+), 44 deletions(-) rename enhanced-crontab-europa.txt => crontab-europa.txt (100%) rename enhanced-crontab-io.txt => crontab-io.txt (100%) rename enhanced-crontab-racknerd.txt => crontab-racknerd.txt (100%) create mode 100644 docs/crontab-merging-issue-resolution.md delete mode 100644 enhanced-crontab.txt diff --git a/README.md b/README.md index adddf56..cb728ad 100644 --- a/README.md +++ b/README.md @@ -334,3 +334,64 @@ Note that these commands will run as `root`. ```shell ./shell/plex.sh {start|stop|restart|status} ``` + +## Enhanced Crontab System Migration + +### System Status + +The crontab system has been migrated from a universal `crontab.txt` to system-specific files: + +- **crontab-europa.txt** - Media server configuration +- **crontab-io.txt** - Download/acquisition server configuration +- **crontab-racknerd.txt** - Backup server configuration + +### Legacy File Status + +The original `crontab.txt` has been: + +- **Backed up** to `crontab.txt.bak` +- **Role**: Previously served as fallback, now obsolete +- **Content**: Contains mixed configuration that was split into system-specific files + +### Current Management + +Use the system-specific approach: + +```bash +# Install system-specific crontab +./manage-enhanced-crontab.sh install + +# The script automatically detects hostname and uses appropriate file +# europa -> crontab-europa.txt +# io -> crontab-io.txt +# racknerd -> crontab-racknerd.txt +``` + +### Fallback Behavior + +If a system-specific file is missing, the management script will: + +1. **Warning**: Display that system-specific file is not found +2. **Recommendation**: Create appropriate system-specific file + +### Creating New System Files + +For new systems, create system-specific files based on the templates: + +```bash +# Copy and customize for new system +cp crontab-europa.txt crontab-newsystem.txt +# Edit for system-specific tasks +``` + +### Benefits of System-Specific Approach + +- **Clear separation** of concerns between systems +- **Reduced conflicts** from universal configurations +- **System-appropriate** task scheduling +- **Better maintenance** and troubleshooting +- **Scalable** for additional systems + +#### Migration Notes + +Migration completed: May 26, 2025 diff --git a/enhanced-crontab-europa.txt b/crontab-europa.txt similarity index 100% rename from enhanced-crontab-europa.txt rename to crontab-europa.txt diff --git a/enhanced-crontab-io.txt b/crontab-io.txt similarity index 100% rename from enhanced-crontab-io.txt rename to crontab-io.txt diff --git a/enhanced-crontab-racknerd.txt b/crontab-racknerd.txt similarity index 100% rename from enhanced-crontab-racknerd.txt rename to crontab-racknerd.txt diff --git a/docs/crontab-merging-issue-resolution.md b/docs/crontab-merging-issue-resolution.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/enhanced-crontab-system.md b/docs/enhanced-crontab-system.md index c11cbea..e53bc35 100644 --- a/docs/enhanced-crontab-system.md +++ b/docs/enhanced-crontab-system.md @@ -6,7 +6,7 @@ This enhanced system provides comprehensive crontab management with automatic ba ## Components -### 1. Enhanced Crontab Entries (`enhanced-crontab.txt`) +### 1. Crontab Entries (`crontab-*.txt`) - **Move backups** (01:00): Transfers Docker backups with logging - **Plex backup** (04:15): Daily Plex database backup with auto-repair diff --git a/enhanced-crontab.txt b/enhanced-crontab.txt deleted file mode 100644 index db1c565..0000000 --- a/enhanced-crontab.txt +++ /dev/null @@ -1,28 +0,0 @@ -# Enhanced Crontab Entries with System Logging -# -# These entries include comprehensive logging to syslog with proper tags -# and error handling for better monitoring and troubleshooting - -# Move the files previously backed up at 0100 -# Logs both stdout and stderr with backup-move tag -0 1 * * * /home/acedanger/shell/move-backups.sh 2>&1 | logger -t backup-move -p user.info - -# Daily Plex backup at 0415 with enhanced logging -# 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 - -# Daily validation at 0700 with detailed logging -# Logs validation results and any auto-fixes performed -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 - -# Backup Immich database weekly (Mondays at 0500) -# Enhanced with proper logging and error handling -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 - -# Generate detailed weekly report (Sundays at 0800) -# Comprehensive reporting with system logging -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 - -# Optional: Add a health check entry to monitor cron jobs (every 6 hours) -# This can help detect if any of the backup processes are failing -# 0 */6 * * * { echo "Cron health check - all backup jobs scheduled"; ps aux | grep -E "(backup-plex|validate-plex|move-backups)" | grep -v grep | wc -l; } 2>&1 | logger -t cron-health -p user.info diff --git a/fix-crontab-merging.sh b/fix-crontab-merging.sh index 09be617..8af471d 100755 --- a/fix-crontab-merging.sh +++ b/fix-crontab-merging.sh @@ -68,7 +68,7 @@ show_current_problem() { fix_crontab() { local system_name="$1" - local crontab_file="$SCRIPT_DIR/enhanced-crontab-${system_name}.txt" + local crontab_file="$SCRIPT_DIR/crontab-${system_name}.txt" if [ ! -f "$crontab_file" ]; then log_error "System-specific crontab file not found: $crontab_file" @@ -130,9 +130,9 @@ main() { echo log_success "Crontab recovery completed for $HOSTNAME" - log_info "The enhanced management script now uses system-specific files:" - log_info " - enhanced-crontab-europa.txt" - log_info " - enhanced-crontab-racknerd.txt" + log_info "The management script now uses system-specific files:" + log_info " - crontab-europa.txt" + log_info " - crontab-racknerd.txt" echo log_info "To manage crontabs going forward, use:" log_info " ./manage-enhanced-crontab.sh install" diff --git a/manage-enhanced-crontab.sh b/manage-enhanced-crontab.sh index c6740da..78988a4 100755 --- a/manage-enhanced-crontab.sh +++ b/manage-enhanced-crontab.sh @@ -15,7 +15,7 @@ NC='\033[0m' # No Color SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" HOSTNAME=$(hostname) -ENHANCED_CRONTAB_FILE="$SCRIPT_DIR/enhanced-crontab-${HOSTNAME}.txt" +ENHANCED_CRONTAB_FILE="$SCRIPT_DIR/crontab-${HOSTNAME}.txt" BACKUP_CRONTAB_FILE="/tmp/crontab-backup-$(date +%Y%m%d_%H%M%S)" log_message() { @@ -54,17 +54,10 @@ install_enhanced_crontab() { if [ ! -f "$ENHANCED_CRONTAB_FILE" ]; then log_warning "System-specific crontab file not found: $ENHANCED_CRONTAB_FILE" log_info "Available crontab files:" - ls -la "$SCRIPT_DIR"/enhanced-crontab-*.txt 2>/dev/null || log_warning "No system-specific crontab files found" + ls -la "$SCRIPT_DIR"/crontab-*.txt 2>/dev/null || log_warning "No system-specific crontab files found" - # Check for generic fallback - FALLBACK_CRONTAB="$SCRIPT_DIR/enhanced-crontab.txt" - if [ -f "$FALLBACK_CRONTAB" ]; then - log_info "Using generic fallback crontab: $FALLBACK_CRONTAB" - ENHANCED_CRONTAB_FILE="$FALLBACK_CRONTAB" - else - log_error "No suitable crontab file found. Please create $ENHANCED_CRONTAB_FILE or $FALLBACK_CRONTAB" - return 1 - fi + log_error "No suitable crontab file found. Please create $ENHANCED_CRONTAB_FILE" + return 1 fi # Create a backup before making changes