]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
Check for file count mismatch
[bacula/bacula] / regress / scripts / functions
1 #
2 # A set of useful functions to be sourced in each test
3 #
4
5 start_test()
6 {
7    echo " "
8    echo " "
9    echo " === Starting $TestName at `date +%R:%S` ==="
10    echo " === Starting $TestName at `date +%R:%S` ===" >>working/log
11    echo " "
12 }
13
14 require_root()
15 {
16 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
17 if [ $MUID != 0 ] ; then
18    echo " "
19    echo "You must be root to run this test."
20    echo "  ===== !!!! $TestName not run at `date +%R:%S` ==="
21    echo "  ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
22    echo " "
23    exit 1
24 fi
25 }
26
27
28 set_debug()
29 {
30    debug=$1
31    if test "$debug" -eq 1 ; then
32      out="tee"
33    else
34      out="output"
35    fi
36
37
38 run_bacula()
39 {
40    debug_wait
41    if test "$debug" -eq 1 ; then
42      bin/bacula-ctl-sd start
43      bin/bacula-ctl-fd start
44      bin/bacula-ctl-dir start
45      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
46    else
47      bin/bacula start 2>&1 >/dev/null
48      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
49    fi
50 }
51
52 run_bconsole()
53 {
54    if test "$debug" -eq 1 ; then
55      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
56    else
57      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
58    fi
59 }
60
61 run_btape()
62 {
63    if test "$debug" -eq 1 ; then
64      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
65    else
66      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
67    fi
68 }
69
70 run_bscan()
71 {
72    if test "$debug" -eq 1 ; then
73       bin/bscan $* | tee tmp/log.out
74    else
75       bin/bscan $* 2>&1 >/dev/null
76    fi
77 }
78
79
80 stop_bacula()
81 {
82    bin/bacula stop 2>&1 >/dev/null
83 }
84
85 check_for_zombie_jobs()
86 {
87    scripts/check_for_zombie_jobs $*
88 }
89
90 change_jobname()
91 {
92    if test $# -eq 1; then
93       oldname=NightlySave
94       newname=$1
95    else
96       oldname=$1
97       newname=$2
98    fi
99    rm -f bin/1
100    mv bin/bacula-dir.conf bin/1
101    echo "s%${oldname}%${newname}%g" >tmp/1
102    sed -f tmp/1 bin/1 >bin/bacula-dir.conf
103 #  echo "Job ${oldname} changed to ${newname}"
104 }
105
106 check_two_logs()
107 {
108    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
109    bstat=$?
110    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
111    rstat=$?
112    grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
113    if test $? -eq 0; then
114       rstat = 2
115    fi
116 }
117
118 check_restore_diff()
119 {
120    diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
121    dstat=$?
122 }
123
124 check_restore_tmp_build_diff()
125 {
126    diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
127    dstat=$?
128 }
129
130 end_test()
131 {
132    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
133       echo " "
134       echo " "
135       echo "  !!!!! $TestName failed!!! !!!!! "
136       echo "  !!!!! $TestName failed!!! !!!!! " >>test.out
137       if [ $bstat != 0 -o $rstat != 0 ] ; then
138          echo "  !!!!! Bad Job termination status     !!!!! "
139          echo "  !!!!! Bad Job termination status     !!!!! " >>test.out
140          echo "        bstat=$bstat rstat=$rstat dstat=$dstat"
141       else
142          echo "  !!!!! Restored files differ          !!!!! "
143          echo "  !!!!! Restored files differ          !!!!! " >>test.out
144          echo "        bstat=$bstat rstat=$rstat dstat=$dstat"
145       fi
146       echo " "
147    else
148       echo "  ===== $TestName OK `date +%R:%S` ===== "
149       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
150       if test "$debug" -eq 0 ; then
151          scripts/cleanup
152       fi
153    fi
154 }
155
156 copy_tape_confs()
157 {
158    scripts/copy-tape-confs
159    scripts/cleanup-tape
160 }
161
162 copy_test_confs()
163 {
164    scripts/copy-test-confs
165    scripts/cleanup
166 }
167
168 debug_wait()
169 {
170   if test "x${REGRESS_WAIT}" = "x1"; then
171      echo "Start Bacula under debugger and enter anything when ready ..."
172      read a
173   fi
174 }
175
176 # Save current directory
177 cwd=`pwd`
178 if test "x${REGRESS_DEBUG}" = "x1"; then
179    set_debug 1
180 else
181    set_debug 0
182 fi
183
184 # Source the configuration variables
185 . ${cwd}/config