]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/source-addr-test
Big backport from Enterprise
[bacula/bacula] / regress / tests / source-addr-test
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # Run a simple backup of the Bacula build directory
7 #   then restore it.
8 #
9 TestName="source-addr-test"
10 JobName=backup
11 . scripts/functions
12
13 scripts/cleanup
14 scripts/copy-confs
15
16 #
17 # Zap out any schedule in default conf file so that
18 #  it doesn't start during our test
19 #
20 outf="tmp/sed_tmp"
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
24
25 PATH=$PATH:/sbin:/usr/sbin
26 #
27 # Deduce a primary IP address by examining
28 #  the interface defined by INTERFACE=
29 #
30 os=`uname`
31 INTERFACE=lo
32 if [ $os = 'FreeBSD' ]; then
33    INTERFACE=bge0
34    IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'`
35 elif [ $os = 'Linux' ]; then
36 #  INTERFACE=eth0
37    INTERFACE=lo
38    IP=`ifconfig ${INTERFACE} | perl -ne '/inet (addr:)?(.+?) / && print $2'`
39 fi
40
41 if [ "$IP" = '' ]; then
42     echo "Can't detect ip address"
43     exit 0
44 fi
45
46 outf="tmp/sed_tmp"
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 
51
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
56
57 DIRPORT=$BASEPORT
58 FDPORT=$(($BASEPORT + 1))
59 SDPORT=$(($BASEPORT + 2))
60
61 change_jobname BackupClient1 $JobName
62 start_test
63
64 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
65 @output /dev/null
66 messages
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"
71 run job=$JobName yes
72 @sleep 3
73 messages
74 quit
75 END_OF_DATA
76
77 run_bacula
78
79 sleep 5
80 print_debug "Detecting connections to SD sourced from ${IP}"
81 netstat -tan | grep -E "127\.0\.0\.1(.|:)$SDPORT .* ${IP}" > $tmp/log3.out
82 if [ $? -ne 0 ]; then
83    stat=2
84    print_debug "Couldn't detect a connection to the SD sourced from SourceAddress ${IP}" 
85 fi
86
87 print_debug "and connections to FD sourced from ${IP}"
88 netstat -tan | grep -E "127\.0\.0\.1(.|:)$FDPORT .* ${IP}" >> $tmp/log3.out
89 if [ $? -ne 0 ]; then
90    stat=2
91    print_debug "Couldn't detect a connection to the FD sourced from SourceAddress ${IP}"
92 fi
93
94 if [ "$stat" = 2 ] ; then
95    netstat -tan
96 fi
97
98 if [ "$debug" = 1 ] ; then
99     cat $tmp/log3.out
100 fi
101
102 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
103 @$out $tmp/log1.out
104 setbandwidth client limit="1000000 kb/s"
105 wait
106 messages
107 @# 
108 @# now do a restore
109 @#
110 @$out ${cwd}/tmp/log2.out  
111 restore where=${cwd}/tmp/bacula-restores select all done
112 yes
113 wait
114 messages
115 quit
116 END_OF_DATA
117
118 run_bconsole
119 check_for_zombie_jobs storage=File1
120 stop_bacula
121 check_two_logs
122 check_restore_diff
123
124 if [ "$stat" = 2 ]; then
125     print_debug `cat $tmp/log3.out`
126     bstat=$stat
127 fi
128
129 end_test