/
functions
969 lines (840 loc) · 21.7 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
#!/bin/sh
#
# A set of useful functions to be sourced in each test
#
copy_configs()
{
COMPONENTS="bareos-dir bareos-sd bareos-fd bconsole tray-monitor"
CONFIGDIRS="BASE ${TestName} $*"
FOUND=""
for component in $COMPONENTS; do
# try to find a config file, store the most specific.
FOUND=""
for directory in $CONFIGDIRS; do
if [ -f "${rconfigs}/${directory}/${component}.conf" ]; then
FOUND="${rconfigs}/${directory}/${component}.conf"
fi
done
if [ "$FOUND" ]; then
/bin/cp "${FOUND}" "${conf}"
else
# copy all config files from subdirectories,
# start with the most generic.
for directory in $CONFIGDIRS; do
if [ -d "${rconfigs}/${directory}/${component}.d" ]; then
/bin/cp -r "${rconfigs}/${directory}/${component}.d" "${conf}"
fi
done
fi
done
# copy certificates
for directory in $CONFIGDIRS; do
if [ -d "${rconfigs}/${directory}/tls/" ]; then
/bin/cp -r "${rconfigs}/${directory}/tls" "${conf}"
fi
done
}
#
# activates a plugin by copying to $plugindirtmp.
# For this, daemons must have following setting:
# Plugin Directory = @plugindirtmp@
#
enable_plugin()
{
RC=0
PLUGIN="$1"
if [ -z "$PLUGIN" ]; then
set_error "enable_plugin: no plugin name given."
exit 1
fi
if ! cp "$plugindir/${PLUGIN}".* "$plugindirtmp/"; then
set_error "enable_plugin: failed to enable ${PLUGIN} plugin."
RC=1
exit 1
fi
print_debug "plugin ${PLUGIN} enabled"
return $RC
}
disable_plugin()
{
RC=0
PLUGIN="$1"
if [ -z "$PLUGIN" ]; then
set_error "enable_plugin: no plugin name given."
exit 1
fi
if ! rm "$plugindirtmp/${PLUGIN}".*; then
set_error "disable_plugin: failed to disable ${PLUGIN} plugin."
RC=1
exit 1
fi
print_debug "plugin ${PLUGIN} disabled"
return $RC
}
check_encoding()
{
if "${BAREOS_DIRECTOR_BINARY}" -d50 -t 2>&1 | grep 'Wanted SQL_ASCII, got UTF8' >/dev/null
then
echo "Found database encoding problem, please modify the database encoding (SQL_ASCII)"
exit 1
fi
}
cleanup()
{
if has_tape_drive; then
"${rscripts}/cleanup-tape"
else
"${rscripts}/cleanup"
fi
}
#
# Creates a directory "${tmp}/data" from a tgz file.
# This directory can be used a data to backup.
# Initialize ${tmp}/file-list with this directory,
# if it does not already exists.
#
setup_data()
{
data_dir="${tmp}/data"
[ -d "$data_dir" ] || mkdir "$data_dir"
for tar in "../../data/small.tgz" "../../data/weird-files.tar.gz"; do
if [ ! -f "$tar" ]; then
set_error "setup_data: $tar not found."
return 1
fi
tar --directory="$data_dir" -xf "$tar" || return 1
done
echo "${data_dir}" >"${tmp}/file-list"
return 0
}
start_test()
{
# in case of an exit during the test,
# call the 'end_test' function.
trap '
EXITCODE=$?;
echo "exit($EXITCODE) is called. Set test to failure and end test.";
estat=998;
end_test;
' EXIT
check_encoding
# Turn off email
outf="${tmp}/sed_tmp"
echo "s% mail =%# mail = %g" >"${outf}"
echo "s% operator =%# operator =%g" >>"${outf}"
if [ -f "${conf}/bareos-dir.conf" ]; then
cp "${conf}/bareos-dir.conf" "${tmp}/1"
sed -f "${outf}" "${tmp}/1" > "${conf}/bareos-dir.conf"
fi
STARTDATE="$(date +%R:%S)"
echo " "
echo " "
echo "=== $TestName: starting at $STARTDATE ==="
echo "=== $TestName: starting at $STARTDATE ===" >> "${working}/log"
echo "="
echo "="
export TestName
export zstat
export estat
estat=0
zstat=0
bstat=0
rstat=0
dstat=0
# marker for cleanup()
echo "$STARTDATE" > "${working}/CLEANUPMARKER"
}
require_root()
{
if [ "$(id -u)" != 0 ] ; then
echo " "
echo "You must be root to run this test."
echo " ===== !!!! $TestName not run at $(date +%R:%S) ==="
echo " ===== !!!! $TestName not run at $(date +%R:%S) !!!! ===== " >>test.out
echo " "
exit 1
fi
}
has_tape_drive()
{
[ "${TAPE_DRIVE}" ] && [ "${TAPE_DRIVE}" != "/dev/null" ]
return $?
}
require_tape_drive()
{
if ! has_tape_drive; then
echo "This test $TestName needs a tape drive, but has none."
exit 1
fi
}
require_second_drive()
{
if [ "${TAPE_DRIVE1}" = "/dev/null" ]; then
echo "This test $TestName has a Job $JobName which needs a second drive, but has none."
exit 1
fi
}
require_autochanger()
{
if [ "${AUTOCHANGER}" = "/dev/null" ]; then
echo "This test $TestName needs an autochanger, but has none."
exit 1
fi
}
require_linux()
{
if [ "$(uname)" != 'Linux' ]; then
echo "This test $TestName runs only on Linux"
exit 1
fi
}
skip_if_no_autochanger()
{
if [ "${AUTOCHANGER}" = "/dev/null" ]; then
echo "$TestName test skipped. No autochanger."
exit 1
fi
}
is_debug()
{
test "$debug" -gt 0
return $?
}
set_debug()
{
debug=$1
if is_debug; then
out=tee
else
out=output
fi
}
print_debug()
{
echo "$*" | grep -q ERROR > /dev/null
if test $? -eq 0; then
echo "$*" >> "$tmp/err.log"
fi
if is_debug; then
echo "$*" >&2
fi
}
write_stdin_to_file()
{
FILE="$1"
# empty file
>"${FILE}"
# read stdin and write to file
while read -r input; do
printf '%s\n' "$input" >>"${FILE}"
done
}
log_stdin()
{
FILE="${1:-${tmp}/debug.log}"
# read stdin and write to file
while read -r input; do
# print if debug is set
print_debug "$input"
# write to log file
printf '%s\n' "$input" >>"${FILE}"
done
}
set_error()
{
estat=9
echo "ERROR: $*" >> "$tmp/err.log"
echo "ERROR: $*"
}
check_files_written()
{
LOG=$1
NB=$2
FILES="$(awk '/FD Files Written:/ { last=$4 } END { print last }' "$LOG")"
if [ "$NB" != "$FILES" ]; then
print_debug "ERROR: Expect $NB files, get $FILES"
bstat=2
fi
}
check_linked_against()
{
LIB="$1"
BIN=${2:-${BAREOS_FILEDAEMON_BINARY}}
#
# See if library is linked against libfastlz
#
cnt="$(ldd "${BIN}" 2>/dev/null | grep -c "${LIB}")"
if [ "${cnt}" -lt 1 ]; then
print_debug "ERROR: ${BIN} not linked against ${LIB}."
return 1
fi
return 0
}
bls_files_verbose()
{
local STORAGE=${1}
local VOLUME=${2}
# JobId is not yet evaluated
#local JOBID=${3}
#local FILENAME=${4}
"${BAREOS_BLS_BINARY}" -V "${VOLUME}" -c "${conf}" -v "${STORAGE}"
return $?
}
check_compression()
{
local STORAGE=${1}
local VOLUME=${2}
# JobId is not yet evaluated
local JOBID=${3}
local FILENAME=${4}
local COMPRESSION=${5:-'GZIP'}
local COMPRESSION_LEVEL="$6"
local COMPRESSION_DESCRIPTION="${COMPRESSION}"
if [ "${COMPRESSION_LEVEL}" ]; then
COMPRESSION_DESCRIPTION="${COMPRESSION}, level=${COMPRESSION_LEVEL}"
fi
print_debug "Is ${FILENAME} compressed with ${COMPRESSION_DESCRIPTION} ?"
if OUT=$(bls_files_verbose "${STORAGE}" "${VOLUME}" | grep -A1 "| ${FILENAME}$" | grep -i "| ${COMPRESSION_DESCRIPTION}, "); then
print_debug "$OUT"
else
set_error "Use of compression algorithm ${COMPRESSION_DESCRIPTION} in job=${JOBID}, file=${FILENAME} not detected."
fi
}
################################################################
# Get information from logs
get_mig_info()
{
# Prev Backup JobId
JOBID=$1
LOG=$2
RET="$(awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' "$LOG")"
}
get_duration()
{
LOG=$1
RET="$(awk 'BEGIN {t["secs"]=1;t["sec"]=1;t["min"]=60;t["mins"]=60}; /Elapsed time:/ { last=$3*t[$4] } END { print last }' "$LOG")"
}
check_duration_gt()
{
LOG="$1"
TIME="$2"
get_duration "$LOG"
if [ "$RET" -gt "$TIME" ]; then
print_debug "Expect greater than $TIME sec, get $RET"
bstat=2
fi
}
check_duration_lt()
{
LOG="$1"
TIME="$2"
get_duration "$LOG"
if [ "$RET" -lt "$TIME" ]; then
print_debug "Expect less than $TIME sec, get $RET"
bstat=2
fi
}
start_bareos()
{
debug_wait
zstat=0
estat=0
if test "$debug" -eq 1 ; then
"${rscripts}/bareos-ctl-dir" start -m -d 100
"${rscripts}/bareos-ctl-sd" start -m -d 100
"${rscripts}/bareos-ctl-fd" start -m "$1" -d 100
else
"${rscripts}/bareos" start >/dev/null 2>&1
fi
# check daemons
DAEMON_STATUS_OUT="$("${rscripts}/bareos" status)"
DAEMON_STATUS=$?
print_debug "$DAEMON_STATUS_OUT"
if [ $DAEMON_STATUS -ne 0 ]; then
exit 1
fi
}
run_bareos()
{
start_bareos "$@"
run_bconsole
return $?
}
run_bconsole()
{
bconsole_file="${1:-${tmp}/bconcmds}"
if [ -f "$bconsole_file" ]; then
if test "$debug" -eq 1 ; then
"${BAREOS_BCONSOLE_BINARY}" -c "${conf}" < "$bconsole_file"
else
"${BAREOS_BCONSOLE_BINARY}" -c "${conf}" < "$bconsole_file" 2>&1 >/dev/null
fi
fi
return $?
}
run_btape()
{
if test "$debug" -eq 1 ; then
"${bin}/btape" -c "${conf}" tape < "${tmp}/bconcmds" | tee "${tmp}/log1.out"
else
"${bin}/btape" -c "${conf}" tape < "${tmp}/bconcmds" >"${tmp}/log1.out" 2>&1
fi
}
run_bscan()
{
print_debug "bscanning with ${BAREOS_BSCAN_BINARY}"
if test "$debug" -eq 1 ; then
"${BAREOS_BSCAN_BINARY}" -B "$DBTYPE" -a "$backenddir" -c "${conf}" "$@" </dev/null | tee "${tmp}/bscan.out"
else
"${BAREOS_BSCAN_BINARY}" -B "$DBTYPE" -a "$backenddir" -c "${conf}" "$@" </dev/null 2>&1 >"${tmp}/bscan.out"
fi
}
run_bscan_db()
{
run_bscan -n "$db_name" -u "$db_user" -P "$db_password" "$@"
}
stop_bareos()
{
if test "$debug" -eq 1 ; then
"${rscripts}/bareos" stop
else
"${rscripts}/bareos" stop >/dev/null 2>&1
fi
}
run_python_unittests()
{
PYTHON_UNITTEST_SCRIPT=${1:-python-bareos-unittest.py}
if [ "${PROJECT_SOURCE_DIR}" ] && [ -e "${PROJECT_SOURCE_DIR}/../python-bareos/" ]; then
if [ "$PYTHONPATH" ]; then
export PYTHONPATH=${PROJECT_SOURCE_DIR}/../python-bareos/:$PYTHONPATH
else
export PYTHONPATH=${PROJECT_SOURCE_DIR}/../python-bareos/
fi
print_debug "PYTHONPATH=$PYTHONPATH"
if PYTHONRESULT=$("${cwd}/${PYTHON_UNITTEST_SCRIPT}" -v); then
print_debug "$PYTHONRESULT"
else
set_error "$PYTHONRESULT"
fi
fi
}
change_files()
{
#
# Use this function to modified some files after a full backup
# so that an incremental backup will see some modified files.
#
# Don't rely on specific filenames and paths,
# as these might change in the future.
#
DIR=${1:-${BackupDirectory-}}
if [ -z "$DIR" ]; then
print_debug "ERROR: change_files: no directory given."
return 1
fi
if [ ! -d "$DIR" ]; then
print_debug "ERROR: change_files($DIR): this is not a directory."
return 1
fi
for i in $(seq 1 9); do
mkdir -p "${DIR}/test$i"
echo "testdata" >> "${DIR}/test$i/test$i.txt"
done
return 0
}
get_file_size()
{
FILE="$1"
SIZE=-1
if [ -e "$FILE" ]; then
SIZE="$(du "$FILE" | cut -f 1)"
fi
print_debug "$FILE: $SIZE bytes"
echo "$SIZE"
}
check_for_zombie_jobs()
{
"${rscripts}/check_for_zombie_jobs" "$@"
}
change_jobname()
{
if test $# -eq 1; then
oldname=NightlySave
newname=$1
else
oldname=$1
newname=$2
fi
rm -f "$tmp/1" "$tmp/2"
mv "${conf}/bareos-dir.conf" "$tmp/1"
echo "s%${oldname}%${newname}%g" >"$tmp/2"
sed -f "$tmp/2" "$tmp/1" >"$conf/bareos-dir.conf"
# echo "Job ${oldname} changed to ${newname}"
}
check_two_logs()
{
grep "^ Termination: *Backup OK" "${tmp}/log1.out" >/dev/null 2>&1
bstat=${bstat:-$?}
grep "^ Termination: .*Backup Error" "${tmp}/log1.out" >/dev/null 2>&1
if test $? -eq 0; then
bstat=2
fi
grep "^ Termination: *Restore OK" "${tmp}/log2.out" >/dev/null 2>&1
rstat=${rstat:-$?}
grep "^ Termination: .*Restore Error" "${tmp}/log2.out" >/dev/null 2>&1
if test $? -eq 0; then
rstat=2
fi
grep "^ Termination: *Restore OK -- warning file count mismatch" "${tmp}/log2.out" >/dev/null 2>&1
if test $? -eq 0; then
rstat=3
fi
grep "^ Termination: .*Verify Differences" "${tmp}/log2.out" >/dev/null 2>&1
if test $? -eq 0; then
rstat=4
fi
grep "Encoding error for database" "${tmp}/log1.out" > /dev/null
if test $? -eq 0; then
print_debug "Found database encoding error"
bstat=2
fi
}
check_log()
{
LOG=$1
if [ -z "$LOG" ]; then
LOG="${tmp}/log1.out"
fi
if ! [ -e "$LOG" ]; then
set_error "log file $LOG does not exist."
return 1
fi
if grep \
-e "^ Termination: .*Backup Error" \
-e "^Can't find " \
-e "Encoding error for database" \
-e "^Could not find Client" \
-e "ERR=" \
"$LOG"
then
bstat=1
fi
if grep \
-e "^ Termination: .*Restore Error" \
-e "^ Termination: *Restore OK -- warning " \
-e "^ Termination: .*Verify Differences" \
"$LOG"
then
rstat=1
fi
if [ $bstat -ne 0 ] || [ $rstat -ne 0 ] ; then
return 1
fi
return 0
}
check_restore_diff()
{
# $dest will be set to
# * the first function parameter, or
# * ${BackupDirectory} (set by test), or
# * ${src}
dest=${1:-${BackupDirectory:-$src}}
"$rscripts/diff.pl" -s "${dest}" -d "${tmp}/bareos-restores/${dest}"
result=$?
OUT="$(diff -ur "${dest}" "${tmp}/bareos-restores/${dest}")"
result="$(($result + $?))"
if is_debug; then
printf "%s\n" "$OUT"
fi
if [ "$result" -ne 0 ] && [ "${dstat:-0}" -eq 0 ]; then
dstat="$result"
fi
return "$result"
}
check_restore_only_files_diff()
{
#
# all parameter have to be full path files.
# They will be check for differences to the restore location.
#
differences=0
for i in "$@"; do
if ! diff -ur "$i" "${tmp}/bareos-restores/$i"; then
differences="$(( differences + 1 ))"
dstat=1
fi
done
test "$differences" -eq 0
return $?
}
check_restore_files_diff()
{
if ! check_restore_only_files_diff "$@"; then
return $?
fi
#
# check if only the files given as parameters have been restored
#
# get list of all restored files
RESTORED_FILES="$(find "${tmp}/bareos-restores" -type f | sed "s%^${tmp}/bareos-restores%%")"
# remove all files given as parameter from the list
for i in "$@"; do
RESTORED_FILES="$(printf "%s" "$RESTORED_FILES" | grep -v "$i")"
done
if [ "$RESTORED_FILES" ]; then
print_debug "given files: $*"
print_debug "additional restored files: $RESTORED_FILES"
set_error "More files then given as parameter have been restored."
return 1
fi
return 0
}
check_restore_bin_diff()
{
if test "$debug" -eq 1 ; then
"$rscripts/diff.pl" -s "${bin}" -d "${tmp}/bareos-restores${bin}"
diff -ur "${bin}" "${tmp}/bareos-restores${bin}"
else
diff -ur "${bin}" "${tmp}/bareos-restores${bin}" >/dev/null 2>&1
fi
dstat=$?
}
check_restore_tmp_build_diff()
{
if test "$debug" -eq 1 ; then
"$rscripts/diff.pl" -s "${tmpsrc}" -d "${tmp}/bareos-restores${tmpsrc}"
diff -ur "${tmpsrc}" "${tmp}/bareos-restores${tmpsrc}"
else
diff -ur "${tmpsrc}" "${tmp}/bareos-restores${tmpsrc}" >/dev/null 2>&1
fi
dstat=$?
}
# bstat is backup error
# dstat is diff difference
# estat is special error status (shown by print_debug message)
# rstat is restore status
# zstat is zombie job(s)
#
end_test()
{
# End of test.
# Remove exit trap (set in start_test)
trap '' EXIT
if [ "$notracedump" != "yes" ]; then
cat "${working}"/bareos.*.traceback 2>/dev/null
cp -f "${working}"/bareos.*.traceback "${dumps}" 2>/dev/null
cat "${working}"/*.bactrace 2>/dev/null
cp -f "${working}"/*.bactrace "${dumps}" 2>/dev/null
fi
if [ -f "$tmp/err.log" ]; then
cat "$tmp/err.log"
fi
ENDDATE="$(date +%R:%S)"
if [ "$estat" != "0" ] ; then
echo " "
echo " !!!!! $TestName failed!!! $ENDDATE !!!!! "
echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
echo " !!!!! $TestName failed!!! $ENDDATE !!!!! " >>test.out
echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
echo " "
exit 1
fi
if [ "$zstat" != "0" ] ; then
echo " "
echo " !!!!! $TestName failed!!! $ENDDATE !!!!! "
echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
echo " !!!!! $TestName failed!!! $ENDDATE !!!!! " >>test.out
echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
echo " "
exit 1
fi
if [ "$dstat" != "0" ] || [ "$bstat" != "0" ] || [ "$rstat" != "0" ] ; then
echo " "
echo " "
echo " !!!!! $TestName failed!!! $ENDDATE !!!!! "
echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
echo " !!!!! $TestName failed!!! $ENDDATE !!!!! " >>test.out
echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
if [ $bstat -ne 0 ] || [ $rstat -ne 0 ] ; then
echo " !!!!! Bad termination status !!!!! "
echo " !!!!! Bad termination status !!!!! " >>test.out
else
echo " !!!!! Restored files differ !!!!! "
echo " !!!!! Restored files differ !!!!! " >>test.out
fi
echo " Status: backup=$bstat restore=$rstat diff=$dstat"
echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
echo " "
exit 1
else
echo "="
echo "="
echo "=== $TestName: OK at $ENDDATE === "
echo "=== $TestName: OK at $ENDDATE === " >>test.out
#if ! is_debug; then
# ${rscripts}/cleanup
#fi
fi
}
copy_tape_confs()
{
"${rscripts}/cleanup-tape"
"${rscripts}/copy-tape-confs"
}
copy_test_confs()
{
"${rscripts}/cleanup"
"${rscripts}/copy-test-confs"
}
disable_plugins()
{
for i in ${conf}/bareos-fd.conf; do
sed 's/Plugin/#Plugin/' "$i" > "$tmp/1"
cp -f "$tmp/1" "$i"
done
}
update_win32()
{
if [ -d "$cwd/build/src/win32/release32" ] \
&& [ -d "$cwd/build/src/win32/release64" ] \
|| [ -d "$cwd/release32" ] && [ -d "$cwd/release64" ]
then
echo -ne "Try to upgrade the FileDaemon:\t"
wget -qO - "$WIN32_ADDR:8091/install"
fi
}
debug_wait()
{
if test "${REGRESS_WAIT}" = "1"; then
echo "Start Bareos under debugger and enter anything when ready ..."
read -r
fi
}
init_drive()
{
mt -f "$1" rewind
mt -f "$1" weof
}
rewind_drive()
{
mt -f "$1" rewind
}
load_slot1()
{
# Get a tape from slot1
slot="$("${scripts}/$MTX" "${AUTOCHANGER}" loaded 0 "${TAPE_DRIVE}" "$DRIVE1")"
case $slot in
0)
"${scripts}/$MTX" "${AUTOCHANGER}" load "$SLOT1" "${TAPE_DRIVE}" "$DRIVE1"
slot="$SLOT1"
;;
"$SLOT1")
slot="$SLOT1"
;;
*)
rewind_drive "${TAPE_DRIVE}"
"${scripts}/$MTX" "${AUTOCHANGER}" unload "$slot" "${TAPE_DRIVE}" "$DRIVE1"
"${scripts}/$MTX" "${AUTOCHANGER}" load "$SLOT1" "${TAPE_DRIVE}" "$DRIVE1"
slot="$SLOT1"
;;
esac
}
#
# $1 has currently loaded slot, load the other one i.e. if 1, load 2;
# if 2, load 1; if 0 load 1
#
load_other_slot()
{
rewind_drive "${TAPE_DRIVE}"
case $1 in
0)
"${scripts}/${AUTOCHANGER_SCRIPT}" "${AUTOCHANGER}" load "$SLOT1" "${TAPE_DRIVE}" "$DRIVE1"
slot=1
;;
$SLOT1)
"${scripts}/${AUTOCHANGER_SCRIPT}" "${AUTOCHANGER}" unload "$1" "${TAPE_DRIVE}" "$DRIVE1"
"${scripts}/${AUTOCHANGER_SCRIPT}" "${AUTOCHANGER}" load "$SLOT2" "${TAPE_DRIVE}" "$DRIVE1"
slot=2
;;
$SLOT2)
"${scripts}/${AUTOCHANGER_SCRIPT}" "${AUTOCHANGER}" unload "$1" "${TAPE_DRIVE}" "$DRIVE1"
"${scripts}/${AUTOCHANGER_SCRIPT}" "${AUTOCHANGER}" load "$SLOT1" "${TAPE_DRIVE}" "$DRIVE1"
slot=1
;;
*)
echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
exit 1
;;
esac
}
if test "x${REGRESS_DEBUG}" = "x1"; then
set_debug 1
else
set_debug 0
fi
# Save current directory
cwd="$(pwd)"
# Source the configuration variables
# shellcheck source=../environment.in
. "${cwd}/environment"
db_name="${db_name:-"regress"}"
db_user="${db_user:-"regress"}"
db_password="${db_password:-""}"
working="${working:-"$cwd/working"}"
dumps="${dumps:-"$cwd/dumps"}"
bin="${bin:-"$cwd/bin"}"
tmp="${tmp:-"$cwd/tmp"}"
# Bareos scripts
scripts="${scripts:-"$cwd/bin"}"
# Bareos Plugin Directory
plugindir="${plugindir:-"$cwd/bin/plugins"}"
# some tests (BASE) load only the plugins copied to plugindirtmp,
# to avoid that all plugins get loaded.
plugindirtmp="${plugindirtmp:-"$working/plugins"}"
# Bareos conf files
conf=${conf:-"$cwd/bin"}
confdir="$conf"
configs="$conf"
BAREOS_CONFIG_DIR="$conf"
# Regress scripts
rscripts=${rscripts:-"$cwd/scripts"}
# Regress configs
rconfigs=${rconfigs:-"$cwd/configs"}
# Bareos source directory when copied here
# also build directory
src=${src:-"$cwd/build"}
# Temp source directory so we don't mess up $src
tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
export BAREOS_CONFIG_DIR
export bin
export conf
export confdir
export configs
export dumps
export plugindir
export plugindirtmp
export rscripts
export scripts
export src
export tmp
export tmpsrc
export working
export dirport="$BASEPORT"
export fdport="$((BASEPORT + 1))"
export sdport="$((BASEPORT + 2))"
export BAREOS_DIR_PORT=$dirport
export BAREOS_FD_PORT=$fdport
export BAREOS_SD_PORT=$sdport
export PERLLIB="$cwd"
export PERL5LIB="$cwd"
bperl="perl -Mscripts::functions"
export bperl
mkdir -p "${working}"
mkdir -p "${tmp}"
mkdir -p "${plugindirtmp}"
touch "${tmp}/dir.out" "${tmp}/fd.out" "${tmp}/sd.out"
CLIENT="${HOST}-fd"
AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
trap "{ estat=999; end_test; }" TERM