1#!/bin/sh 2# 3# Run a simple backup 4# then restore it. 5# 6 7unset LANG 8TestName="lan-addr-test" 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 52cp ${conf}/bareos-dir.conf $tmp/1 53sed -f ${outf} ${cwd}/tmp/1 > ${conf}/bareos-dir.conf 54 55 56# Directory to backup. 57# This directory will be created by setup_data(). 58BackupDirectory="${tmp}/data" 59 60# Use a tgz to setup data to be backuped. 61# Data will be placed at "${tmp}/data/". 62setup_data data/small.tgz 63 64# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list". 65echo "${BackupDirectory}" >${tmp}/file-list 66 67 68start_test 69 70cat <<END_OF_DATA >${cwd}/tmp/bconcmds 71@$out /dev/null 72messages 73@$out ${cwd}/tmp/log1.out 74@#label volume=TestVolume001 storage=File pool=Full 75@#setdebug level=100 storage=File 76run job=$JobName yes 77@#sleep 3 78messages 79quit 80END_OF_DATA 81 82run_bareos 83cat <<END_OF_DATA >${cwd}/tmp/bconcmds 84@$out /dev/null 85messages 86@$out ${cwd}/tmp/log1.out 87label volume=TestVolume001 storage=File pool=Full 88@#setdebug level=100 storage=File 89wait 90messages 91@# 92@# now do a restore 93@# 94@$out ${cwd}/tmp/log2.out 95restore where=${cwd}/tmp/bareos-restores select all done 96yes 97wait 98messages 99quit 100END_OF_DATA 101 102run_bconsole 103check_for_zombie_jobs storage=File 104stop_bareos 105 106print_debug "Detecting connections to SD with source and target ${IP}" 107grep -E "${IP}(.|:)${BAREOS_SD_PORT} .* ${IP}" $tmp/log1.out > $tmp/log3.out 108if [ $? -ne 0 ]; then 109 stat=2 110 print_debug "Couldn't detect a connection to the SD with source and target ${IP}" 111fi 112 113if [ "$stat" = 2 ] ; then 114 netstat -tan 115fi 116 117if [ "$debug" = 1 ] ; then 118 cat $tmp/log3.out 119fi 120 121 122check_two_logs 123check_restore_diff 124 125if [ "$stat" = 2 ]; then 126 print_debug `cat $tmp/log3.out` 127 bstat=$stat 128fi 129 130end_test 131