]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/source-addr-test
regress: add function to create many dirs
[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 outf="tmp/sed_tmp"
42 echo "s/PidDirectory/DirSourceAddress=$IP; PidDirectory/g" > $outf
43 echo "s/Address =/Address = 127.0.0.1 #/g" >> $outf 
44 cp $scripts/bacula-dir.conf $tmp/1
45 sed -f ${outf} ${cwd}/tmp/1 > $scripts/bacula-dir.conf 
46
47 # Set source address on the FD as well
48 echo "s/Pid Directory/FDSourceAddress=$IP; Pid Directory/g" >$outf
49 cp $scripts/bacula-fd.conf $tmp/2
50 sed -f ${outf} ${cwd}/tmp/2 > $scripts/bacula-fd.conf
51
52 DIRPORT=$BASEPORT
53 FDPORT=$(($BASEPORT + 1))
54 SDPORT=$(($BASEPORT + 2))
55
56 change_jobname BackupClient1 $JobName
57 start_test
58
59 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
60 @$out /dev/null
61 messages
62 @$out ${cwd}/tmp/log1.out
63 @#label volume=TestVolume001 storage=File pool=File
64 @#setdebug level=100 storage=File
65 run job=$JobName yes
66 @sleep 3
67 messages
68 quit
69 END_OF_DATA
70
71 run_bacula
72
73 print_debug "Detecting connections to SD sourced from ${IP}"
74 netstat -tan | grep -E "127.0.0.1(.|:)$SDPORT .* ${IP}" > $tmp/log3.out
75 if [ $? -ne 0 ]; then
76    stat=2
77    print_debug "Couldn't detect a connection to the SD sourced from SourceAddress ${IP}" 
78 fi
79
80 print_debug "and connections to FD sourced from ${IP}"
81 netstat -tan | grep -E "127.0.0.1(.|:)$FDPORT .* ${IP}" >> $tmp/log3.out
82 if [ $? -ne 0 ]; then
83    stat=2
84    print_debug "Couldn't detect a connection to the FD sourced from SourceAddress ${IP}"
85 fi
86
87 if [ "$stat" = 2 ] ; then
88    netstat -tan
89 fi
90
91 if [ "$debug" = 1 ] ; then
92     cat $tmp/log3.out
93 fi
94
95 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
96 @$out /dev/null
97 messages
98 @$out ${cwd}/tmp/log1.out
99 label volume=TestVolume001 storage=File pool=File
100 @#setdebug level=100 storage=File
101 wait
102 messages
103 @# 
104 @# now do a restore
105 @#
106 @$out ${cwd}/tmp/log2.out  
107 restore where=${cwd}/tmp/bacula-restores select all done
108 yes
109 wait
110 messages
111 quit
112 END_OF_DATA
113
114 run_bconsole
115 check_for_zombie_jobs storage=File
116 stop_bacula
117 check_two_logs
118 check_restore_diff
119
120 if [ "$stat" = 2 ]; then
121     print_debug `cat $tmp/log3.out`
122     bstat=$stat
123 fi
124
125 end_test