From 250cae98ef16de23ac2741f72e1b05773664ef55 Mon Sep 17 00:00:00 2001 From: Benoit Vianin Date: Sat, 4 Nov 2023 10:34:40 +0000 Subject: [PATCH] Restore the +XX minutes fucntion and move print to debug mode --- .../etc/services.available/10-db-backup/run | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/install/etc/services.available/10-db-backup/run b/install/etc/services.available/10-db-backup/run index a3ebe44..a7fafbd 100755 --- a/install/etc/services.available/10-db-backup/run +++ b/install/etc/services.available/10-db-backup/run @@ -16,13 +16,19 @@ else current_time=$(date +"%s") today=$(date +"%Y%m%d") - # Check if DB_DUMP_BEGIN is an integer - if [[ $DB_DUMP_BEGIN =~ ^[0-9]+$ ]]; then - print_info "DB_DUMP_BEGIN is an integer." + print_debug "******** Begin DB_DUMP_BEGIN ********" + print_debug "Current time $current_time" + + if [[ $DB_DUMP_BEGIN =~ ^\+(.*)$ ]]; then + print_debug "DB_DUMP_BEGIN is a jump of minute starting with +." + waittime=$(( ${BASH_REMATCH[1]} * 60 )) + target_time=$(($current_time + $waittime)) + elif [[ $DB_DUMP_BEGIN =~ ^[0-9]+$ ]]; then + print_debug "DB_DUMP_BEGIN is an integer." waittime=$(( ${BASH_REMATCH[1]} * 60 )) target_time=$(($current_time + $waittime)) elif [[ $DB_DUMP_BEGIN =~ ^([0-9]{2}):([0-9]{2}):([0-9]{2})$ ]]; then - print_info "DB_DUMP_BEGIN is time." + print_debug "DB_DUMP_BEGIN is a time." # Extract hours, minutes, and seconds from DB_DUMP_BEGIN db_hour=${BASH_REMATCH[1]} db_minute=${BASH_REMATCH[2]} @@ -30,24 +36,26 @@ else # Calculate DB_DUMP_BEGIN time in seconds db_time=$(date -d "${db_hour}:${db_minute}:${db_second}" +%s) + print_debug "DB time = $db_time" # Calculate the difference in seconds waittime=$((db_time - current_time)) - print_info "Difference in seconds: $waittime" + print_debug "Difference in seconds: $waittime" if (( $waittime < 0 )); then waittime=$(( ($waittime + ($DB_DUMP_FREQ - 1)) / ($DB_DUMP_FREQ * 60) )) waittime=$(( $waittime * -1 )) - print_info "Difference in seconds (rounded): $waittime" + print_debug "Difference in seconds (rounded) waittime is in the past : $waittime" fi target_time=$(($current_time + $waittime)) + print_debug "Target time = $target_time" else - print_info "DB_DUMP_BEGIN is not an integer or in the correct format (hh:mm:ss)." + print_info "DB_DUMP_BEGIN is not starting with + or is not an integer or is not in the correct format (hh:mm:ss)." fi + print_debug "******** End DB_DUMP_BEGIN ********" print_info "Wait Time: ${waittime} Target time: $(date -d @${target_time} +"%Y-%m-%d %T %Z") Current Time: $(date -d @${current_time} +"%Y-%m-%d %T %Z")" - print_info "Next Backup at $(date -d @${target_time} +"%Y-%m-%d %T %Z")" sleep $waittime fi