]> arthur.barton.de Git - bup.git/blob - t/test-sparse-files.sh
restore: add generative --sparse testing
[bup.git] / t / test-sparse-files.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . t/lib.sh || exit $?
4
5 set -o pipefail
6
7 mb=1048576
8 top="$(WVPASS pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 readonly mb top tmpdir
11
12 export BUP_DIR="$tmpdir/bup"
13 export GIT_DIR="$tmpdir/bup"
14
15 bup() { "$top/bup" "$@"; }
16
17 WVPASS cd "$tmpdir"
18
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=$(python -c \
22   "import os; print getattr(os.stat('.'), 'st_blksize', 0) or $mb * 3") \
23     || exit $?
24 data_size=$((block_size * 10))
25 readonly block_size data_size
26
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"
31     exit 0
32 fi
33
34 WVSTART "sparse restore on $(current-filesystem), assuming ${block_size}B blocks"
35
36 WVPASS bup init
37 WVPASS mkdir src
38
39 WVPASS dd if=/dev/zero of=src/foo seek="$data_size" bs=1 count=1
40 WVPASS bup index src
41 WVPASS bup save -n src src
42
43 WVSTART "sparse file restore (all sparse)"
44 WVPASS bup restore -C restore "src/latest/$(pwd)/"
45 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
46 WVPASS [ "$restore_size" -ge "$((data_size / 1024))" ]
47 WVPASS "$top/t/compare-trees" -c src/ restore/src/
48
49 WVSTART "sparse file restore --no-sparse (all sparse)"
50 WVPASS rm -r restore
51 WVPASS bup restore --no-sparse -C restore "src/latest/$(pwd)/"
52 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
53 WVPASS [ "$restore_size" -ge "$((data_size / 1024))" ]
54 WVPASS "$top/t/compare-trees" -c src/ restore/src/
55
56 WVSTART "sparse file restore --sparse (all sparse)"
57 WVPASS rm -r restore
58 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
59 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
60 WVPASS [ "$restore_size" -le "$((3 * (block_size / 1024)))" ]
61 WVPASS "$top/t/compare-trees" -c src/ restore/src/
62
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
66 WVPASS bup index src
67 WVPASS bup save -n src src
68 WVPASS rm -r restore
69 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
70 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
71 WVPASS [ "$restore_size" -le "$((3 * (block_size / 1024)))" ]
72 WVPASS "$top/t/compare-trees" -c src/ restore/src/
73
74 WVSTART "sparse file restore --sparse (sparse middle)"
75 WVPASS echo "end" >> src/foo
76 WVPASS bup index src
77 WVPASS bup save -n src src
78 WVPASS rm -r restore
79 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
80 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
81 WVPASS [ "$restore_size" -le "$((5 * (block_size / 1024)))" ]
82 WVPASS "$top/t/compare-trees" -c src/ restore/src/
83
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
88 WVPASS bup index src
89 WVPASS bup save -n src src
90 WVPASS rm -r restore
91 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
92 WVPASS "$top/t/compare-trees" -c src/ restore/src/
93
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
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 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
102 WVPASS [ "$restore_size" -le "$((5 * (block_size / 1024)))" ]
103 WVPASS "$top/t/compare-trees" -c src/ restore/src/
104
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
109 WVPASS bup index src
110 WVPASS bup save -n src src
111 WVPASS rm -r restore
112 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
113 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
114 WVPASS [ "$restore_size" -le "$((5 * (block_size / 1024)))" ]
115 WVPASS "$top/t/compare-trees" -c src/ restore/src/
116
117 if test "$block_size" -gt $mb; then
118     random_size="$block_size"
119 else
120     random_size=1M
121 fi
122 WVSTART "sparse file restore --sparse (random $random_size)"
123 WVPASS bup random --seed "$RANDOM" 1M > src/foo
124 WVPASS bup index src
125 WVPASS bup save -n src src
126 WVPASS rm -r restore
127 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
128 WVPASS "$top/t/compare-trees" -c src/ restore/src/
129
130 WVSTART "sparse file restore --sparse (random sparse regions)"
131 WVPASS rm -rf "$BUP_DIR" src
132 WVPASS bup init
133 WVPASS mkdir src
134 for sparse_dataset in 0 1 2 3 4 5 6 7 8 9
135 do
136     WVPASS "$top/t/sparse-test-data" "src/foo-$sparse_dataset"
137 done
138 WVPASS bup index src
139 WVPASS bup save -n src src
140 WVPASS rm -r restore
141 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
142 WVPASS "$top/t/compare-trees" -c src/ restore/src/
143
144
145 WVPASS rm -rf "$tmpdir"