3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # Run a simple backup of the Bacula build directory
9 TestName="source-addr-test"
17 # Zap out any schedule in default conf file so that
18 # it doesn't start during our test
21 echo "s% Schedule =%# Schedule =%g" >${outf}
22 cp $scripts/bacula-dir.conf $tmp/1
23 sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf
25 PATH=$PATH:/sbin:/usr/sbin
27 # Deduce a primary IP address by examining
28 # the interface defined by INTERFACE=
32 if [ $os = 'FreeBSD' ]; then
34 IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'`
35 elif [ $os = 'Linux' ]; then
38 IP=`ifconfig ${INTERFACE} | perl -ne '/inet (addr:)?(.+?) / && print $2'`
41 if [ "$IP" = '' ]; then
42 echo "Can't detect ip address"
47 echo "s/PidDirectory/DirSourceAddress=$IP; PidDirectory/g" > $outf
48 echo "s/Address =/Address = \"127.0.0.1\" #/g" >> $outf
49 cp $scripts/bacula-dir.conf $tmp/1
50 sed -f ${outf} ${cwd}/tmp/1 > $scripts/bacula-dir.conf
52 # Set source address on the FD as well
53 echo "s/Pid Directory/FDSourceAddress=$IP; Pid Directory/g" >$outf
54 cp $scripts/bacula-fd.conf $tmp/2
55 sed -f ${outf} ${cwd}/tmp/2 > $scripts/bacula-fd.conf
58 FDPORT=$(($BASEPORT + 1))
59 SDPORT=$(($BASEPORT + 2))
61 change_jobname BackupClient1 $JobName
64 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
67 @$out ${cwd}/tmp/log1.out
68 @#label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0
69 @#setdebug level=100 storage=File1
70 setbandwidth client limit="1000 kb/s"
80 print_debug "Detecting connections to SD sourced from ${IP}"
81 netstat -tan | grep -E "127\.0\.0\.1(.|:)$SDPORT .* ${IP}" > $tmp/log3.out
84 print_debug "Couldn't detect a connection to the SD sourced from SourceAddress ${IP}"
87 print_debug "and connections to FD sourced from ${IP}"
88 netstat -tan | grep -E "127\.0\.0\.1(.|:)$FDPORT .* ${IP}" >> $tmp/log3.out
91 print_debug "Couldn't detect a connection to the FD sourced from SourceAddress ${IP}"
94 if [ "$stat" = 2 ] ; then
98 if [ "$debug" = 1 ] ; then
102 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
104 setbandwidth client limit="1000000 kb/s"
110 @$out ${cwd}/tmp/log2.out
111 restore where=${cwd}/tmp/bacula-restores select all done
119 check_for_zombie_jobs storage=File1
124 if [ "$stat" = 2 ]; then
125 print_debug `cat $tmp/log3.out`