]> arthur.barton.de Git - bup.git/blob - t/test.sh
3f96ab005a80d9d835d8c344029d0d848f057492
[bup.git] / t / test.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . t/lib.sh
4
5 TOP="$(WVPASS /bin/pwd)" || exit $?
6 export BUP_DIR="$TOP/buptest.tmp"
7
8 bup()
9 {
10     "$TOP/bup" "$@"
11 }
12
13 WVSTART "init"
14
15 WVPASS rm -rf "$BUP_DIR"
16 WVPASS bup init
17
18 WVSTART "index"
19 D=bupdata.tmp
20 WVPASS force-delete $D
21 WVPASS mkdir $D
22 WVFAIL bup index --exclude-from $D/cannot-exist $D
23 WVPASSEQ "$(bup index --check -p)" ""
24 WVPASSEQ "$(bup index --check -p $D)" ""
25 WVFAIL [ -e $D.fake ]
26 WVFAIL bup index --check -u $D.fake
27 WVPASS bup index --check -u $D
28 WVPASSEQ "$(bup index --check -p $D)" "$D/"
29 WVPASS touch $D/a
30 WVPASS bup random 128k >$D/b
31 WVPASS mkdir $D/d $D/d/e
32 WVPASS bup random 512 >$D/f
33 WVPASS ln -s non-existent-file $D/g
34 WVPASSEQ "$(bup index -s $D/)" "A $D/"
35 WVPASSEQ "$(bup index -s $D/b)" ""
36 WVPASSEQ "$(bup index --check -us $D/b)" "A $D/b"
37 WVPASSEQ "$(bup index --check -us $D/b $D/d)" \
38 "A $D/d/e/
39 A $D/d/
40 A $D/b"
41 WVPASS touch $D/d/z
42 WVPASS bup tick
43 WVPASSEQ "$(bup index --check -usx $D)" \
44 "A $D/g
45 A $D/f
46 A $D/d/z
47 A $D/d/e/
48 A $D/d/
49 A $D/b
50 A $D/a
51 A $D/"
52 WVPASSEQ "$(bup index --check -us $D/a $D/b --fake-valid)" \
53 "  $D/b
54   $D/a"
55 WVPASSEQ "$(bup index --check -us $D/a)" "  $D/a"  # stays unmodified
56 WVPASSEQ "$(bup index --check -us $D/d --fake-valid)" \
57 "  $D/d/z
58   $D/d/e/
59   $D/d/"
60 WVPASS touch $D/d/z
61 WVPASS bup index -u $D/d/z  # becomes modified
62 WVPASSEQ "$(bup index -s $D/a $D $D/b)" \
63 "A $D/g
64 A $D/f
65 M $D/d/z
66   $D/d/e/
67 M $D/d/
68   $D/b
69   $D/a
70 A $D/"
71
72 WVPASS bup index -u $D/d/e $D/a --fake-invalid
73 WVPASSEQ "$(cd $D && bup index -m .)" \
74 "./g
75 ./f
76 ./d/z
77 ./d/e/
78 ./d/
79 ./a
80 ./"
81 WVPASSEQ "$(cd $D && bup index -m)" \
82 "g
83 f
84 d/z
85 d/e/
86 d/
87 a
88 ./"
89 WVPASSEQ "$(cd $D && bup index -s .)" "$(cd $D && bup index -s .)"
90
91 WVFAIL bup save -t $D/doesnt-exist-filename
92
93 WVPASS mv $BUP_DIR/bupindex $BUP_DIR/bi.old
94 WVFAIL bup save -t $D/d/e/fifotest
95 WVPASS mkfifo $D/d/e/fifotest
96 WVPASS bup index -u $D/d/e/fifotest
97 WVPASS bup save -t $D/d/e/fifotest
98 WVPASS bup save -t $D/d/e
99 WVPASS rm -f $D/d/e/fifotest
100 WVPASS bup index -u $D/d/e
101 WVFAIL bup save -t $D/d/e/fifotest
102 WVPASS mv $BUP_DIR/bi.old $BUP_DIR/bupindex
103
104 WVPASS bup index -u $D/d/e
105 WVPASS bup save -t $D/d/e
106 WVPASSEQ "$(cd $D && bup index -m)" \
107 "g
108 f
109 d/z
110 d/
111 a
112 ./"
113 WVPASS bup save -t $D/d
114 WVPASS bup index --fake-invalid $D/d/z
115 WVPASS bup save -t $D/d/z
116 WVPASS bup save -t $D/d/z  # test regenerating trees when no files are changed
117 WVPASS bup save -t $D/d
118 WVPASSEQ "$(cd $D && bup index -m)" \
119 "g
120 f
121 a
122 ./"
123 WVPASS bup save -r :$BUP_DIR -n r-test $D
124 WVFAIL bup save -r :$BUP_DIR/fake/path -n r-test $D
125 WVFAIL bup save -r :$BUP_DIR -n r-test $D/fake/path
126
127 WVSTART "split"
128 WVPASS echo a >a.tmp
129 WVPASS echo b >b.tmp
130 WVPASS bup split -b a.tmp >taga.tmp
131 WVPASS bup split -b b.tmp >tagb.tmp
132 WVPASS cat a.tmp b.tmp | WVPASS bup split -b >tagab.tmp
133 WVPASSEQ $(cat taga.tmp | wc -l) 1
134 WVPASSEQ $(cat tagb.tmp | wc -l) 1
135 WVPASSEQ $(cat tagab.tmp | wc -l) 1
136 WVPASSEQ $(cat tag[ab].tmp | wc -l) 2
137 WVPASSEQ "$(bup split -b a.tmp b.tmp)" "$(cat tagab.tmp)"
138 WVPASSEQ "$(bup split -b --keep-boundaries a.tmp b.tmp)" "$(cat tag[ab].tmp)"
139 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --keep-boundaries --git-ids)" \
140          "$(cat tag[ab].tmp)"
141 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --git-ids)" \
142          "$(cat tagab.tmp)"
143 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp
144 WVPASS bup split -vvvv -b t/testfile2 >tags2.tmp
145 WVPASS bup margin
146 WVPASS bup midx -f
147 WVPASS bup midx --check -a
148 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
149         $BUP_DIR/objects/pack/*.idx
150 WVPASS bup midx --check -a
151 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
152         $BUP_DIR/objects/pack/*.idx \
153         $BUP_DIR/objects/pack/*.idx
154 WVPASS bup midx --check -a
155 all=$(echo $BUP_DIR/objects/pack/*.idx $BUP_DIR/objects/pack/*.midx)
156 WVPASS bup midx -o $BUP_DIR/objects/pack/zzz.midx $all
157 WVPASS bup tick
158 WVPASS bup midx -o $BUP_DIR/objects/pack/yyy.midx $all
159 WVPASS bup midx -a
160 WVPASSEQ "$(echo $BUP_DIR/objects/pack/*.midx)" \
161         "$BUP_DIR/objects/pack/yyy.midx"
162 WVPASS bup margin
163 WVPASS bup split -t t/testfile2 >tags2t.tmp
164 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
165 WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
166 WVPASS bup split -r :$BUP_DIR -c t/testfile2 >tags2c.tmp
167 WVPASS ls -lR \
168    | WVPASS bup split -r :$BUP_DIR -c --fanout 3 --max-pack-objects 3 -n lslr
169 WVPASS bup ls
170 WVFAIL bup ls /does-not-exist
171 WVPASS bup ls /lslr
172 WVPASS bup ls /lslr/latest
173 WVPASS bup ls /lslr/latest/
174 #WVPASS bup ls /lslr/1971-01-01   # all dates always exist
175 WVFAIL diff -u tags1.tmp tags2.tmp
176
177 # fanout must be different from non-fanout
178 WVFAIL diff tags2t.tmp tags2tf.tmp
179 WVPASS wc -c t/testfile1 t/testfile2
180 WVPASS wc -l tags1.tmp tags2.tmp
181
182 WVSTART "bloom"
183 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
184 WVPASS rm $BUP_DIR/objects/pack/bup.bloom
185 WVPASS bup bloom -k 4
186 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
187 WVPASS bup bloom -d buptest.tmp/objects/pack --ruin --force
188 WVFAIL bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
189 WVPASS bup bloom --force -k 5
190 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
191
192 WVSTART "memtest"
193 WVPASS bup memtest -c1 -n100
194 WVPASS bup memtest -c1 -n100 --existing
195
196 WVSTART "join"
197 WVPASS bup join $(cat tags1.tmp) >out1.tmp
198 WVPASS bup join <tags2.tmp >out2.tmp
199 WVPASS bup join <tags2t.tmp -o out2t.tmp
200 WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
201 WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
202 WVPASS diff -u t/testfile1 out1.tmp
203 WVPASS diff -u t/testfile2 out2.tmp
204 WVPASS diff -u t/testfile2 out2t.tmp
205 WVPASS diff -u t/testfile2 out2c.tmp
206
207 WVSTART "save/git-fsck"
208 (
209     WVPASS cd "$BUP_DIR"
210     #git repack -Ad
211     #git prune
212     (WVPASS cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || exit $?
213     result="$(git fsck --full --strict 2>&1)" || exit $?
214     n=$(echo "$result" |
215         egrep -v 'dangling (commit|tree|blob)' |
216         WVPASS tee -a /dev/stderr |
217         WVPASS wc -l) || exit $?
218     WVPASS [ "$n" -eq 0 ]
219 ) || exit $?
220
221 WVSTART "restore"
222 WVPASS force-delete buprestore.tmp
223 WVFAIL bup restore boink
224 WVPASS touch $TOP/$D/$D
225 WVPASS bup index -u $TOP/$D
226 WVPASS bup save -n master /
227 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D"
228 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
229 WVPASS force-delete buprestore.tmp
230 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D/"
231 WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
232 WVPASS diff -ur $D/ buprestore.tmp/
233
234 (
235     tmp=testrestore.tmp
236     WVPASS force-delete $tmp
237     WVPASS mkdir $tmp
238     export BUP_DIR="$(pwd)/$tmp/bup"
239     WVPASS WVPASS bup init
240     WVPASS mkdir -p $tmp/src/x/y/z
241     WVPASS bup random 8k > $tmp/src/x/y/random-1
242     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
243     WVPASS bup index -u $tmp/src
244     WVPASS bup save --strip -n foo $tmp/src
245
246     WVSTART "restore /foo/latest"
247     WVPASS bup restore -C $tmp/restore /foo/latest
248     WVPASS t/compare-trees $tmp/src/ $tmp/restore/latest/
249
250     WVSTART "restore /foo/latest/"
251     WVPASS force-delete "$tmp/restore"
252     WVPASS bup restore -C $tmp/restore /foo/latest/
253     for x in $tmp/src/*; do
254         WVPASS t/compare-trees $x/ $tmp/restore/$(basename $x);
255     done
256
257     WVSTART "restore /foo/latest/."
258     WVPASS force-delete "$tmp/restore"
259     WVPASS bup restore -C $tmp/restore /foo/latest/.
260     WVPASS t/compare-trees $tmp/src/ $tmp/restore/
261
262     WVSTART "restore /foo/latest/x"
263     WVPASS force-delete "$tmp/restore"
264     WVPASS bup restore -C $tmp/restore /foo/latest/x
265     WVPASS t/compare-trees $tmp/src/x/ $tmp/restore/x/
266
267     WVSTART "restore /foo/latest/x/"
268     WVPASS force-delete "$tmp/restore"
269     WVPASS bup restore -C $tmp/restore /foo/latest/x/
270     for x in $tmp/src/x/*; do
271         WVPASS t/compare-trees $x/ $tmp/restore/$(basename $x);
272     done
273
274     WVSTART "restore /foo/latest/x/."
275     WVPASS force-delete "$tmp/restore"
276     WVPASS bup restore -C $tmp/restore /foo/latest/x/.
277     WVPASS t/compare-trees $tmp/src/x/ $tmp/restore/
278 ) || exit $?
279
280
281 WVSTART "ftp"
282 WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new
283 WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new
284 WVPASS bup ftp "cat /master/latest/$TOP/$D/f"{,} >$D/f2.new
285 WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new
286 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
287 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
288 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
289 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
290
291 WVSTART "tag"
292 WVFAIL bup tag -d v0.n 2>/dev/null
293 WVFAIL bup tag v0.n non-existant 2>/dev/null
294 WVPASSEQ "$(bup tag)" ""
295 WVPASS bup tag v0.1 master
296 WVPASSEQ "$(bup tag)" "v0.1"
297 WVPASS bup tag -d v0.1
298
299 # This section destroys data in the bup repository, so it is done last.
300 WVSTART "fsck"
301 WVPASS bup fsck
302 WVPASS bup fsck --quick
303 if bup fsck --par2-ok; then
304     WVSTART "fsck (par2)"
305 else
306     WVSTART "fsck (PAR2 IS MISSING)"
307 fi
308 WVPASS bup fsck -g
309 WVPASS bup fsck -r
310 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
311 WVFAIL bup fsck --quick
312 WVFAIL bup fsck --quick --disable-par2
313 WVPASS chmod u+w $BUP_DIR/objects/pack/*.idx
314 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
315 WVFAIL bup fsck --quick -j4
316 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
317 WVFAIL bup fsck --quick
318 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
319 if bup fsck --par2-ok; then
320     WVPASS bup fsck -r # ok because of repairs from last time
321     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
322     WVFAIL bup fsck
323     WVFAIL bup fsck -rvv   # too many errors to be repairable
324     WVFAIL bup fsck -r   # too many errors to be repairable
325 else
326     WVFAIL bup fsck --quick -r # still fails because par2 was missing
327 fi
328
329 WVSTART "exclude-bupdir"
330 D=exclude-bupdir.tmp
331 WVPASS force-delete $D
332 WVPASS mkdir $D
333 export BUP_DIR="$D/.bup"
334 WVPASS bup init
335 WVPASS touch $D/a
336 WVPASS bup random 128k >$D/b
337 WVPASS mkdir $D/d $D/d/e
338 WVPASS bup random 512 >$D/f
339 WVPASS bup index -ux $D
340 WVPASS bup save -n exclude-bupdir $D
341 WVPASSEQ "$(bup ls -a exclude-bupdir/latest/$TOP/$D/)" "a
342 b
343 d/
344 f"
345
346 WVSTART "exclude"
347 (
348     D=exclude.tmp
349     WVPASS force-delete $D
350     WVPASS mkdir $D
351     export BUP_DIR="$D/.bup"
352     WVPASS bup init
353     WVPASS touch $D/a
354     WVPASS bup random 128k >$D/b
355     WVPASS mkdir $D/d $D/d/e
356     WVPASS bup random 512 >$D/f
357     WVPASS bup random 512 >$D/j
358     WVPASS bup index -ux --exclude $D/d --exclude $D/j $D
359     WVPASS bup save -n exclude $D
360     WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
361 b
362 f"
363     WVPASS mkdir $D/g $D/h
364     WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h \
365         --exclude $TOP/$D/j $D
366     WVPASS bup save -n exclude $D
367     WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
368 b
369 f"
370 ) || exit $?
371
372 WVSTART "exclude-from"
373 (
374     D=exclude-fromdir.tmp
375     EXCLUDE_FILE=exclude-from.tmp
376     WVPASS echo "$D/d 
377  $TOP/$D/g
378 $D/h
379 $D/i" > $EXCLUDE_FILE
380     WVPASS force-delete $D
381     WVPASS mkdir $D
382     export BUP_DIR="$D/.bup"
383     WVPASS bup init
384     WVPASS touch $D/a
385     WVPASS bup random 128k >$D/b
386     WVPASS mkdir $D/d $D/d/e
387     WVPASS bup random 512 >$D/f
388     WVPASS mkdir $D/g $D/h
389     WVPASS bup random 128k > $D/i
390     WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
391     WVPASS bup save -n exclude-from $D
392     WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
393 b
394 f"
395     WVPASS rm $EXCLUDE_FILE
396 ) || exit $?
397
398 WVSTART "save (no index)"
399 (
400     tmp=save-no-index.tmp
401     WVPASS force-delete $tmp
402     WVPASS mkdir $tmp
403     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
404     WVPASS bup init
405     WVFAIL bup save -n nothing /
406     WVPASS rm -r "$tmp"
407 ) || exit $?
408
409 WVSTART "save --strip"
410 (
411     tmp=graft-points.tmp
412     WVPASS force-delete $tmp
413     WVPASS mkdir $tmp
414     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
415     WVPASS bup init
416     WVPASS mkdir -p $tmp/src/x/y/z
417     WVPASS bup random 8k > $tmp/src/x/y/random-1
418     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
419     WVPASS bup index -u $tmp/src
420     WVPASS bup save --strip -n foo $tmp/src/x/y
421     WVPASS bup restore -C $tmp/restore /foo/latest
422     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/"
423 ) || exit $?
424
425 WVSTART "save --strip-path (relative)"
426 (
427     tmp=graft-points.tmp
428     WVPASS force-delete $tmp
429     WVPASS mkdir $tmp
430     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
431     WVPASS bup init
432     WVPASS mkdir -p $tmp/src/x/y/z
433     WVPASS bup random 8k > $tmp/src/x/y/random-1
434     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
435     WVPASS bup index -u $tmp/src
436     WVPASS bup save --strip-path $tmp/src -n foo $tmp/src/x
437     WVPASS bup restore -C $tmp/restore /foo/latest
438     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/"
439 ) || exit $?
440
441 WVSTART "save --strip-path (absolute)"
442 (
443     tmp=graft-points.tmp
444     WVPASS force-delete $tmp
445     WVPASS mkdir $tmp
446     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
447     WVPASS bup init
448     WVPASS mkdir -p $tmp/src/x/y/z
449     WVPASS bup random 8k > $tmp/src/x/y/random-1
450     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
451     WVPASS bup index -u $tmp/src
452     WVPASS bup save --strip-path "$TOP" -n foo $tmp/src
453     WVPASS bup restore -C $tmp/restore /foo/latest
454     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$tmp/src/"
455 ) || exit $?
456
457 WVSTART "save --strip-path (no match)"
458 (
459     tmp=graft-points.tmp
460     WVPASS force-delete $tmp
461     WVPASS mkdir $tmp
462     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
463     WVPASS bup init
464     WVPASS mkdir -p $tmp/src/x/y/z
465     WVPASS bup random 8k > $tmp/src/x/y/random-1
466     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
467     WVPASS bup index -u $tmp/src
468     WVPASS bup save --strip-path $tmp/foo -n foo $tmp/src/x
469     WVPASS bup restore -C $tmp/restore /foo/latest
470     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/"
471 ) || exit $?
472
473 WVSTART "save --graft (empty graft points disallowed)"
474 (
475     tmp=graft-points.tmp
476     WVPASS force-delete $tmp
477     WVPASS mkdir $tmp
478     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
479     WVPASS bup init
480     WVFAIL bup save --graft =/grafted -n graft-point-absolute $tmp
481     WVFAIL bup save --graft $TOP/$tmp= -n graft-point-absolute $tmp
482 ) || exit $?
483
484 WVSTART "save --graft /x/y=/a/b (relative paths)"
485 (
486     tmp=graft-points.tmp
487     WVPASS force-delete $tmp
488     WVPASS mkdir $tmp
489     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
490     WVPASS bup init
491     WVPASS mkdir -p $tmp/src/x/y/z
492     WVPASS bup random 8k > $tmp/src/x/y/random-1
493     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
494     WVPASS bup index -u $tmp/src
495     WVPASS bup save --graft $tmp/src=x -n foo $tmp/src
496     WVPASS bup restore -C $tmp/restore /foo/latest
497     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/x/"
498 ) || exit $?
499
500 WVSTART "save --graft /x/y=/a/b (matching structure)"
501 (
502     tmp=graft-points.tmp
503     WVPASS force-delete $tmp
504     WVPASS mkdir $tmp
505     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
506     WVPASS bup init
507     WVPASS mkdir -p $tmp/src/x/y/z
508     WVPASS bup random 8k > $tmp/src/x/y/random-1
509     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
510     WVPASS bup index -u $tmp/src
511     WVPASS bup save -v --graft "$TOP/$tmp/src/x/y=$TOP/$tmp/src/a/b" \
512         -n foo $tmp/src/x/y
513     WVPASS bup restore -C $tmp/restore /foo/latest
514     WVPASS t/compare-trees $tmp/src/x/y/ \
515         "$tmp/restore/latest/$TOP/$tmp/src/a/b/"
516 ) || exit $?
517
518 WVSTART "save --graft /x/y=/a (shorter target)"
519 (
520     tmp=graft-points.tmp
521     WVPASS force-delete $tmp
522     WVPASS mkdir $tmp
523     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
524     WVPASS bup init
525     WVPASS mkdir -p $tmp/src/x/y/z
526     WVPASS bup random 8k > $tmp/src/x/y/random-1
527     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
528     WVPASS bup index -u $tmp/src
529     WVPASS bup save -v --graft "$TOP/$tmp/src/x/y=/a" -n foo $tmp/src/x/y
530     WVPASS bup restore -C $tmp/restore /foo/latest
531     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/a/"
532 ) || exit $?
533
534 WVSTART "save --graft /x=/a/b (longer target)"
535 (
536     tmp=graft-points.tmp
537     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
538     WVPASS force-delete $tmp
539     WVPASS mkdir $tmp
540     WVPASS bup init
541     WVPASS mkdir -p $tmp/src/x/y/z
542     WVPASS bup random 8k > $tmp/src/x/y/random-1
543     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
544     WVPASS bup index -u $tmp/src
545     WVPASS bup save -v --graft "$TOP/$tmp/src=$TOP/$tmp/src/a/b/c" \
546         -n foo $tmp/src
547     WVPASS bup restore -C $tmp/restore /foo/latest
548     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/a/b/c/"
549 ) || exit $?
550
551 WVSTART "save --graft /x=/ (root target)"
552 (
553     tmp=graft-points.tmp
554     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
555     WVPASS force-delete $tmp
556     WVPASS mkdir $tmp
557     WVPASS bup init
558     WVPASS mkdir -p $tmp/src/x/y/z
559     WVPASS bup random 8k > $tmp/src/x/y/random-1
560     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
561     WVPASS bup index -u $tmp/src
562     WVPASS bup save -v --graft "$TOP/$tmp/src/x=/" -n foo $tmp/src/x
563     WVPASS bup restore -C $tmp/restore /foo/latest
564     WVPASS t/compare-trees $tmp/src/x/ "$tmp/restore/latest/"
565 ) || exit $?
566
567 #WVSTART "save --graft /=/x/ (root source)"
568 # FIXME: Not tested for now -- will require cleverness, or caution as root.
569
570 WVSTART "indexfile"
571 D=indexfile.tmp
572 INDEXFILE=tmpindexfile.tmp
573 WVPASS rm -f $INDEXFILE
574 WVPASS force-delete $D
575 WVPASS mkdir $D
576 export BUP_DIR="$D/.bup"
577 WVPASS bup init
578 WVPASS touch $D/a
579 WVPASS touch $D/b
580 WVPASS mkdir $D/c
581 WVPASS bup index -ux $D
582 WVPASS bup save --strip -n bupdir $D
583 WVPASSEQ "$(bup ls bupdir/latest/)" "a
584 b
585 c/"
586 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
587 WVPASS bup save --strip -n indexfile -f $INDEXFILE $D
588 WVPASSEQ "$(bup ls indexfile/latest/)" "a
589 b"
590
591
592 WVSTART "import-rsnapshot"
593 D=rsnapshot.tmp
594 export BUP_DIR="$TOP/$D/.bup"
595 WVPASS force-delete $D
596 WVPASS mkdir $D
597 WVPASS bup init
598 WVPASS mkdir -p $D/hourly.0/buptest/a
599 WVPASS touch $D/hourly.0/buptest/a/b
600 WVPASS mkdir -p $D/hourly.0/buptest/c/d
601 WVPASS touch $D/hourly.0/buptest/c/d/e
602 WVPASS true
603 WVPASS bup import-rsnapshot $D/
604 WVPASSEQ "$(bup ls buptest/latest/)" "a/
605 c/"
606
607
608 if [ "$(which rdiff-backup)" != "" ]; then
609     WVSTART "import-rdiff-backup"
610     D=rdiff-backup.tmp
611     export BUP_DIR="$TOP/$D/.bup"
612     WVPASS force-delete $D
613     WVPASS mkdir $D
614     WVPASS bup init
615     WVPASS mkdir $D/rdiff-backup
616     WVPASS rdiff-backup $TOP/cmd $D/rdiff-backup
617     WVPASS bup tick
618     WVPASS rdiff-backup $TOP/Documentation $D/rdiff-backup
619     WVPASS bup import-rdiff-backup $D/rdiff-backup import-rdiff-backup
620     WVPASSEQ "$(bup ls import-rdiff-backup/ | wc -l)" "3"
621     WVPASSEQ "$(bup ls import-rdiff-backup/latest/ | sort)" "$(ls $TOP/Documentation | sort)"
622 fi
623
624
625 WVSTART "compression"
626 D=compression0.tmp
627 export BUP_DIR="$TOP/$D/.bup"
628 WVPASS force-delete $D
629 WVPASS mkdir $D
630 WVPASS bup init
631 WVPASS bup index $TOP/Documentation
632 WVPASS bup save -n compression -0 --strip $TOP/Documentation
633 # 'ls' on NetBSD sets -A by default when running as root, so we have to undo
634 # it by grepping out any dotfiles.  (Normal OSes don't auto-set -A, but this
635 # is harmless there.)
636 expected="$(WVPASS ls $TOP/Documentation | grep -v '^\.' | WVPASS sort)" \
637     || exit $?
638 actual="$(WVPASS bup ls compression/latest/ | WVPASS sort)" || exit $?
639 WVPASSEQ "$actual" "$expected"
640 COMPRESSION_0_SIZE=$(WVPASS du -k -s $D | WVPASS cut -f1) || exit $?
641
642 D=compression9.tmp
643 export BUP_DIR="$TOP/$D/.bup"
644 WVPASS force-delete $D
645 WVPASS mkdir $D
646 WVPASS bup init
647 WVPASS bup index $TOP/Documentation
648 WVPASS bup save -n compression -9 --strip $TOP/Documentation
649 WVPASSEQ "$(bup ls compression/latest/ | sort)" \
650          "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
651 COMPRESSION_9_SIZE=$(WVPASS du -k -s $D | WVPASS cut -f1) || exit $?
652
653 WVPASS [ "$COMPRESSION_9_SIZE" -lt "$COMPRESSION_0_SIZE" ]
654
655 WVSTART "save disjoint top-level directories"
656 (
657     # Resolve any symlinks involving the top top-level dirs.
658     real_pwd="$(WVPASS realpath .)" || exit $?
659     real_tmp="$(WVPASS realpath /tmp/.)" || exit $?
660     pwd_top="$(echo $real_pwd | WVPASS awk -F "/" '{print $2}')" || exit $?
661     tmp_top="$(echo $real_tmp | WVPASS awk -F "/" '{print $2}')" || exit $?
662
663     if [ "$pwd_top" = "$tmp_top" ]; then
664         echo "(running from within /$tmp_top; skipping test)" 1>&2
665         exit 0
666     fi
667     D=bupdata.tmp
668     WVPASS force-delete $D
669     WVPASS mkdir -p $D/x
670     WVPASS date > $D/x/1
671     tmpdir="$(WVPASS mktemp -d $real_tmp/bup-test-XXXXXXX)" || exit $?
672     cleanup() { WVPASS rm -r "${tmpdir}"; }
673     WVPASS trap cleanup EXIT
674     WVPASS date > "$tmpdir/2"
675
676     export BUP_DIR="$TOP/buptest.tmp"
677     WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
678
679     WVPASS bup init
680     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir"
681     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir"
682
683     # For now, assume that "ls -a" and "sort" use the same order.
684     actual="$(WVPASS bup ls -a src/latest)" || exit $?
685     expected="$(echo -e "$pwd_top/\n$tmp_top/" | WVPASS sort)" || exit $?
686     WVPASSEQ "$actual" "$expected"
687 ) || exit $?
688
689 WVSTART "clear-index"
690 D=clear-index.tmp
691 export BUP_DIR="$TOP/$D/.bup"
692 WVPASS force-delete $TOP/$D
693 WVPASS mkdir $TOP/$D
694 WVPASS bup init
695 WVPASS touch $TOP/$D/foo
696 WVPASS touch $TOP/$D/bar
697 WVPASS bup index -u $D
698 WVPASSEQ "$(bup index -p)" "$D/foo
699 $D/bar
700 $D/
701 ./"
702 WVPASS rm $TOP/$D/foo
703 WVPASS bup index --clear
704 WVPASS bup index -u $TOP/$D
705 expected="$(WVPASS bup index -p)" || exit $?
706 WVPASSEQ "$expected" "$D/bar
707 $D/
708 ./"
709
710 # bup index --exclude-rx ...
711 (
712     export BUP_DIR="$TOP/buptest.tmp"
713     D=bupdata.tmp
714
715     WVSTART "index --exclude-rx '^/foo' (root anchor)"
716     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
717     WVPASS bup init
718     WVPASS mkdir $D
719     WVPASS touch $D/a
720     WVPASS touch $D/b
721     WVPASS mkdir $D/sub1
722     WVPASS mkdir $D/sub2
723     WVPASS touch $D/sub1/a
724     WVPASS touch $D/sub2/b
725     WVPASS bup index -u $D --exclude-rx "^$(pwd)/$D/sub1/"
726     WVPASS bup save --strip -n bupdir $D
727     WVPASS bup restore -C buprestore.tmp /bupdir/latest/
728     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
729     WVPASSEQ "$actual" ".
730 ./a
731 ./b
732 ./sub2
733 ./sub2/b"
734
735     WVSTART "index --exclude-rx '/foo$' (non-dir, tail anchor)"
736     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
737     WVPASS bup init
738     WVPASS mkdir $D
739     WVPASS touch $D/a
740     WVPASS touch $D/b
741     WVPASS touch $D/foo
742     WVPASS mkdir $D/sub
743     WVPASS mkdir $D/sub/foo
744     WVPASS touch $D/sub/foo/a
745     WVPASS bup index -u $D --exclude-rx '/foo$'
746     WVPASS bup save --strip -n bupdir $D
747     WVPASS bup restore -C buprestore.tmp /bupdir/latest/
748     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
749     WVPASSEQ "$actual" ".
750 ./a
751 ./b
752 ./sub
753 ./sub/foo
754 ./sub/foo/a"
755
756     WVSTART "index --exclude-rx '/foo/$' (dir, tail anchor)"
757     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
758     WVPASS bup init
759     WVPASS mkdir $D
760     WVPASS touch $D/a
761     WVPASS touch $D/b
762     WVPASS touch $D/foo
763     WVPASS mkdir $D/sub
764     WVPASS mkdir $D/sub/foo
765     WVPASS touch $D/sub/foo/a
766     WVPASS bup index -u $D --exclude-rx '/foo/$'
767     WVPASS bup save --strip -n bupdir $D
768     WVPASS bup restore -C buprestore.tmp /bupdir/latest/
769     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
770     WVPASSEQ "$actual" ".
771 ./a
772 ./b
773 ./foo
774 ./sub"
775
776     WVSTART "index --exclude-rx '/foo/.' (dir content)"
777     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
778     WVPASS bup init
779     WVPASS mkdir $D
780     WVPASS touch $D/a
781     WVPASS touch $D/b
782     WVPASS touch $D/foo
783     WVPASS mkdir $D/sub
784     WVPASS mkdir $D/sub/foo
785     WVPASS touch $D/sub/foo/a
786     WVPASS bup index -u $D --exclude-rx '/foo/.'
787     WVPASS bup save --strip -n bupdir $D
788     WVPASS bup restore -C buprestore.tmp /bupdir/latest/
789     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
790     WVPASSEQ "$actual" ".
791 ./a
792 ./b
793 ./foo
794 ./sub
795 ./sub/foo"
796 ) || exit $?
797
798
799 # bup restore --exclude-rx ...
800 (
801     export BUP_DIR="$TOP/buptest.tmp"
802     D=bupdata.tmp
803
804     WVSTART "restore --exclude-rx '^/foo' (root anchor)"
805     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
806     WVPASS bup init
807     WVPASS mkdir $D
808     WVPASS touch $D/a
809     WVPASS touch $D/b
810     WVPASS mkdir $D/sub1
811     WVPASS mkdir $D/sub2
812     WVPASS touch $D/sub1/a
813     WVPASS touch $D/sub2/b
814     WVPASS bup index -u $D
815     WVPASS bup save --strip -n bupdir $D
816     WVPASS bup restore -C buprestore.tmp --exclude-rx "^/sub1/" /bupdir/latest/
817     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
818     WVPASSEQ "$actual" ".
819 ./a
820 ./b
821 ./sub2
822 ./sub2/b"
823
824     WVSTART "restore --exclude-rx '/foo$' (non-dir, tail anchor)"
825     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
826     WVPASS bup init
827     WVPASS mkdir $D
828     WVPASS touch $D/a
829     WVPASS touch $D/b
830     WVPASS touch $D/foo
831     WVPASS mkdir $D/sub
832     WVPASS mkdir $D/sub/foo
833     WVPASS touch $D/sub/foo/a
834     WVPASS bup index -u $D
835     WVPASS bup save --strip -n bupdir $D
836     WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo$' /bupdir/latest/
837     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
838     WVPASSEQ "$actual" ".
839 ./a
840 ./b
841 ./sub
842 ./sub/foo
843 ./sub/foo/a"
844
845     WVSTART "restore --exclude-rx '/foo/$' (dir, tail anchor)"
846     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
847     WVPASS bup init
848     WVPASS mkdir $D
849     WVPASS touch $D/a
850     WVPASS touch $D/b
851     WVPASS touch $D/foo
852     WVPASS mkdir $D/sub
853     WVPASS mkdir $D/sub/foo
854     WVPASS touch $D/sub/foo/a
855     WVPASS bup index -u $D
856     WVPASS bup save --strip -n bupdir $D
857     WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo/$' /bupdir/latest/
858     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
859     WVPASSEQ "$actual" ".
860 ./a
861 ./b
862 ./foo
863 ./sub"
864
865     WVSTART "restore --exclude-rx '/foo/.' (dir content)"
866     WVPASS rm -rf "$D" "$BUP_DIR" buprestore.tmp
867     WVPASS bup init
868     WVPASS mkdir $D
869     WVPASS touch $D/a
870     WVPASS touch $D/b
871     WVPASS touch $D/foo
872     WVPASS mkdir $D/sub
873     WVPASS mkdir $D/sub/foo
874     WVPASS touch $D/sub/foo/a
875     WVPASS bup index -u $D
876     WVPASS bup save --strip -n bupdir $D
877     WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo/.' /bupdir/latest/
878     actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
879     WVPASSEQ "$actual" ".
880 ./a
881 ./b
882 ./foo
883 ./sub
884 ./sub/foo"
885 ) || exit $?