mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 03:20:12 -08:00
feat: Migrate to system-specific crontab files with enhanced logging and management
This commit is contained in:
61
README.md
61
README.md
@@ -334,3 +334,64 @@ Note that these commands will run as `root`.
|
|||||||
```shell
|
```shell
|
||||||
./shell/plex.sh {start|stop|restart|status}
|
./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
|
||||||
|
|||||||
0
docs/crontab-merging-issue-resolution.md
Normal file
0
docs/crontab-merging-issue-resolution.md
Normal file
@@ -6,7 +6,7 @@ This enhanced system provides comprehensive crontab management with automatic ba
|
|||||||
|
|
||||||
## Components
|
## Components
|
||||||
|
|
||||||
### 1. Enhanced Crontab Entries (`enhanced-crontab.txt`)
|
### 1. Crontab Entries (`crontab-*.txt`)
|
||||||
|
|
||||||
- **Move backups** (01:00): Transfers Docker backups with logging
|
- **Move backups** (01:00): Transfers Docker backups with logging
|
||||||
- **Plex backup** (04:15): Daily Plex database backup with auto-repair
|
- **Plex backup** (04:15): Daily Plex database backup with auto-repair
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -68,7 +68,7 @@ show_current_problem() {
|
|||||||
|
|
||||||
fix_crontab() {
|
fix_crontab() {
|
||||||
local system_name="$1"
|
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
|
if [ ! -f "$crontab_file" ]; then
|
||||||
log_error "System-specific crontab file not found: $crontab_file"
|
log_error "System-specific crontab file not found: $crontab_file"
|
||||||
@@ -130,9 +130,9 @@ main() {
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
log_success "Crontab recovery completed for $HOSTNAME"
|
log_success "Crontab recovery completed for $HOSTNAME"
|
||||||
log_info "The enhanced management script now uses system-specific files:"
|
log_info "The management script now uses system-specific files:"
|
||||||
log_info " - enhanced-crontab-europa.txt"
|
log_info " - crontab-europa.txt"
|
||||||
log_info " - enhanced-crontab-racknerd.txt"
|
log_info " - crontab-racknerd.txt"
|
||||||
echo
|
echo
|
||||||
log_info "To manage crontabs going forward, use:"
|
log_info "To manage crontabs going forward, use:"
|
||||||
log_info " ./manage-enhanced-crontab.sh install"
|
log_info " ./manage-enhanced-crontab.sh install"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ NC='\033[0m' # No Color
|
|||||||
|
|
||||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
HOSTNAME=$(hostname)
|
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)"
|
BACKUP_CRONTAB_FILE="/tmp/crontab-backup-$(date +%Y%m%d_%H%M%S)"
|
||||||
|
|
||||||
log_message() {
|
log_message() {
|
||||||
@@ -54,17 +54,10 @@ install_enhanced_crontab() {
|
|||||||
if [ ! -f "$ENHANCED_CRONTAB_FILE" ]; then
|
if [ ! -f "$ENHANCED_CRONTAB_FILE" ]; then
|
||||||
log_warning "System-specific crontab file not found: $ENHANCED_CRONTAB_FILE"
|
log_warning "System-specific crontab file not found: $ENHANCED_CRONTAB_FILE"
|
||||||
log_info "Available crontab files:"
|
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
|
log_error "No suitable crontab file found. Please create $ENHANCED_CRONTAB_FILE"
|
||||||
FALLBACK_CRONTAB="$SCRIPT_DIR/enhanced-crontab.txt"
|
return 1
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a backup before making changes
|
# Create a backup before making changes
|
||||||
|
|||||||
Reference in New Issue
Block a user