]> arthur.barton.de Git - bup.git/blob - t/test-sparse-files.sh
d57b5913d8cfc78c231306a2797619d604bc7cc2
[bup.git] / t / test-sparse-files.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
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 (bracketed zero run in buf)"
73 WVPASS echo 'x' > src/foo
74 WVPASS dd if=/dev/zero bs=1 count=512 >> src/foo
75 WVPASS echo 'y' >> 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 WVPASS "$top/t/compare-trees" -c src/ restore/src/
81
82 WVSTART "sparse file restore --sparse (sparse start)"
83 WVPASS dd if=/dev/zero of=src/foo seek=$mb bs=1 count=1
84 WVPASS echo "end" >> src/foo
85 WVPASS bup index src
86 WVPASS bup save -n src src
87 WVPASS rm -r restore
88 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
89 restore_size=$(WVPASS du -k -s restore | WVPASS cut -f1) || exit $?
90 WVPASS [ "$restore_size" -lt 100 ]
91 WVPASS "$top/t/compare-trees" -c src/ restore/src/
92
93 WVSTART "sparse file restore --sparse (sparse start and end)"
94 WVPASS dd if=/dev/zero of=src/foo seek=$mb bs=1 count=1
95 WVPASS echo "middle" >> src/foo
96 WVPASS dd if=/dev/zero of=src/foo seek=$((2 * mb)) bs=1 count=1 conv=notrunc
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" -lt 100 ]
103 WVPASS "$top/t/compare-trees" -c src/ restore/src/
104
105 WVSTART "sparse file restore --sparse (random)"
106 WVPASS bup random 512k > src/foo
107 WVPASS bup index src
108 WVPASS bup save -n src src
109 WVPASS rm -r restore
110 WVPASS bup restore --sparse -C restore "src/latest/$(pwd)/"
111 WVPASS "$top/t/compare-trees" -c src/ restore/src/
112
113 WVPASS rm -rf "$tmpdir"