feat: Migrate to system-specific crontab files with enhanced logging and management

This commit is contained in:
Peter Wood
2025-05-26 12:10:15 -04:00
parent b016f4e241
commit e6aec6dd5d
9 changed files with 70 additions and 44 deletions

View File

@@ -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

View File

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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