]> hackdaworld.org Git - outofuni/backup.git/commitdiff
added ctrl prog for client
authorhackbard <hackbard@hackdaworld.org>
Sun, 11 Oct 2015 15:56:45 +0000 (17:56 +0200)
committerhackbard <hackbard@hackdaworld.org>
Sun, 11 Oct 2015 15:56:45 +0000 (17:56 +0200)
bin/backupctrl [new file with mode: 0755]

diff --git a/bin/backupctrl b/bin/backupctrl
new file mode 100755 (executable)
index 0000000..90640d8
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+op="pusage"
+
+function detect() {
+       IFS=$'\n'
+       for psline in `ps -ef | grep [r]sync`; do
+               ppid="`echo $psline | cut -d ' ' -f 2`"
+               pptime=`echo $psline | \
+                       sed 's/.*[0-9] \([0-9][0-9]:[0-9][0-9]\) \?.*/\1/'`
+               ppcmd="`echo $psline | \
+                       sed 's/.*\(rsync .*\)/\1/'`"
+               echo
+               echo detected possible backup process $ppid started at $pptime
+               echo
+               if [ ! -z "$1" ]; then
+               if [ "$1" = "kill" ]; then
+                       echo -en "want me to kill it? [y/N]: "
+                       read answer
+                       echo
+                       if [ "$answer" = "y" ]; then
+                               kill -9 $ppid
+                       fi
+               fi
+               fi
+       done
+       IFS=""
+}
+
+#if [ $# = 1 ]; then
+       case $1 in
+               status)
+                       if [ ! -f ~/.backup ]; then
+                               echo
+                               echo "backup activated (no rejection file)"
+                               echo
+                               detect
+                       else
+                               if [ -z "`cat ~/.backup | grep ^off`" ]; then
+                                       echo
+                                       echo backup activated
+                                       echo
+                                       detect
+                               else
+                                       echo
+                                       echo backup rejected
+                                       echo
+                                       detect "kill"
+                               fi
+                       fi
+                       ;;
+               off)
+                       echo "# disabled at `date`" > ~/.backup
+                       echo "off" >> ~/.backup
+                       detect "kill"
+                       ;;
+               on)
+                       echo "# enabled at `date`" > ~/.backup
+                       echo "on" >> ~/.backup
+                       ;;
+               *)
+                       echo -en "\nusage:\n$0 [status|off|on]\n\n"
+                       ;;
+       esac
+#fi
+