From 0d8afeb8070b1ec80e9ff386fdf5cb89ea47d51d Mon Sep 17 00:00:00 2001 From: Emil Breiner Date: Wed, 18 Nov 2020 17:59:11 +0100 Subject: [PATCH] Introduction of a new helper-handler pair named nap The .nap file can be created to freeze the processing of the configurations for a (static) random interval. It is possible to specify the interval in seconds with a min and a max value and if it should be static. Change-Id: I9523fd3645b1007fe7e24b6bd4ec18a104a07e05 --- handlers/Makefile.am | 12 ++++- handlers/nap.helper.in | 101 +++++++++++++++++++++++++++++++++++++++++ handlers/nap.in | 25 ++++++++++ 3 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 handlers/nap.helper.in create mode 100644 handlers/nap.in diff --git a/handlers/Makefile.am b/handlers/Makefile.am index e952645..e5e58c4 100644 --- a/handlers/Makefile.am +++ b/handlers/Makefile.am @@ -1,10 +1,10 @@ HANDLERS = borg borg.helper dup dup.helper maildir makecd \ - makecd.helper mysql mysql.helper pgsql pgsql.helper rdiff \ + makecd.helper mysql mysql.helper nap nap.helper pgsql pgsql.helper rdiff \ rdiff.helper rsync sh svn sys sys.helper trac tar tar.helper DIST_HANDLERS = borg.in borg.helper.in dup.in dup.helper.in maildir.in makecd.in \ - makecd.helper.in mysql.in mysql.helper.in pgsql.in pgsql.helper.in rdiff.in \ + makecd.helper.in mysql.in mysql.helper.in nap.in nap.helper.in pgsql.in pgsql.helper.in rdiff.in \ rdiff.helper.in rsync.in sh.in svn.in sys.in sys.helper.in trac.in tar.in tar.helper.in wget CLEANFILES = $(HANDLERS) @@ -62,6 +62,14 @@ mysql.helper: $(srcdir)/mysql.helper.in rm -f mysql.helper $(edit) $(srcdir)/mysql.helper.in > mysql.helper +nap: $(srcdir)/nap.in + rm -f nap + $(edit) $(srcdir)/nap.in > nap + +nap.helper: $(srcdir)/nap.helper.in + rm -f nap.helper + $(edit) $(srcdir)/nap.helper.in > nap.helper + pgsql: $(srcdir)/pgsql.in rm -f pgsql $(edit) $(srcdir)/pgsql.in > pgsql diff --git a/handlers/nap.helper.in b/handlers/nap.helper.in new file mode 100644 index 0000000..8de5e1c --- /dev/null +++ b/handlers/nap.helper.in @@ -0,0 +1,101 @@ +# nap.helper creates a configuration file to offer the possibility +# to add a delay in form of a sleep before the start of the backup +# process itself + +HELPERS="$HELPERS nap:randomized_delay_of_backups" + +do_nap_static_random_delay() { + + # set a boolean value to enable a static random delay seeded with the machine-id in /etc/machine-id. + radioBox "$nap_title" "enable the static random delay. For more information check the doc's..." \ + "true" "enable the static random delay" off \ + "false" "default" on + [ $? -eq 1 ] && return + nap_static_random_delay=$REPLY + setDefault interval_min +} + + +do_nap_interval_min() { + + msg="Specify a lower limit for the time span of the delay in seconds:" + # set the minimum delay for the interval + inputBox "$nap_title" "${msg}" + [ $? -eq 0 ] || return + nap_interval_min=$REPLY + _interval_min_done="(DONE)" + setDefault interval_max +} + +do_nap_interval_max() { + + msg="Specify a upper limit for the time span of the delay in seconds:" + # set the maximum delay for the interval + inputBox "$nap_title" "${msg}" + [ $? -eq 0 ] || return + nap_interval_max=$REPLY + _interval_max_done="(DONE)" + setDefault finish +} + +do_nap_finish() { + + # Uses the prefix 0.nap because it has to be the first file processed by the corresponding handler + # that the randomized delay becomes useful. + + get_next_filename $configdirectory/1.nap + cat > $next_filename <,0,8))); \ + print int($nap_interval_min + rand($nap_interval_max - $nap_interval_min))") + +fi + +echo "Holding processing of configurations for $delay seconds..." +perl -e "sleep $delay"