]> hackdaworld.org Git - outofuni/backup.git/commitdiff
added trigger file
authorhackbard <hackbard@hackdaworld.org>
Sat, 3 Oct 2015 09:18:13 +0000 (09:18 +0000)
committerhackbard <hackbard@hackdaworld.org>
Sat, 3 Oct 2015 09:18:13 +0000 (09:18 +0000)
bin/trigger [new file with mode: 0755]

diff --git a/bin/trigger b/bin/trigger
new file mode 100755 (executable)
index 0000000..fe53c79
--- /dev/null
@@ -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 ...
+