Added trac handler, changed VSERVERS variable to be lowercase and
[matthijs/upstream/backupninja.git] / handlers / svn
1 #
2 # this handler will backup subversion repostitories.
3 #
4
5 getconf src /var/lib/svn
6 getconf dest /var/backups/svn
7 getconf tmp /var/backups/svn.tmp
8 getconf HOTBACKUP /usr/lib/subversion/hot-backup.py
9 getconf vsname  
10
11 error=0
12
13 # If vservers are configured, decide if the handler should
14 # use them or if it should just operate on the host
15 if [ "$vservers" = "yes" ]
16 then
17         if [ ! -z $vsname ]
18         then            
19                 info "Using vserver '$vsname'"
20                 usevserver=1
21         else
22                 info "No vserver name specified, actions will be performed on the host"
23         fi
24 fi
25
26 # Check to make sure that the specified vserver exists
27 if [ $usevserver ]
28 then
29         vroot="$VROOTDIR/$vsname"
30         [ -d $vroot ] || fatal "vserver '$vsname' does not exist at '$vroot'"
31 fi
32
33 cd $vroot$src
34 for repo in `find . -name svnserve.conf`
35 do
36     repo=`dirname $repo`
37     repo=`dirname $repo`
38
39     ret=`mkdir -p $vroot$tmp/$repo 2>&1`
40     code=$?
41     if [ "$ret" ]; then
42        debug "$ret"
43     fi
44     if [ $code != 0 ]; then   
45        error "command failed mkdir -p $vroot$tmp/$repo"
46     fi
47
48     if [ $usevserver ]
49     then
50         ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1`
51     else
52         ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
53     fi
54     code=$?
55     if [ "$ret" ]; then
56        debug "$ret"
57     fi
58     if [ $code != 0 ]; then
59        error "command failed -- $HOTBACKUP $vroot$src/$repo $vroot$tmp/$repo"
60        error=1
61     fi
62 done
63
64 if [ $error -eq 1 ]; then
65     echo "Error: because of earlier errors, we are leaving svn backups in $vroot$tmp instead of $vroot$dest"
66 else
67     if [ -d $vroot$dest -a -d $vroot$tmp ]; then
68         rm -rf $vroot$dest
69     fi
70     if [ -d $vroot$tmp ]; then
71         mv $vroot$tmp $vroot$dest
72     fi
73 fi
74
75 exit 0