From: hackbard Date: Sat, 3 Oct 2015 09:18:13 +0000 (+0000) Subject: added trigger file X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=a29a0d8219eb39337e816d06055b121bf9734429;p=outofuni%2Fbackup.git added trigger file --- diff --git a/bin/trigger b/bin/trigger new file mode 100755 index 0000000..fe53c79 --- /dev/null +++ b/bin/trigger @@ -0,0 +1,69 @@ +#!/bin/bash + +# contab example to backup every configuration: +# */1 * * * * /mnt/wd/ext/backup/bin/trigger -a +# +# additional verbose logging: +# */1 * * * * /mnt/wd/ext/backup/bin/trigger -a -l /var/log/trigger.log +# +# backup of configurations 'foo' and 'bar' +# */1 * * * * /mnt/wd/ext/backup/bin/trigger foo bar + +function log { + [ "$dolog" = "1" ] && echo "`date` - $@" >> $log +} + +mode=single +confs="" +log="" +for arg in "$@"; do + case $arg in + -a) + mode=all + shift + ;; + -l) + log=$2 + shift 2 + ;; + *) + confs="$arg $confs" + shift + ;; + esac +done + +prog=$0 +pdir=`dirname $prog` +cdir=$pdir/../config + +dolog=0 +if [ ! -z "$log" ]; then + mkdir -p `dirname $log` + [ -d `dirname $log` ] && dolog=1 +fi + +if [ "$mode" = "all" ]; then + confs="" + for cf in $cdir/*.conf; do + confs="`basename $cf | sed 's/\.conf$//'` $confs" + done +fi + +log triggering backup of $confs ... +for conf in $confs; do + if [ -f $cdir/${conf}.conf ]; then + rp=`ps -ef | grep "[c]onfig/${conf}\.conf"` + if [ -z "$rp" ]; then + cmd="$pdir/backup $cdir/${conf}.conf" + log started backup of $conf ... + nohup $cmd &>/dev/null & + else + log backup of $conf in progress ... + fi + else + log no configuration found for $conf, doing nothing ... + fi +done +log triggering completed, terminating ... +