]> arthur.barton.de Git - bup.git/blob - t/test-sparse-files.sh
Add support for "restore --sparse"
[bup.git] / t / test-sparse-files.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh
3
4 set -o pipefail
5
6 readonly mb=1048576
7 readonly top="$(WVPASS pwd)" || exit $?
8 readonly tmpdir="$(WVPASS wvmktempdir)" || exit $?
9
10 export BUP_DIR="$tmpdir/bup"
11 export GIT_DIR="$tmpdir/bup"
12
13 bup() { "$top/bup" "$@"; }
14
15 WVPASS cd "$tmpdir"
16
17 WVPASS dd if=/dev/zero of=test-sparse seek=$((1024 * 256)) bs=1 count=1
18 restore_size=$(WVPASS du -k -s test-sparse | WVPASS cut -f1) || exit $?
19 if ! [ "$restore_size" -lt 256 ]; then
20     WVSTART "no sparse support detected -- skipping tests"
21     exit 0
22 fi
23
24 WVPASS bup init
25 WVPASS mkdir src
26
27 WVPASS dd if=/dev/zero of=src/foo seek=$mb bs=1 count=1
28 WVPASS bup index src
29 WVPASS bup save -n src src
30
31 WVSTART "sparse file restore (all sparse)"
32 WVPASS bup restore -C restore "src/latest/$(pwd)/"
33 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
34 WVPASS [ "$restore_size" -gt 1000 ]
35 WVPASS "$top/t/compare-trees" -c src/ restore/src/
36
37 WVSTART "sparse file restore --no-sparse (all sparse)"
38 WVPASS rm -r restore
39 WVPASS bup restore --no-sparse -C restore "src/latest/$(pwd)/"
40 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
41 WVPASS [ "$restore_size" -gt 1000 ]
42 WVPASS "$top/t/compare-trees" -c src/ restore/src/
43
44 WVSTART "sparse file restore --sparse (all sparse)"
45 WVPASS rm -r restore
46 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
47 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
48 WVPASS [ "$restore_size" -lt 100 ]
49 WVPASS "$top/t/compare-trees" -c src/ restore/src/
50
51 WVSTART "sparse file restore --sparse (sparse end)"
52 WVPASS echo "start" > src/foo
53 WVPASS dd if=/dev/zero of=src/foo seek=$mb bs=1 count=1 conv=notrunc
54 WVPASS bup index src
55 WVPASS bup save -n src src
56 WVPASS rm -r restore
57 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
58 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
59 WVPASS [ "$restore_size" -lt 100 ]
60 WVPASS "$top/t/compare-trees" -c src/ restore/src/
61
62 WVSTART "sparse file restore --sparse (sparse middle)"
63 WVPASS echo "end" >> src/foo
64 WVPASS bup index src
65 WVPASS bup save -n src src
66 WVPASS rm -r restore
67 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
68 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
69 WVPASS [ "$restore_size" -lt 100 ]
70 WVPASS "$top/t/compare-trees" -c src/ restore/src/
71
72 WVSTART "sparse file restore --sparse (sparse start)"
73 WVPASS dd if=/dev/zero of=src/foo seek=$mb bs=1 count=1
74 WVPASS echo "end" >> src/foo
75 WVPASS bup index src
76 WVPASS bup save -n src src
77 WVPASS rm -r restore
78 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
79 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
80 WVPASS [ "$restore_size" -lt 100 ]
81 WVPASS "$top/t/compare-trees" -c src/ restore/src/
82
83 WVSTART "sparse file restore --sparse (sparse start and end)"
84 WVPASS dd if=/dev/zero of=src/foo seek=$mb bs=1 count=1
85 WVPASS echo "middle" >> src/foo
86 WVPASS dd if=/dev/zero of=src/foo seek=$((2 * mb)) bs=1 count=1 conv=notrunc
87 WVPASS bup index src
88 WVPASS bup save -n src src
89 WVPASS rm -r restore
90 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
91 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
92 WVPASS [ "$restore_size" -lt 100 ]
93 WVPASS "$top/t/compare-trees" -c src/ restore/src/
94
95 WVSTART "sparse file restore --sparse (random)"
96 WVPASS bup random 512k > src/foo
97 WVPASS bup index src
98 WVPASS bup save -n src src
99 WVPASS rm -r restore
100 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
101 WVPASS "$top/t/compare-trees" -c src/ restore/src/
102
103 WVPASS rm -rf "$tmpdir"