feat: Add enhanced crontab entries and backup management with improved logging and fallback mechanisms

This commit is contained in:
Peter Wood
2025-05-26 15:46:55 +00:00
parent 907c1ed18e
commit 06f1b78c5e
8 changed files with 49 additions and 4 deletions

View File

@@ -0,0 +1,10 @@
0 1 * * * /home/acedanger/shell/move-backups.sh 2>&1 | logger -t backup-move -p user.info
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
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
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
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
# Backup created: Mon May 26 03:30:22 PM UTC 2025
# Backup type: post-install
# System: io
# User: root
# Full system info: Linux io 6.8.0-59-generic #61-Ubuntu SMP PREEMPT_DYNAMIC Fri Apr 11 23:16:11 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

View File

@@ -0,0 +1,6 @@
0 2 * * * { echo "Starting Docker backup"; /home/acedanger/shell/backup-docker.sh; echo "Docker backup completed with exit code: $?"; } 2>&1 | logger -t docker-backup -p user.info
# Backup created: Mon May 26 03:44:30 PM UTC 2025
# Backup type: post-install
# System: io
# User: root
# Full system info: Linux io 6.8.0-59-generic #61-Ubuntu SMP PREEMPT_DYNAMIC Fri Apr 11 23:16:11 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

View File

@@ -0,0 +1 @@
0 2 * * * { echo "Starting Docker backup"; /home/acedanger/shell/backup-docker.sh; echo "Docker backup completed with exit code: $?"; } 2>&1 | logger -t docker-backup -p user.info

12
enhanced-crontab-io.txt Normal file
View File

@@ -0,0 +1,12 @@
# Enhanced Crontab Entries for IO (Download/Acquisition Server)
#
# This system runs download management services (Radarr, Sonarr, SABnzbd, etc.)
# and should focus on Docker container management rather than media server tasks
# Daily Docker backup at 0200 with enhanced logging
# Backs up Docker container configurations and data
0 2 * * * { echo "Starting Docker backup"; /home/acedanger/shell/backup-docker.sh; echo "Docker backup completed with exit code: $?"; } 2>&1 | logger -t docker-backup -p user.info
# Optional: Monitor Docker container health (every 6 hours)
# This can help detect if any download services are failing
# 0 */6 * * * { echo "Docker health check"; docker ps --format "table {{.Names}}\t{{.Status}}" | grep -v "Up"; } 2>&1 | logger -t docker-health -p user.info

View File

@@ -50,17 +50,29 @@ backup_current_crontab() {
install_enhanced_crontab() { install_enhanced_crontab() {
log_info "Installing enhanced crontab entries for system: $HOSTNAME" log_info "Installing enhanced crontab entries for system: $HOSTNAME"
# Check for system-specific crontab file first
if [ ! -f "$ENHANCED_CRONTAB_FILE" ]; then if [ ! -f "$ENHANCED_CRONTAB_FILE" ]; then
log_error "Enhanced 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"/enhanced-crontab-*.txt 2>/dev/null || log_warning "No system-specific crontab files found"
return 1
# 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
fi fi
# Create a backup before making changes # Create a backup before making changes
if [ -f "$SCRIPT_DIR/crontab-backup-system.sh" ]; then if [ -f "$SCRIPT_DIR/crontab-backup-system.sh" ]; then
log_info "Creating pre-install backup" log_info "Creating pre-install backup"
"$SCRIPT_DIR/crontab-backup-system.sh" backup pre-install if ! "$SCRIPT_DIR/crontab-backup-system.sh" backup pre-install; then
log_warning "Pre-install backup failed (normal for systems with no existing crontab)"
fi
fi fi
# Extract just the cron entries (skip comments and empty lines) # Extract just the cron entries (skip comments and empty lines)
@@ -74,6 +86,8 @@ install_enhanced_crontab() {
rm -f /tmp/cron_entries_only.txt rm -f /tmp/cron_entries_only.txt
return 1 return 1
fi fi
else
log_warning "Backup script not found, skipping validation"
fi fi
if sudo crontab /tmp/cron_entries_only.txt; then if sudo crontab /tmp/cron_entries_only.txt; then
@@ -82,7 +96,9 @@ install_enhanced_crontab() {
# Create a post-install backup # Create a post-install backup
if [ -f "$SCRIPT_DIR/crontab-backup-system.sh" ]; then if [ -f "$SCRIPT_DIR/crontab-backup-system.sh" ]; then
"$SCRIPT_DIR/crontab-backup-system.sh" backup post-install if ! "$SCRIPT_DIR/crontab-backup-system.sh" backup post-install; then
log_warning "Post-install backup failed, but crontab installation was successful"
fi
fi fi
else else
log_error "Failed to install enhanced crontab entries" log_error "Failed to install enhanced crontab entries"