]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/restore-stop-read-test
baculum: Add strip_prefix, add_prefix, add_suffix and regex_where restore options...
[bacula/bacula] / regress / tests / restore-stop-read-test
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # Run a simple backup of the Bacula build directory
7 #   then restore one file and see if we read too much
8 #   data
9 #
10 # With AWK, we get the 1st executable file from the volume we get the also a
11 # "position" of the file in the volume with NR (line number).
12 #
13 # With grep "FI=nn SessId=", we search in the trace file up to which FI we read the data.
14 #
15 # For example, if we find build/libtool NR=6, the trace file should have all
16 # FileIndex<6 (probably between 3 and 5) If we find a FI=6 in the trace file,
17 # it means that we read too much data
18
19 TestName="restore-stop-read-test"
20 JobName=backup
21 . scripts/functions
22
23 scripts/cleanup
24 scripts/copy-confs
25
26 #
27 # Zap out any schedule in default conf file so that
28 #  it doesn't start during our test
29 #
30 outf="$tmp/sed_tmp"
31 echo "s%  Schedule =%# Schedule =%g" >${outf}
32 cp $scripts/bacula-dir.conf $tmp/1
33 sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf
34
35 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'MaximumFileSize', '10MB', 'Device')"
36 director=`$bperl -e "get_dirname()"`
37
38 change_jobname BackupClient1 $JobName
39 start_test
40
41 cat <<END_OF_DATA >$tmp/bconcmds
42 @$out /dev/null
43 messages
44 @$out $tmp/log1.out
45 label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0
46 run job=$JobName yes
47 wait
48 messages
49 END_OF_DATA
50
51 run_bacula
52 stop_bacula
53
54 $bin/bls -V TestVolume001 FileChgr1-Dev1 > $tmp/list
55
56 f=`awk '/-rwxr-xr-x/ { print $11; exit }' $tmp/list`
57
58 # The "line" in the bls is between 3-n, the fileindex (one by line)
59 # is between 1-n. So we search for FI=line, like FI=fileindex+3
60 line=`awk '/-rwxr-xr-x/ { print NR; exit }' $tmp/list`
61
62 if [ "x$f" = x ]; then
63     print_debug "ERROR: Unable to find a file in the backup list"
64     exit 1
65 fi
66
67 p=`dirname $f`
68 f=`basename $f`
69
70 cat <<END_OF_DATA >$tmp/bconcmds
71 @$out $tmp/log2.out  
72 @# 
73 @# now do a restore
74 @#
75 setdebug level=500 trace=1 storage=File1
76 restore where=$tmp/bacula-restores
77 5
78 cd "$p"
79 mark "$f"
80 done
81 @sleep 2
82 @exec "cp $working/$director.restore.1.bsr $working/restore1.bsr"
83 yes
84 wait
85 messages
86 setdebug level=0 trace=0 storage=File1
87 quit
88 END_OF_DATA
89
90 run_bacula
91
92 print_debug "Looking for FI=$line in the SD working/*trace file"
93 # We have more or less one FI per line
94 grep "FI=$line SessId=" working/*trace > /dev/null
95 if [ $? -eq 0 ]; then
96     print_debug "ERROR: Should not find references to FileIndex $line in trace, should stop before"
97     estat=1
98 fi
99
100 # The "line" in the bls is between 3-n, the fileindex (one by line)
101 # is between 1-n. So we search for FI=line, like FI=fileindex+3
102 f=`awk '/-rwxr-xr-x/ { if (count++ == 10) { print $11; exit} }' $tmp/list`
103 line=`awk '/-rwxr-xr-x/ { if(count++ == 10) {print NR; exit}}' $tmp/list`
104
105 if [ "x$f" = x ]; then
106     print_debug "ERROR: Unable to find a file=$file in the backup list"
107     exit 1
108 fi
109
110 p=`dirname $f`
111 f=`basename $f`
112
113 cat <<END_OF_DATA >$tmp/bconcmds
114 @$out $tmp/log2.out  
115 @# 
116 @# now do a restore
117 @#
118 setdebug level=500 trace=1 storage=File1
119 restore where=$tmp/bacula-restores
120 5
121 cd "$p"
122 mark "$f"
123 done
124 yes
125 wait
126 messages
127 setdebug level=0 trace=0 storage=File1
128 quit
129 END_OF_DATA
130
131 run_bconsole
132
133 # We have more or less one FI per line
134 print_debug "Looking for file=$f FI=$line in the SD trace file"
135 grep "FI=$line SessId=" working/*trace > /dev/null
136 if [ $? -eq 0 ]; then
137     print_debug "ERROR: Should not find references to FileIndex $line in trace, should stop before"
138     estat=1
139 fi
140
141 check_for_zombie_jobs storage=File1
142 stop_bacula
143
144 check_two_logs
145 end_test