mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 03:20:12 -08:00
feat: Add help flag support to enhanced crontab management script installation
This commit is contained in:
@@ -271,7 +271,7 @@ validate_crontab_syntax() {
|
|||||||
local errors=0
|
local errors=0
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
((line_num++))
|
line_num=$((line_num + 1))
|
||||||
|
|
||||||
# Skip comments and empty lines
|
# Skip comments and empty lines
|
||||||
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ "$line" =~ ^[[:space:]]*$ ]]; then
|
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ "$line" =~ ^[[:space:]]*$ ]]; then
|
||||||
@@ -279,9 +279,9 @@ validate_crontab_syntax() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Basic cron format validation
|
# 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"
|
log_error "Line $line_num: Invalid cron format: $line"
|
||||||
((errors++))
|
errors=$((errors + 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for common issues
|
# Check for common issues
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -1,36 +1,5 @@
|
|||||||
# Edit this file to introduce tasks to be run by cron.
|
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
|
||||||
# Each task to run has to be defined through a single line
|
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
|
||||||
# indicating with different fields when the task will be run
|
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
|
||||||
# and what command to run for the task
|
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
|
||||||
#
|
|
||||||
# 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
|
|
||||||
|
|||||||
@@ -204,6 +204,11 @@ show_usage() {
|
|||||||
|
|
||||||
case "${1:-help}" in
|
case "${1:-help}" in
|
||||||
install)
|
install)
|
||||||
|
# Check if --help flag is present
|
||||||
|
if [[ "$*" == *"--help"* ]]; then
|
||||||
|
show_usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
verify_scripts_exist
|
verify_scripts_exist
|
||||||
backup_current_crontab
|
backup_current_crontab
|
||||||
install_enhanced_crontab
|
install_enhanced_crontab
|
||||||
|
|||||||
Reference in New Issue
Block a user