Skip to content

Commit

Permalink
Use alternate cron
Browse files Browse the repository at this point in the history
  • Loading branch information
tiredofit committed Dec 4, 2023
1 parent fb9fe8a commit d58b27d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
19 changes: 14 additions & 5 deletions install/assets/dbbackup/template-dbbackup/run
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ if [[ "${MODE,,}" =~ "standalone" ]] || [ "${MODE,,}" = "manual" ] || [ "${1,,}"
backup_job_backup_begin=+0
else
silent sleep {{BACKUP_NUMBER}}
set -x
time_last_run=0
time_current=$(date +'%s')

set +x
if [[ "${backup_job_backup_begin}" =~ ^\+(.*)$ ]]; then
print_debug "BACKUP_BEGIN is a jump of minute starting with +"
timer plusvalue
Expand All @@ -37,10 +38,18 @@ else
#elif echo "${backup_job_backup_begin//\*/#}" | grep -qP "^(.*((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|#) ?){5}$" ; then # Allow slashes, yet not supporting advanced cron yet
elif echo "${backup_job_backup_begin//\*/#}" | grep -qP "^(((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|#) ?){5}$" ; then
print_debug "BACKUP_BEGIN is a cron expression"
time_last_run=$(date +"%s")
backup_job_backup_begin=${backup_job_backup_begin//\"/}
backup_job_backup_begin=${backup_job_backup_begin//\'/}
timer cron "${backup_job_backup_begin}" "${time_current}" "${time_last_run}"
if var_false "${CRON_ALTERNATE}"; then
time_last_run=$(date +"%s")

backup_job_backup_begin=${backup_job_backup_begin//\"/}
backup_job_backup_begin=${backup_job_backup_begin//\'/}
timer cron "${backup_job_backup_begin}" "${time_current}" "${time_last_run}"
else
echo "${backup_job_backup_begin} /var/run/s6/legacy-services/dbbackup-{{BACKUP_NUMBER}} now" > /tmp/.container/cron/{{BACKUP_NUMBER}}-backup
crontab -l | { cat; echo "${backup_job_backup_begin} /var/run/s6/legacy-services/dbbackup-{{BACKUP_NUMBER}} now"; } | crontab -
s6-svc -d /var/run/s6/legacy-services/dbbackup-{{BACKUP_NUMBER}}
exit 0
fi
else
print_error "_BACKUP_BEGIN is invalid - Unable to perform scheduling"
cat <<EOF
Expand Down
1 change: 1 addition & 0 deletions install/assets/defaults/10-db-backup
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/command/with-contenv bash

BACKUP_JOB_CONCURRENCY=${BACKUP_JOB_CONCURRENCY:-"1"}
CRON_ALTERNATE=${CRON_ALTERNATE:-"TRUE"}
DBBACKUP_USER=${DBBACKUP_USER:-"dbbackup"}
DBBACKUP_GROUP=${DBBACKUP_GROUP:-"${DBBACKUP_USER}"} # Must go after DBBACKUP_USER
DEFAULT_BACKUP_BEGIN=${DEFAULT_BACKUP_BEGIN:-+0}
Expand Down
5 changes: 3 additions & 2 deletions install/assets/functions/10-db-backup
Original file line number Diff line number Diff line change
Expand Up @@ -1882,12 +1882,12 @@ timer() {
local cron_compare_difference=$(( cron_compare - ${4} ))

if [ "${cron_compare_difference}" -lt 60 ]; then
cron_compare=$((${cron_compare} + $(( 60 - cron_compare_difference )) ))
cron_compare=$((cron_compare + $(( 60 - cron_compare_difference )) ))
fi

local cron_current_seconds="$(date --date=@"${cron_compare_seconds}" +"%-S")"
if [ "${cron_current_seconds}" -ne 0 ]; then
cron_compare_seconds=$(( cron_compare_seconds - cron_current_seconds ))
cron_compare=$(( cron_compare_seconds - cron_current_seconds ))
fi

local cron_minute="$(echo -n "${2}" | awk '{print $1}')"
Expand Down Expand Up @@ -1926,6 +1926,7 @@ timer() {
fi

cron_next_hour="${cron_next}"
cron_next_minute=0
fi

print_debug "[timer] [cron] Parse Day of Week"
Expand Down

0 comments on commit d58b27d

Please sign in to comment.