|
16 | 16 | current_time=$(date +"%s")
|
17 | 17 | today=$(date +"%Y%m%d")
|
18 | 18 |
|
19 |
| - if [[ $DB_DUMP_BEGIN =~ ^\+(.*)$ ]]; then |
| 19 | + # Check if DB_DUMP_BEGIN is an integer |
| 20 | + if [[ $DB_DUMP_BEGIN =~ ^[0-9]+$ ]]; then |
| 21 | + print_info "DB_DUMP_BEGIN is an integer." |
20 | 22 | waittime=$(( ${BASH_REMATCH[1]} * 60 ))
|
21 | 23 | target_time=$(($current_time + $waittime))
|
22 |
| - else |
23 |
| - target_time=$(date --date="${today}${DB_DUMP_BEGIN}" +"%s") |
24 |
| - if [[ "$target_time" < "$current_time" ]]; then |
25 |
| - target_time=$(($target_time + 24*60*60)) |
| 24 | + elif [[ $DB_DUMP_BEGIN =~ ^([0-9]{2}):([0-9]{2}):([0-9]{2})$ ]]; then |
| 25 | + print_info "DB_DUMP_BEGIN is time." |
| 26 | + # Extract hours, minutes, and seconds from DB_DUMP_BEGIN |
| 27 | + db_hour=${BASH_REMATCH[1]} |
| 28 | + db_minute=${BASH_REMATCH[2]} |
| 29 | + db_second=${BASH_REMATCH[3]} |
| 30 | + |
| 31 | + # Calculate DB_DUMP_BEGIN time in seconds |
| 32 | + db_time=$(date -d "${db_hour}:${db_minute}:${db_second}" +%s) |
| 33 | + |
| 34 | + # Calculate the difference in seconds |
| 35 | + waittime=$((db_time - current_time)) |
| 36 | + print_info "Difference in seconds: $waittime" |
| 37 | + |
| 38 | + if (( $waittime < 0 )); then |
| 39 | + waittime=$(( ($waittime + ($DB_DUMP_FREQ - 1)) / ($DB_DUMP_FREQ * 60) )) |
| 40 | + waittime=$(( $waittime * -1 )) |
| 41 | + print_info "Difference in seconds (rounded): $waittime" |
26 | 42 | fi
|
27 |
| - waittime=$(($target_time - $current_time)) |
| 43 | + |
| 44 | + target_time=$(($current_time + $waittime)) |
| 45 | + else |
| 46 | + print_info "DB_DUMP_BEGIN is not an integer or in the correct format (hh:mm:ss)." |
28 | 47 | fi
|
29 |
| - print_debug "Wait Time: ${waittime} Target time: ${target_time} Current Time: ${current_time}" |
| 48 | + |
| 49 | + 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")" |
30 | 50 | print_info "Next Backup at $(date -d @${target_time} +"%Y-%m-%d %T %Z")"
|
31 | 51 | sleep $waittime
|
32 | 52 | fi
|
|
0 commit comments