]> www.hackdaworld.org Git - outofuni/backup.git/blob - bin/backupctrl
90640d83825c4f623f8f69bd293f058ee36fd1a1
[outofuni/backup.git] / bin / backupctrl
1 #!/bin/bash
2
3 op="pusage"
4
5 function detect() {
6         IFS=$'\n'
7         for psline in `ps -ef | grep [r]sync`; do
8                 ppid="`echo $psline | cut -d ' ' -f 2`"
9                 pptime=`echo $psline | \
10                         sed 's/.*[0-9] \([0-9][0-9]:[0-9][0-9]\) \?.*/\1/'`
11                 ppcmd="`echo $psline | \
12                         sed 's/.*\(rsync .*\)/\1/'`"
13                 echo
14                 echo detected possible backup process $ppid started at $pptime
15                 echo
16                 if [ ! -z "$1" ]; then
17                 if [ "$1" = "kill" ]; then
18                         echo -en "want me to kill it? [y/N]: "
19                         read answer
20                         echo
21                         if [ "$answer" = "y" ]; then
22                                 kill -9 $ppid
23                         fi
24                 fi
25                 fi
26         done
27         IFS=""
28 }
29
30 #if [ $# = 1 ]; then
31         case $1 in
32                 status)
33                         if [ ! -f ~/.backup ]; then
34                                 echo
35                                 echo "backup activated (no rejection file)"
36                                 echo
37                                 detect
38                         else
39                                 if [ -z "`cat ~/.backup | grep ^off`" ]; then
40                                         echo
41                                         echo backup activated
42                                         echo
43                                         detect
44                                 else
45                                         echo
46                                         echo backup rejected
47                                         echo
48                                         detect "kill"
49                                 fi
50                         fi
51                         ;;
52                 off)
53                         echo "# disabled at `date`" > ~/.backup
54                         echo "off" >> ~/.backup
55                         detect "kill"
56                         ;;
57                 on)
58                         echo "# enabled at `date`" > ~/.backup
59                         echo "on" >> ~/.backup
60                         ;;
61                 *)
62                         echo -en "\nusage:\n$0 [status|off|on]\n\n"
63                         ;;
64         esac
65 #fi
66