]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/bvfs-test
Backport from BEE
[bacula/bacula] / regress / tests / bvfs-test
1 #!/bin/sh
2 #
3 # Run a simple backup of the Bacula build directory then create some           
4 #   new files, do an Incremental and restore those two files.
5 # test the bvfs interface
6 #
7 TestName="bvfs-test"
8 JobName=Incremental 
9 . scripts/functions
10
11 ${rscripts}/cleanup
12 ${rscripts}/copy-test-confs
13 echo "${tmpsrc}" >${tmp}/file-list
14 echo "${cwd}/build" >> ${tmp}/file-list
15
16 mkdir -p ${tmpsrc}
17 cp -p ${src}/src/dird/*.c ${tmpsrc}
18 cd ${tmp}
19 echo "${tmpsrc}/ficheriro1.txt" >restore-list
20 echo "${tmpsrc}/ficheriro2.txt" >>restore-list
21 cd ${cwd}
22
23 change_jobname CompressedTest $JobName
24 start_test
25
26 cat <<END_OF_DATA >${tmp}/bconcmds
27 @$out /dev/null
28 messages
29 @$out ${tmp}/log1.out
30 label storage=File volume=TestVolume001
31 label storage=File volume=TestVolume002
32 run job=$JobName yes
33 wait
34 messages
35 quit
36 END_OF_DATA
37
38 run_bacula
39 check_for_zombie_jobs storage=File
40 #
41 # Now create two new files to be restored later
42 #
43 sleep 1
44 echo "ficheriro1.txt" >${tmpsrc}/ficheriro1.txt
45 cp -f ${tmpsrc}/dird.c ${tmpsrc}/ficheriro2.txt
46
47 cat <<END_OF_DATA >${tmp}/bconcmds
48 @$out /dev/null
49 messages
50 @$out ${tmp}/log1.out
51 @# Force Incremental on the second Volume
52 update volume=TestVolume001 VolStatus=Used
53 run level=Differential job=$JobName yes
54 wait
55 messages
56 quit
57 END_OF_DATA
58
59 run_bconsole
60
61 sleep 1
62 touch ${tmpsrc}/ficheriro1.txt
63 touch ${tmpsrc}/ficheriro2.txt
64
65 cat <<END_OF_DATA >${tmp}/bconcmds
66 @$out /dev/null
67 messages
68 @$out ${tmp}/log1.out
69 run level=Incremental job=$JobName yes
70 wait
71 messages
72 quit
73 END_OF_DATA
74
75 run_bconsole
76
77 sleep 1
78 cd ${tmpsrc}
79 cp -f ficheriro2.txt 1
80 sed "s%a%b%g" 1 >ficheriro2.txt
81 rm -f 1
82 cd ${cwd}
83 cat <<END_OF_DATA >${tmp}/bconcmds
84 @$out /dev/null
85 messages
86 @$out ${tmp}/log1.out
87 run level=Differential job=$JobName yes
88 wait
89 messages
90 quit
91 END_OF_DATA
92
93 run_bconsole
94
95 sleep 1
96 touch ${tmpsrc}/ficheriro1.txt
97 touch ${tmpsrc}/ficheriro2.txt
98 cat <<END_OF_DATA >${tmp}/bconcmds
99 @$out /dev/null
100 messages
101 @$out ${tmp}/log1.out
102 run level=Incremental job=$JobName yes
103 wait
104 messages
105 quit
106 END_OF_DATA
107
108 run_bconsole
109
110 sleep 1
111 touch ${tmpsrc}/ficheriro1.txt
112 touch ${tmpsrc}/ficheriro2.txt
113 cat <<END_OF_DATA >${tmp}/bconcmds
114 @$out /dev/null
115 messages
116 @$out ${tmp}/log1.out
117 run level=Incremental job=$JobName yes
118 wait
119 messages
120 quit
121 END_OF_DATA
122
123 run_bconsole
124
125 sleep 1
126 touch ${tmpsrc}/ficheriro1.txt
127 touch ${tmpsrc}/ficheriro2.txt
128 cat <<END_OF_DATA >${tmp}/bconcmds
129 @$out /dev/null
130 messages
131 @$out ${tmp}/log1.out
132 run level=Incremental job=$JobName yes
133 wait
134 messages
135 quit
136 END_OF_DATA
137
138 run_bconsole
139 sleep 1
140 cat /etc/hosts >> ${tmpsrc}/ficheriro1.txt
141 rm -f ${tmpsrc}/dird_conf.c
142 touch ${tmpsrc}/ficheriro2.txt
143 ln ${tmpsrc}/ficheriro2.txt ${tmpsrc}/hardlink2
144
145 cat <<END_OF_DATA >${tmp}/bconcmds
146 @$out /dev/null
147 messages
148 @$out ${tmp}/log1.out
149 run level=Incremental accurate=yes job=$JobName
150 yes
151 wait
152 messages
153 @$out ${tmp}/log3.out
154 .bvfs_update
155 .bvfs_lsdir path=$tmpsrc/ jobid=1,2,3,4,5,6,7,8
156 .bvfs_lsfile path=$tmpsrc/ jobid=1,2,3,4,5,6,7,8
157 @$out ${tmp}/log31.out
158 .bvfs_lsfile path=$tmpsrc/ jobid=1,2,3,4,5,6,7
159 quit
160 END_OF_DATA
161
162 run_bconsole
163
164 cat <<END_OF_DATA >${tmp}/bconcmds
165 @$out $tmp/log4.out
166 .bvfs_cleanup path=b21
167 END_OF_DATA
168
169
170 # we look in the lsdir/lsfiles output to get filenameid and pathid for version and restore
171 awk '/ficheriro1.txt/ { 
172   print ".bvfs_versions jobid=" $4 " fnid=" $2 " pathid=" $1 " client='$CLIENT'"
173   print ".bvfs_restore jobid=" $4 " fileid=" $3 " path=b21"
174 } ' $tmp/log3.out >> $tmp/bconcmds
175
176 cat <<END_OF_DATA >>${tmp}/bconcmds
177 restore file="?b21" where=$tmp/bacula-restores yes
178 wait
179 messages
180 quit
181 END_OF_DATA
182
183 run_bconsole
184
185 diff $tmpsrc/ficheriro1.txt $tmp/bacula-restores/$tmpsrc/ficheriro1.txt &>> $tmp/d1
186 if [ $? != 0 ]; then
187     print_debug "ERROR: ficheriro1.txt is different"
188     rstat=1
189 fi
190
191 rm -rf $tmp/bacula-restores
192
193 cat <<END_OF_DATA >${tmp}/bconcmds
194 @$out $tmp/log4.out
195 @# Try to restore a directory
196 .bvfs_cleanup path=b21
197 END_OF_DATA
198
199 awk '/ficheriro2.txt/ { 
200   print ".bvfs_restore jobid=1,2,3,4,5,6,7,8 dirid=" $1 " path=b21"
201 } ' $tmp/log3.out >> $tmp/bconcmds
202
203 cat <<END_OF_DATA >>${tmp}/bconcmds
204 @$out $tmp/log2.out
205 restore file="?b21" where=$tmp/bacula-restores yes
206 wait
207 messages
208 quit
209 END_OF_DATA
210
211 run_bconsole
212
213 $rscripts/diff.pl -s $tmpsrc/ -d $tmp/bacula-restores/$tmpsrc/
214 if [ $? != 0 ]; then
215     print_debug "ERROR: Found error while restoring a directory"
216     rstat=1
217 fi
218
219 diff $tmpsrc/ficheriro2.txt $tmp/bacula-restores/$tmpsrc/ficheriro2.txt
220 if [ $? != 0 ]; then
221     print_debug "ERROR: ficheriro2.txt is different"
222     rstat=1
223 fi
224
225 rm -rf $tmp/bacula-restores
226
227 cat <<END_OF_DATA >${tmp}/bconcmds
228 @$out $tmp/log4.out
229 @# Try to restore a hardlinks
230 .bvfs_cleanup path=b21
231 END_OF_DATA
232
233 jidx=`awk -F '\t' '/ficheriro2.txt|hardlinks2/ { lstat=$5  } 
234    END { print ".bvfs_decode_lstat lstat=\"" lstat "\"" 
235 } ' $tmp/log3.out | $bin/bconsole -c $conf/bconsole.conf | awk -F= '/LinkFI/ { print $2 } '`
236
237 awk '/ficheriro2.txt/ { if (!id) { id=$3 } } /hardlink2/ { if (!id) { id=$3 } }
238   END {
239     print ".bvfs_restore jobid=1,2,3,4,5,6,7,8 hardlink=8,'$jidx' fileid=" id " path=b21"
240   } ' $tmp/log3.out >> $tmp/bconcmds
241
242 cat <<END_OF_DATA >>${tmp}/bconcmds
243 @$out $tmp/log2.out
244 restore file="?b21" where=$tmp/bacula-restores yes
245 wait
246 messages
247 quit
248 END_OF_DATA
249
250 run_bconsole
251
252 test -f $tmp/bacula-restores/$tmpsrc/hardlink2 -a -f $tmp/bacula-restores/$tmpsrc/ficheriro2.txt
253 if [ $? != 0 ]; then
254     print_debug "ERROR: Need to get all files"
255     rstat=1
256 fi
257
258 # Compare Inode
259 ls -i $tmp/bacula-restores/$tmpsrc/hardlink2 | awk ' { print $1 } ' > $tmp/1
260 ls -i $tmp/bacula-restores/$tmpsrc/ficheriro2.txt | awk ' { print $1 } ' > $tmp/2
261 diff $tmp/1 $tmp/2 > /dev/null
262 if [ $? != 0 ]; then
263     print_debug "ERROR: Both files should have the same inode number"
264     rstat=1
265 fi
266
267 check_for_zombie_jobs storage=File
268 stop_bacula
269
270 check_two_logs
271
272 grep dird_conf.c $tmp/log3.out > /dev/null
273 if [ $? = 0 ]; then
274     print_debug "ERROR: Should not find dird_conf.c in bvfs_lsfiles output $tmp/log3.out"
275     estat=1
276 fi
277
278 grep dird_conf.c $tmp/log31.out > /dev/null
279 if [ $? != 0 ]; then
280     print_debug "ERROR: Should find dird_conf.c in bvfs_lsfiles output $tmp/log31.out"
281     estat=1
282 fi
283
284 #
285 # Delete .c files because we will only restored the txt files
286 #
287 #rm -f ${tmpsrc}/*.c
288 #check_restore_tmp_build_diff
289 #
290 #${cwd}/build/src/tools/bvfs_test -T  -p ${tmpsrc} -j 1,2,3,4,5,6,7,8 \
291 #    -w "$working" -n "$db_name" -u "$db_user" -P "$db_password"
292 #
293 #${cwd}/build/src/tools/bvfs_test  -p ${cwd}/build/ -j 1,2,3,4,5,6,7,8    \
294 #    -w "$working" -n "$db_name" -u "$db_user" -P "$db_password" 
295 #
296 #${cwd}/build/src/tools/bvfs_test  -p ${tmpsrc} -j 1,2,3,4,5,6,7,8    \
297 #    -w "$working" -n "$db_name" -u "$db_user" -P "$db_password" \
298 #    -f ficheriro1.txt -c ${HOST}-fd
299
300 end_test