4dca225172cce1f6b30825221d0529c7fd8192e6
[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/bin/svnadmin hotcopy"
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 # If needed, make sure that the specified vserver exists and is running.
27 if [ $usevserver ]
28 then
29         info "examining vserver '$vsname'"
30         # does it exist ?
31         vroot="$VROOTDIR/$vsname"
32         [ -d $vroot ] || fatal "vserver '$vsname' does not exist at '$vroot'"
33         # is it running ?
34         running=`$VSERVERINFO $vsname RUNNING`
35         [ "$running" = "1" ] || fatal "vserver $vsname is not running."
36 fi
37
38 cd $vroot$src
39 for repo in `find . -name svnserve.conf`
40 do
41     repo=`dirname $repo`
42     repo=`dirname $repo`
43
44     ret=`mkdir -p $vroot$tmp/$repo 2>&1`
45     code=$?
46     if [ "$ret" ]; then
47        debug "$ret"
48     fi
49     if [ $code != 0 ]; then   
50        error "command failed mkdir -p $vroot$tmp/$repo"
51     fi
52
53     if [ $usevserver ]
54     then
55         ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1`
56     else
57         ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
58     fi
59     code=$?
60     if [ "$ret" ]; then
61        debug "$ret"
62     fi
63     if [ $code != 0 ]; then
64        error "command failed -- $HOTBACKUP $vroot$src/$repo $vroot$tmp/$repo"
65        error=1
66     fi
67 done
68
69 if [ $error -eq 1 ]; then
70     echo "Error: because of earlier errors, we are leaving svn backups in $vroot$tmp instead of $vroot$dest"
71 else
72     if [ -d $vroot$dest -a -d $vroot$tmp ]; then
73         rm -rf $vroot$dest
74     fi
75     if [ -d $vroot$tmp ]; then
76         mv $vroot$tmp $vroot$dest
77     fi
78 fi
79
80 exit 0