From e42f8e9a8cf09e5dfd96946f608073621ac84479 Mon Sep 17 00:00:00 2001 From: Benoit Vianin Date: Sun, 5 Nov 2023 06:48:47 +0000 Subject: [PATCH] Code refactoring --- install/etc/services.available/10-db-backup/run | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/install/etc/services.available/10-db-backup/run b/install/etc/services.available/10-db-backup/run index 368b5fc..12f2364 100755 --- a/install/etc/services.available/10-db-backup/run +++ b/install/etc/services.available/10-db-backup/run @@ -33,20 +33,12 @@ else waittime=$(($target_time - $current_time)) elif [[ $DB_DUMP_BEGIN =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})[[:space:]]([0-9]{2}):([0-9]{2}):([0-9]{2})$ ]]; then - # Extract year, month, day, hours, minutes, and seconds from DB_DUMP_BEGIN - db_year=${BASH_REMATCH[1]} - db_month=${BASH_REMATCH[2]} - db_day=${BASH_REMATCH[3]} - db_hour=${BASH_REMATCH[4]} - db_minute=${BASH_REMATCH[5]} - db_second=${BASH_REMATCH[6]} - # Calculate DB_DUMP_BEGIN time in seconds - db_time=$(date -d "${db_year}-${db_month}-${db_day} ${db_hour}:${db_minute}:${db_second}" +%s) - print_debug "DB time = $db_time" + dump_time=$(date -d "${DB_DUMP_BEGIN}" +%s) + print_debug "Dump time = $dump_time" # Calculate the difference in seconds - waittime=$((db_time - current_time)) + waittime=$((dump_time - current_time)) print_debug "Difference in seconds: $waittime" if (( $waittime < 0 )); then @@ -58,7 +50,7 @@ else target_time=$(($current_time + $waittime)) print_debug "Target time = $target_time" else - print_info "DB_DUMP_BEGIN is not starting with + or is not an integer or is not 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 (YYYY-mm-dd hh:mm:ss)." fi print_debug "******** End DB_DUMP_BEGIN ********"