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