#!/bin/bash # Install (or refresh) the single daily crontab entry that drives application # backups. The entry runs `libreportal backup scheduled`, which enqueues a # backup task per enabled app for the processor to drain serially. crontabSetupBackupScheduler() { local ISCRON=$( (runAsManager crontab -l) 2>/dev/null ) if [[ "$ISCRON" == *"command not found"* ]]; then isNotice "Crontab is not found. Unable to set up the backup scheduler." return 0 fi if ! runAsManager crontab -l 2>/dev/null | grep -q "cron is set up for $sudo_user_name"; then isNotice "Crontab is not set up, skipping backup scheduler until it's found." return 0 fi local marker="# CRONTAB BACKUP SCHEDULER" local scheduler_entry="$CFG_BACKUP_CRONTAB_APP libreportal backup scheduled $marker" # Drop any previous scheduler entry first. This happens whichever mode we # are in, and it is what makes Manual actually take effect: switching to # Manual has to REMOVE an entry that is already installed, not merely # decline to add one. local result; result=$(runAsManager crontab -l 2>/dev/null | grep -v "$marker" | runAsManager crontab -) # Manual: the user starts backups themselves from the Backup page. The # schedule below is left in the config untouched, so switching back to # Automatic restores the time they had chosen rather than a default. if [[ "${CFG_BACKUP_MODE:-automatic}" == "manual" ]]; then isNotice "Backups are set to Manual — no schedule installed. Start them from the Backup page." return 0 fi local result; result=$( (runAsManager crontab -l 2>/dev/null; echo "$scheduler_entry") | runAsManager crontab - ) checkSuccess "Installing the daily backup scheduler entry" local schedule_time=$(echo "$CFG_BACKUP_CRONTAB_APP" | cut -d' ' -f2) isSuccessful "Enabled apps will be queued for backup daily at ${schedule_time}:00" }