From 458683d395e0a5c04155e51f4ccd2c67d5ad1a86 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Mon, 26 May 2025 10:59:31 -0400 Subject: [PATCH] feat: Add help flag support to enhanced crontab management script installation --- crontab-backup-system.sh | 6 +-- ...rontab-post-install-20250526_105807.backup | 10 +++++ ...crontab-pre-install-20250526_105807.backup | 41 +++++++++++++++++++ crontab-backups/europa/current-crontab.backup | 41 +++---------------- manage-enhanced-crontab.sh | 5 +++ 5 files changed, 64 insertions(+), 39 deletions(-) create mode 100644 crontab-backups/europa/archive/europa-crontab-post-install-20250526_105807.backup create mode 100644 crontab-backups/europa/archive/europa-crontab-pre-install-20250526_105807.backup diff --git a/crontab-backup-system.sh b/crontab-backup-system.sh index da6557b..60e7567 100755 --- a/crontab-backup-system.sh +++ b/crontab-backup-system.sh @@ -271,7 +271,7 @@ validate_crontab_syntax() { local errors=0 while IFS= read -r line; do - ((line_num++)) + line_num=$((line_num + 1)) # Skip comments and empty lines if [[ "$line" =~ ^[[:space:]]*# ]] || [[ "$line" =~ ^[[:space:]]*$ ]]; then @@ -279,9 +279,9 @@ validate_crontab_syntax() { fi # Basic cron format validation - if [[ ! "$line" =~ ^[[:space:]]*([0-9*,-]+[[:space:]]+){4}[0-9*,-]+[[:space:]].+ ]]; then + if ! [[ "$line" =~ ^[[:space:]]*([0-9*,-]+[[:space:]]+){4}[0-9*,-]+[[:space:]].+ ]]; then log_error "Line $line_num: Invalid cron format: $line" - ((errors++)) + errors=$((errors + 1)) fi # Check for common issues diff --git a/crontab-backups/europa/archive/europa-crontab-post-install-20250526_105807.backup b/crontab-backups/europa/archive/europa-crontab-post-install-20250526_105807.backup new file mode 100644 index 0000000..d4c6b53 --- /dev/null +++ b/crontab-backups/europa/archive/europa-crontab-post-install-20250526_105807.backup @@ -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 10:58:07 AM EDT 2025 +# Backup type: post-install +# System: europa +# User: root +# Full system info: Linux europa 6.1.0-33-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.133-1 (2025-04-10) x86_64 GNU/Linux diff --git a/crontab-backups/europa/archive/europa-crontab-pre-install-20250526_105807.backup b/crontab-backups/europa/archive/europa-crontab-pre-install-20250526_105807.backup new file mode 100644 index 0000000..603b397 --- /dev/null +++ b/crontab-backups/europa/archive/europa-crontab-pre-install-20250526_105807.backup @@ -0,0 +1,41 @@ +# Edit this file to introduce tasks to be run by cron. +# +# Each task to run has to be defined through a single line +# indicating with different fields when the task will be run +# and what command to run for the task +# +# To define the time you can provide concrete values for +# minute (m), hour (h), day of month (dom), month (mon), +# and day of week (dow) or use '*' in these fields (for 'any'). +# +# Notice that tasks will be started based on the cron's system +# daemon's notion of time and timezones. +# +# Output of the crontab jobs (including errors) is sent through +# email to the user the crontab file belongs to (unless redirected). +# +# For example, you can run a backup of all your user accounts +# at 5 a.m every week with: +# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ +# +# For more information see the manual pages of crontab(5) and cron(8) +# +# m h dom mon dow command +# 2023-06-11 I can't figure out how to get the nas to mount automagically so here is a band-aid +# @reboot sleep 30 && mount -a +# +# move the files previously backed up at 0100 +0 1 * * * /home/acedanger/shell/move-backups.sh +# daily Plex backup at 0415 +15 4 * * * /home/acedanger/shell/backup-plex.sh +# daily validation at 0700 +0 7 * * * /home/acedanger/shell/validate-plex-backups.sh --fix +# backup immich database +0 5 * * 1 mv /mnt/share/media/immich/uploads/backups/immich-db-backup* /mnt/share/media/backups/immich +# Generate detailed weekly report (Sundays at 0800) +0 8 * * 0 /home/acedanger/shell/validate-plex-backups.sh --report +# Backup created: Mon May 26 10:58:07 AM EDT 2025 +# Backup type: pre-install +# System: europa +# User: root +# Full system info: Linux europa 6.1.0-33-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.133-1 (2025-04-10) x86_64 GNU/Linux diff --git a/crontab-backups/europa/current-crontab.backup b/crontab-backups/europa/current-crontab.backup index 7d47a76..2fd2558 100644 --- a/crontab-backups/europa/current-crontab.backup +++ b/crontab-backups/europa/current-crontab.backup @@ -1,36 +1,5 @@ -# Edit this file to introduce tasks to be run by cron. -# -# Each task to run has to be defined through a single line -# indicating with different fields when the task will be run -# and what command to run for the task -# -# To define the time you can provide concrete values for -# minute (m), hour (h), day of month (dom), month (mon), -# and day of week (dow) or use '*' in these fields (for 'any'). -# -# Notice that tasks will be started based on the cron's system -# daemon's notion of time and timezones. -# -# Output of the crontab jobs (including errors) is sent through -# email to the user the crontab file belongs to (unless redirected). -# -# For example, you can run a backup of all your user accounts -# at 5 a.m every week with: -# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ -# -# For more information see the manual pages of crontab(5) and cron(8) -# -# m h dom mon dow command -# 2023-06-11 I can't figure out how to get the nas to mount automagically so here is a band-aid -# @reboot sleep 30 && mount -a -# -# move the files previously backed up at 0100 -0 1 * * * /home/acedanger/shell/move-backups.sh -# daily Plex backup at 0415 -15 4 * * * /home/acedanger/shell/backup-plex.sh -# daily validation at 0700 -0 7 * * * /home/acedanger/shell/validate-plex-backups.sh --fix -# backup immich database -0 5 * * 1 mv /mnt/share/media/immich/uploads/backups/immich-db-backup* /mnt/share/media/backups/immich -# Generate detailed weekly report (Sundays at 0800) -0 8 * * 0 /home/acedanger/shell/validate-plex-backups.sh --report +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 diff --git a/manage-enhanced-crontab.sh b/manage-enhanced-crontab.sh index 9f9b796..37c6bc7 100755 --- a/manage-enhanced-crontab.sh +++ b/manage-enhanced-crontab.sh @@ -204,6 +204,11 @@ show_usage() { case "${1:-help}" in install) + # Check if --help flag is present + if [[ "$*" == *"--help"* ]]; then + show_usage + exit 0 + fi verify_scripts_exist backup_current_crontab install_enhanced_crontab