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