2 . ./wvtest-bup.sh || exit $?
8 top="$(WVPASS pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 readonly mb top tmpdir
12 export BUP_DIR="$tmpdir/bup"
13 export GIT_DIR="$tmpdir/bup"
15 bup() { "$top/bup" "$@"; }
19 # The 3MB guess is semi-arbitrary, but we've been informed that
20 # Lustre, for example, uses 1MB, so guess higher than that, at least.
21 block_size=$(bup-cfg-py -c \
22 "import os; print(getattr(os.stat('.'), 'st_blksize', 0)) or $mb * 3") \
24 data_size=$((block_size * 10))
25 readonly block_size data_size
27 WVPASS dd if=/dev/zero of=test-sparse-probe seek="$data_size" bs=1 count=1
28 probe_size=$(WVPASS du -k -s test-sparse-probe | WVPASS cut -f1) || exit $?
29 if [ "$probe_size" -ge "$((data_size / 1024))" ]; then
30 WVSTART "no sparse support detected -- skipping tests"
34 WVSTART "sparse restore on $(current-filesystem), assuming ${block_size}B blocks"
39 WVPASS dd if=/dev/zero of=src/foo seek="$data_size" bs=1 count=1
41 WVPASS bup save -n src src
43 WVSTART "sparse file restore (all sparse)"
44 WVPASS bup restore -C restore "src/latest/$(pwd)/"
45 restore_size=$(WVPASS du -k -s restore/src/foo | WVPASS cut -f1) || exit $?
46 WVPASS [ "$restore_size" -ge "$((data_size / 1024))" ]
47 WVPASS "$top/t/compare-trees" -c src/ restore/src/
49 WVSTART "sparse file restore --no-sparse (all sparse)"
51 WVPASS bup restore --no-sparse -C restore "src/latest/$(pwd)/"
52 restore_size=$(WVPASS du -k -s restore/src/foo | WVPASS cut -f1) || exit $?
53 WVPASS [ "$restore_size" -ge "$((data_size / 1024))" ]
54 WVPASS "$top/t/compare-trees" -c src/ restore/src/
56 WVSTART "sparse file restore --sparse (all sparse)"
58 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
59 restore_size=$(WVPASS du -k -s restore/src/foo | WVPASS cut -f1) || exit $?
60 WVPASS [ "$restore_size" -le "$((3 * (block_size / 1024)))" ]
61 WVPASS "$top/t/compare-trees" -c src/ restore/src/
63 WVSTART "sparse file restore --sparse (sparse end)"
64 WVPASS echo "start" > src/foo
65 WVPASS dd if=/dev/zero of=src/foo seek="$data_size" bs=1 count=1 conv=notrunc
67 WVPASS bup save -n src src
69 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
70 restore_size=$(WVPASS du -k -s restore/src/foo | WVPASS cut -f1) || exit $?
71 WVPASS [ "$restore_size" -le "$((3 * (block_size / 1024)))" ]
72 WVPASS "$top/t/compare-trees" -c src/ restore/src/
74 WVSTART "sparse file restore --sparse (sparse middle)"
75 WVPASS echo "end" >> src/foo
77 WVPASS bup save -n src src
79 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
80 restore_size=$(WVPASS du -k -s restore/src/foo | WVPASS cut -f1) || exit $?
81 WVPASS [ "$restore_size" -le "$((5 * (block_size / 1024)))" ]
82 WVPASS "$top/t/compare-trees" -c src/ restore/src/
84 WVSTART "sparse file restore --sparse (bracketed zero run in buf)"
85 WVPASS echo 'x' > src/foo
86 WVPASS dd if=/dev/zero bs=1 count=512 >> src/foo
87 WVPASS echo 'y' >> src/foo
89 WVPASS bup save -n src src
91 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
92 WVPASS "$top/t/compare-trees" -c src/ restore/src/
94 WVSTART "sparse file restore --sparse (sparse start)"
95 WVPASS dd if=/dev/zero of=src/foo seek="$data_size" bs=1 count=1
96 WVPASS echo "end" >> src/foo
98 WVPASS bup save -n src src
100 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
101 restore_size=$(WVPASS du -k -s restore/src/foo | WVPASS cut -f1) || exit $?
102 WVPASS [ "$restore_size" -le "$((5 * (block_size / 1024)))" ]
103 WVPASS "$top/t/compare-trees" -c src/ restore/src/
105 WVSTART "sparse file restore --sparse (sparse start and end)"
106 WVPASS dd if=/dev/zero of=src/foo seek="$data_size" bs=1 count=1
107 WVPASS echo "middle" >> src/foo
108 WVPASS dd if=/dev/zero of=src/foo seek=$((2 * data_size)) bs=1 count=1 conv=notrunc
110 WVPASS bup save -n src src
112 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
113 restore_size=$(WVPASS du -k -s restore/src/foo | WVPASS cut -f1) || exit $?
114 WVPASS [ "$restore_size" -le "$((5 * (block_size / 1024)))" ]
115 WVPASS "$top/t/compare-trees" -c src/ restore/src/
117 if test "$block_size" -gt $mb; then
118 random_size="$block_size"
122 WVSTART "sparse file restore --sparse (random $random_size)"
123 WVPASS bup random --seed "$RANDOM" 1M > src/foo
125 WVPASS bup save -n src src
127 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
128 WVPASS "$top/t/compare-trees" -c src/ restore/src/
130 WVSTART "sparse file restore --sparse (random sparse regions)"
131 WVPASS rm -rf "$BUP_DIR" src
134 for sparse_dataset in 0 1 2 3 4 5 6 7 8 9
136 WVPASS "$top/t/sparse-test-data" "src/foo-$sparse_dataset"
139 WVPASS bup save -n src src
141 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
142 WVPASS "$top/t/compare-trees" -c src/ restore/src/
144 WVSTART "sparse file restore --sparse (short zero runs around boundary)"
145 WVPASS bup-cfg-py > src/foo <<EOF
146 from sys import stdout
147 stdout.write("x" * 65535 + "\0")
148 stdout.write("\0" + "x" * 65535)
149 stdout.write("\0" + "x" * 65534 + "\0")
150 stdout.write("x" * 65536)
154 WVPASS bup save -n src src
156 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
157 WVPASS "$top/t/compare-trees" -c src/ restore/src/
160 WVPASS rm -rf "$tmpdir"