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