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