]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/source-addr-test
ebl Make sure that vtape directory is created during -tape tests
[bacula/bacula] / regress / tests / source-addr-test
1 #!/bin/sh
2 #
3 # Run a simple backup of the Bacula build directory
4 #   then restore it.
5 #
6 TestName="source-addr-test"
7 JobName=backup
8 . scripts/functions
9
10 scripts/cleanup
11 scripts/copy-confs
12
13 #
14 # Zap out any schedule in default conf file so that
15 #  it doesn't start during our test
16 #
17 outf="tmp/sed_tmp"
18 echo "s%  Schedule =%# Schedule =%g" >${outf}
19 cp $scripts/bacula-dir.conf $tmp/1
20 sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf
21
22 PATH=$PATH:/sbin:/usr/sbin
23 #
24 # Deduce a primary IP address by examining
25 #  the interface defined by INTERFACE=
26 #
27 os=`uname`
28 if [ $os = 'FreeBSD' ]; then
29    INTERFACE=bge0
30    IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'`
31 elif [ $os = 'Linux' ]; then
32    INTERFACE=eth0
33    IP=`ifconfig ${INTERFACE} | perl -ne '/inet addr:(.+?) / && print $1'`
34 fi
35
36 if [ "$IP" = '' ]; then
37     echo "Can't detect ip address"
38     exit 0
39 fi
40
41 print_debug "Detected ip address is $IP"
42
43 outf="tmp/sed_tmp"
44 echo "s/PidDirectory/DirSourceAddress=$IP; PidDirectory/g" > $outf
45 echo "s/Address =/Address = 127.0.0.1 #/g" >> $outf 
46 cp $scripts/bacula-dir.conf $tmp/1
47 sed -f ${outf} ${cwd}/tmp/1 > $scripts/bacula-dir.conf 
48
49 # Set source address on the FD as well
50 echo "s/Pid Directory/FDSourceAddress=$IP; Pid Directory/g" >$outf
51 cp $scripts/bacula-fd.conf $tmp/2
52 sed -f ${outf} ${cwd}/tmp/2 > $scripts/bacula-fd.conf
53
54 DIRPORT=$BASEPORT
55 FDPORT=$(($BASEPORT + 1))
56 SDPORT=$(($BASEPORT + 2))
57
58 change_jobname Client1 $JobName
59 start_test
60
61 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
62 @output /dev/null
63 messages
64 @$out ${cwd}/tmp/log1.out
65 @#label volume=TestVolume001 storage=File pool=Default
66 @#setdebug level=100 storage=File
67 run job=$JobName yes
68 @sleep 3
69 messages
70 quit
71 END_OF_DATA
72
73 run_bacula
74
75 print_debug "Connections to SD sourced from ${IP}:"
76 netstat -tan | grep -E "127.0.0.1(.|:)$SDPORT .* ${IP}" > $tmp/log3.out
77 if [ $? -ne 0 ]; then
78    stat=2
79    print_debug "Couldn't detect a connection to the SD sourced from SourceAddress ${IP}" 
80 fi
81
82 print_debug "Connections to FD sourced from ${IP}:"
83 netstat -tan | grep -E "127.0.0.1(.|:)$FDPORT .* ${IP}" >> $tmp/log3.out
84 if [ $? -ne 0 ]; then
85    stat=2
86    print_debug "Couldn't detect a connection to the FD sourced from SourceAddress ${IP}"
87 fi
88
89
90 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
91 @output /dev/null
92 messages
93 @$out ${cwd}/tmp/log1.out
94 label volume=TestVolume001 storage=File pool=Default
95 @#setdebug level=100 storage=File
96 wait
97 messages
98 @# 
99 @# now do a restore
100 @#
101 @$out ${cwd}/tmp/log2.out  
102 restore where=${cwd}/tmp/bacula-restores select all done
103 yes
104 wait
105 messages
106 @$out
107 quit
108 END_OF_DATA
109
110 run_bconsole
111 check_for_zombie_jobs storage=File
112 stop_bacula
113 check_two_logs
114 check_restore_diff
115
116 if [ "$stat" = 2 ]; then
117     print_debug `cat $tmp/log3.out`
118     bstat=$stat
119 fi
120
121 end_test