|
16 | 16 | current_time=$(date +"%s")
|
17 | 17 | today=$(date +"%Y%m%d")
|
18 | 18 |
|
| 19 | + print_debug "******** Begin DB_DUMP_BEGIN ********" |
| 20 | + print_debug "Current time $current_time" |
| 21 | + |
19 | 22 | if [[ $DB_DUMP_BEGIN =~ ^\+(.*)$ ]]; then
|
| 23 | + print_debug "DB_DUMP_BEGIN is a jump of minute starting with +." |
20 | 24 | waittime=$(( ${BASH_REMATCH[1]} * 60 ))
|
21 | 25 | target_time=$(($current_time + $waittime))
|
22 |
| - else |
| 26 | + elif [[ $DB_DUMP_BEGIN =~ ^[0-9]+$ ]]; then |
| 27 | + print_debug "DB_DUMP_BEGIN is an integer." |
| 28 | + |
23 | 29 | target_time=$(date --date="${today}${DB_DUMP_BEGIN}" +"%s")
|
24 | 30 | if [[ "$target_time" < "$current_time" ]]; then
|
25 | 31 | target_time=$(($target_time + 24*60*60))
|
26 | 32 | fi
|
27 | 33 | waittime=$(($target_time - $current_time))
|
| 34 | + elif [[ $DB_DUMP_BEGIN =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})[[:space:]]([0-9]{2}):([0-9]{2}):([0-9]{2})$ ]]; |
| 35 | + then |
| 36 | + # Calculate DB_DUMP_BEGIN time in seconds |
| 37 | + dump_time=$(date -d "${DB_DUMP_BEGIN}" +%s) |
| 38 | + print_debug "Dump time = $dump_time" |
| 39 | + |
| 40 | + # Calculate the difference in seconds |
| 41 | + waittime=$((dump_time - current_time)) |
| 42 | + print_debug "Difference in seconds: $waittime" |
| 43 | + |
| 44 | + if (( $waittime < 0 )); then |
| 45 | + waittime=$(( ($waittime + ($DB_DUMP_FREQ - 1)) / ($DB_DUMP_FREQ * 60) )) |
| 46 | + waittime=$(( $waittime * -1 )) |
| 47 | + print_debug "Difference in seconds (rounded) waittime is in the past : $waittime" |
| 48 | + fi |
| 49 | + |
| 50 | + target_time=$(($current_time + $waittime)) |
| 51 | + print_debug "Target time = $target_time" |
| 52 | + else |
| 53 | + 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)." |
28 | 54 | fi
|
29 |
| - print_debug "Wait Time: ${waittime} Target time: ${target_time} Current Time: ${current_time}" |
30 |
| - print_info "Next Backup at $(date -d @${target_time} +"%Y-%m-%d %T %Z")" |
| 55 | + |
| 56 | + print_debug "******** End DB_DUMP_BEGIN ********" |
| 57 | + 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")" |
31 | 58 | sleep $waittime
|
32 | 59 | fi
|
33 | 60 |
|
|
0 commit comments