diff --git a/handlers/Makefile.am b/handlers/Makefile.am index e9526450dbd9259055b097726b3ce7a9743c52b3..e5e58c486678387a2fde5c7c8ff091b2e081c115 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 0000000000000000000000000000000000000000..8de5e1c4c03bb941703b9dc5640205ad527ffc72 --- /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 <<EOF +### configuration file for nap.handler ### +# This holds back the processing of configuration files in this directory +# for a randomized and configurable time span + +nap_static_random_delay = $nap_static_random_delay +nap_interval_min = $nap_interval_min +nap_interval_max = $nap_interval_max +EOF + chmod 600 $next_filename +} + +nap_main_menu() { + while true; do + static_random_delay="enable the static random delay" + interval_min="specify the minimum delay for the interval $_interval_min_done" + interval_max="specify the maximum delay for the interval $_interval_max_done" + menuBox "$nap_title" "choose a step:" \ + static "$static_random_delay" \ + interval_min "$interval_min" \ + interval_max "$interval_max" \ + finish "finish and create configuration file" + [ $? -eq 0 ] || return + case "$REPLY" in + "static") do_nap_static_random_delay;; + "interval_min") do_nap_interval_min;; + "interval_max") do_nap_interval_max;; + "finish") + if [[ "$_interval_min_done$_interval_max_done" != "(DONE)(DONE)" ]]; then + msgBox "$nap_title" "You cannot create the configuration file until mandatory steps are completed." + else + do_nap_finish + return + fi + ;; + esac + done +} + +nap_wizard() { + + # global variables + nap_title="random delay on backup process wizard" + + _interval_min_done= + _interval_max_done= + + + # define some defaults for the configurations + nap_static_random_delay=true + nap_interval_min= + nap_interval_max= + + nap_main_menu +} diff --git a/handlers/nap.in b/handlers/nap.in new file mode 100644 index 0000000000000000000000000000000000000000..a169bfcbe6429e1ff1d7231ea861b37a85de9688 --- /dev/null +++ b/handlers/nap.in @@ -0,0 +1,25 @@ +# nap.handler for processing the .nap files to freeze the processing of configurations +# in the configuration directory of backupninja temporary. + +getconf nap_static_random_delay +getconf nap_interval_min +getconf nap_interval_max + +# check for static random delay +if [ $nap_static_random_delay == "false" ]; then + + # use perl rand if static random is set false + delay=$(perl -e "print int($nap_interval_min + rand($nap_interval_max - $nap_interval_min))") + +else + + # seed rand with machine-id, the substring 0,8 is needed so the integer value does not + # overflows the max integer value of perl on a 32 bit system. With this method entropy isn't + # a problem + delay=$(cat /etc/machine-id | perl -e "srand(hex(substr(<STDIN>,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"