1#!/bin/sh
2#
3# Run a simple backup
4#   then restore it.
5#
6
7unset LANG
8TestName="lan-addr-test-passive"
9JobName=backup
10. scripts/functions
11
12scripts/cleanup
13scripts/copy-confs
14
15#
16# Zap out any schedule in default conf file so that
17#  it doesn't start during our test
18#
19outf="tmp/sed_tmp"
20echo "s%  Schedule =%# Schedule =%g" >${outf}
21echo "s%Name = \"BackupClient1FileList\"%Name = \"backup\";  client run after job = \"netstat -tan\"%g" >>${outf}
22cp ${conf}/bareos-dir.conf $tmp/1
23sed -f ${outf} $tmp/1 >${conf}/bareos-dir.conf
24
25PATH=$PATH:/sbin:/usr/sbin
26#
27# Deduce a primary IP address by examining
28#  the interface defined by INTERFACE=
29#
30os=`uname`
31if [ $os = 'FreeBSD' ]; then
32   INTERFACE=bge0
33   IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'`
34elif [ $os = 'Linux' ]; then
35   INTERFACE=eth0
36   IP=`ifconfig ${INTERFACE} | perl -ne '/inet addr:(.+?) / && print $1'`
37fi
38
39if [ "$IP" = '' ]; then
40    # ifconfig output may be like this (RHEL/CentOS 7, Fedora, ...?)
41    # eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
42    #    inet 192.168.121.195  netmask 255.255.255.0  broadcast 192.168.121.255
43    IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'`
44    if [ "$IP" = '' ]; then
45        echo "Can't detect ip address"
46        exit 0
47    fi
48fi
49
50outf="tmp/sed_tmp"
51echo "s/Address =/Address = 127.0.0.1; LAN Address = $IP #/g" > $outf
52echo 's/Client {/Client {; Passive=yes/g' >> $outf
53cp ${conf}/bareos-dir.conf $tmp/1
54sed -f ${outf} ${cwd}/tmp/1 > ${conf}/bareos-dir.conf
55
56
57# Directory to backup.
58# This directory will be created by setup_data().
59BackupDirectory="${tmp}/data"
60
61# Use a tgz to setup data to be backuped.
62# Data will be placed at "${tmp}/data/".
63setup_data data/small.tgz
64
65# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
66echo "${BackupDirectory}" >${tmp}/file-list
67
68
69start_test
70
71cat <<END_OF_DATA >${cwd}/tmp/bconcmds
72@$out /dev/null
73messages
74@$out ${cwd}/tmp/log1.out
75@#label volume=TestVolume001 storage=File pool=Full
76@#setdebug level=100 storage=File
77run job=$JobName yes
78@#sleep 3
79messages
80quit
81END_OF_DATA
82
83run_bareos
84cat <<END_OF_DATA >${cwd}/tmp/bconcmds
85@$out /dev/null
86messages
87@$out ${cwd}/tmp/log1.out
88label volume=TestVolume001 storage=File pool=Full
89@#setdebug level=100 storage=File
90wait
91messages
92@#
93@# now do a restore
94@#
95@$out ${cwd}/tmp/log2.out
96restore where=${cwd}/tmp/bareos-restores select all done
97yes
98wait
99messages
100quit
101END_OF_DATA
102
103run_bconsole
104check_for_zombie_jobs storage=File
105stop_bareos
106
107
108print_debug "and connections to FD with source and target ${IP}"
109grep -E "${IP}(.|:)${BAREOS_FD_PORT} .* ${IP}"  $tmp/log1.out >> $tmp/log3.out
110if [ $? -ne 0 ]; then
111   stat=2
112   print_debug "Couldn't detect a connection to the FD with source and target ${IP}"
113fi
114
115if [ "$stat" = 2 ] ; then
116   netstat -tan
117fi
118
119if [ "$debug" = 1 ] ; then
120    cat $tmp/log3.out
121fi
122
123
124check_two_logs
125check_restore_diff
126
127if [ "$stat" = 2 ]; then
128    print_debug `cat $tmp/log3.out`
129    bstat=$stat
130fi
131
132end_test
133