Hello! We are running our annual fundraising. Please consider making a donation if you value this freely available service or want to support people around the world working towards liberatory social change. https://riseup.net/donate.

Commit 0d8afeb8 authored by Emil Breiner's avatar Emil Breiner
Browse files

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
parent ab8d5a3a
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
......@@ -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
# 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
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
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
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
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;;
if [[ "$_interval_min_done$_interval_max_done" != "(DONE)(DONE)" ]]; then
msgBox "$nap_title" "You cannot create the configuration file until mandatory steps are completed."
nap_wizard() {
# global variables
nap_title="random delay on backup process wizard"
# define some defaults for the configurations
# 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))")
# 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))")
echo "Holding processing of configurations for $delay seconds..."
perl -e "sleep $delay"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment