3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
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
15 ${rscripts}/copy-test-confs
16 echo "${tmpsrc}" >${tmp}/file-list
17 echo "${cwd}/build" >> ${tmp}/file-list
20 cp -p ${src}/src/dird/*.c ${tmpsrc}
22 echo "${tmpsrc}/ficheriro1.txt" >restore-list
23 echo "${tmpsrc}/ficheriro2.txt" >>restore-list
26 change_jobname CompressedTest $JobName
29 cat <<END_OF_DATA >${tmp}/bconcmds
33 SELECT pg_catalog.setval('file_fileid_seq', 21474836471, false);
36 label storage=File volume=TestVolume001
37 label storage=File volume=TestVolume002
45 check_for_zombie_jobs storage=File
47 # Now create two new files to be restored later
50 echo "ficheriro1.txt" >${tmpsrc}/ficheriro1.txt
51 cp -f ${tmpsrc}/dird.c ${tmpsrc}/ficheriro2.txt
53 cat <<END_OF_DATA >${tmp}/bconcmds
57 @# Force Incremental on the second Volume
58 update volume=TestVolume001 VolStatus=Used
59 run level=Differential job=$JobName yes
68 touch ${tmpsrc}/ficheriro1.txt
69 touch ${tmpsrc}/ficheriro2.txt
71 cat <<END_OF_DATA >${tmp}/bconcmds
75 run level=Incremental job=$JobName yes
85 cp -f ficheriro2.txt 1
86 sed "s%a%b%g" 1 >ficheriro2.txt
89 cat <<END_OF_DATA >${tmp}/bconcmds
93 run level=Differential job=$JobName yes
102 touch ${tmpsrc}/ficheriro1.txt
103 touch ${tmpsrc}/ficheriro2.txt
104 cat <<END_OF_DATA >${tmp}/bconcmds
107 @$out ${tmp}/log1.out
108 run level=Incremental job=$JobName yes
117 touch ${tmpsrc}/ficheriro1.txt
118 touch ${tmpsrc}/ficheriro2.txt
119 cat <<END_OF_DATA >${tmp}/bconcmds
122 @$out ${tmp}/log1.out
123 run level=Incremental job=$JobName yes
132 touch ${tmpsrc}/ficheriro1.txt
133 touch ${tmpsrc}/ficheriro2.txt
134 cat <<END_OF_DATA >${tmp}/bconcmds
137 @$out ${tmp}/log1.out
138 run level=Incremental job=$JobName yes
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
151 cat <<END_OF_DATA >${tmp}/bconcmds
154 @$out ${tmp}/log1.out
155 run level=Incremental accurate=yes job=$JobName
159 @$out ${tmp}/log3.out
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
172 cat <<END_OF_DATA >${tmp}/bconcmds
174 .bvfs_cleanup path=b21
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
184 cat <<END_OF_DATA >>${tmp}/bconcmds
185 restore file="?b21" where=$tmp/bacula-restores yes
193 diff $tmpsrc/ficheriro1.txt $tmp/bacula-restores/$tmpsrc/ficheriro1.txt > $tmp/d1 2>&1
195 print_debug "ERROR: ficheriro1.txt is different"
199 rm -rf $tmp/bacula-restores
201 cat <<END_OF_DATA >${tmp}/bconcmds
203 @# Try to restore a directory
204 .bvfs_cleanup path=b21
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
211 cat <<END_OF_DATA >>${tmp}/bconcmds
213 restore file="?b21" where=$tmp/bacula-restores yes
221 $rscripts/diff.pl -s $tmpsrc/ -d $tmp/bacula-restores/$tmpsrc/
223 print_debug "ERROR: Found error while restoring a directory"
227 diff $tmpsrc/ficheriro2.txt $tmp/bacula-restores/$tmpsrc/ficheriro2.txt
229 print_debug "ERROR: ficheriro2.txt is different"
233 rm -rf $tmp/bacula-restores
235 cat <<END_OF_DATA >${tmp}/bconcmds
237 @# Try to restore a hardlinks
238 .bvfs_cleanup path=b21
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 } '`
245 awk '/ficheriro2.txt/ { if (!id) { id=$3 } } /hardlink2/ { if (!id) { id=$3 } }
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
250 cat <<END_OF_DATA >>${tmp}/bconcmds
252 restore file="?b21" where=$tmp/bacula-restores yes
260 test -f $tmp/bacula-restores/$tmpsrc/hardlink2 -a -f $tmp/bacula-restores/$tmpsrc/ficheriro2.txt
262 print_debug "ERROR: Need to get all files"
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
271 print_debug "ERROR: Both files should have the same inode number"
275 check_for_zombie_jobs storage=File
280 grep dird_conf.c $tmp/log3.out > /dev/null
282 print_debug "ERROR: Should not find dird_conf.c in bvfs_lsfiles output $tmp/log3.out"
286 grep dird_conf.c $tmp/log31.out > /dev/null
288 print_debug "ERROR: Should find dird_conf.c in bvfs_lsfiles output $tmp/log31.out"
292 awk '/\tficheriro1.txt/ { print "ok"} ' $tmp/log32.out | grep ok > /dev/null
294 print_debug "ERROR: Should find ficheriro1.txt in bvfs_lsfiles output $tmp/log32.out"
300 # Delete .c files because we will only restored the txt files
303 #check_restore_tmp_build_diff
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"
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"
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