Skip to content

Commit 250cae9

Browse files
committed
Restore the +XX minutes fucntion and move print to debug mode
1 parent 3c6beea commit 250cae9

File tree

1 file changed

+16
-8
lines changed
  • install/etc/services.available/10-db-backup

1 file changed

+16
-8
lines changed

install/etc/services.available/10-db-backup/run

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,46 @@ else
1616
current_time=$(date +"%s")
1717
today=$(date +"%Y%m%d")
1818

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."
2228
waittime=$(( ${BASH_REMATCH[1]} * 60 ))
2329
target_time=$(($current_time + $waittime))
2430
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."
2632
# Extract hours, minutes, and seconds from DB_DUMP_BEGIN
2733
db_hour=${BASH_REMATCH[1]}
2834
db_minute=${BASH_REMATCH[2]}
2935
db_second=${BASH_REMATCH[3]}
3036

3137
# Calculate DB_DUMP_BEGIN time in seconds
3238
db_time=$(date -d "${db_hour}:${db_minute}:${db_second}" +%s)
39+
print_debug "DB time = $db_time"
3340

3441
# Calculate the difference in seconds
3542
waittime=$((db_time - current_time))
36-
print_info "Difference in seconds: $waittime"
43+
print_debug "Difference in seconds: $waittime"
3744

3845
if (( $waittime < 0 )); then
3946
waittime=$(( ($waittime + ($DB_DUMP_FREQ - 1)) / ($DB_DUMP_FREQ * 60) ))
4047
waittime=$(( $waittime * -1 ))
41-
print_info "Difference in seconds (rounded): $waittime"
48+
print_debug "Difference in seconds (rounded) waittime is in the past : $waittime"
4249
fi
4350

4451
target_time=$(($current_time + $waittime))
52+
print_debug "Target time = $target_time"
4553
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)."
4755
fi
4856

57+
print_debug "******** End DB_DUMP_BEGIN ********"
4958
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")"
5159
sleep $waittime
5260
fi
5361

0 commit comments

Comments
 (0)