]> arthur.barton.de Git - bup.git/blob - t/test-save-restore-excludes.sh
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / t / test-save-restore-excludes.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . t/lib.sh || exit $?
4
5 set -o pipefail
6
7 top="$(WVPASS pwd)" || exit $?
8 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
18 WVSTART "index excludes bupdir"
19 WVPASS force-delete src "$BUP_DIR"
20 WVPASS bup init
21 WVPASS mkdir src
22 WVPASS touch src/a
23 WVPASS bup random 128k >src/b
24 WVPASS mkdir src/d src/d/e
25 WVPASS bup random 512 >src/f
26 WVPASS bup index -ux src
27 WVPASS bup save -n exclude-bupdir src
28 WVPASSEQ "$(bup ls -AF "exclude-bupdir/latest/$tmpdir/src/")" "a
29 b
30 d/
31 f"
32
33
34 WVSTART "index --exclude"
35 WVPASS force-delete src "$BUP_DIR"
36 WVPASS bup init
37 WVPASS mkdir src
38 WVPASS touch src/a
39 WVPASS bup random 128k >src/b
40 WVPASS mkdir src/d src/d/e
41 WVPASS bup random 512 >src/f
42 WVPASS bup random 512 >src/j
43 WVPASS bup index -ux --exclude src/d --exclude src/j src
44 WVPASS bup save -n exclude src
45 WVPASSEQ "$(bup ls "exclude/latest/$tmpdir/src/")" "a
46 b
47 f"
48 WVPASS mkdir src/g src/h
49 WVPASS bup index -ux --exclude src/d --exclude $tmpdir/src/g --exclude src/h \
50     --exclude "$tmpdir/src/j" src
51 WVPASS bup save -n exclude src
52 WVPASSEQ "$(bup ls "exclude/latest/$tmpdir/src/")" "a
53 b
54 f"
55
56
57 WVSTART "index --exclude-from"
58 WVPASS force-delete src "$BUP_DIR"
59 WVPASS bup init
60 WVPASS mkdir src
61 WVPASS echo "src/d
62  $tmpdir/src/g
63 src/h
64 src/i" > exclude-list
65 WVPASS touch src/a
66 WVPASS bup random 128k >src/b
67 WVPASS mkdir src/d src/d/e
68 WVPASS bup random 512 >src/f
69 WVPASS mkdir src/g src/h
70 WVPASS bup random 128k > src/i
71 WVPASS bup index -ux --exclude-from exclude-list src
72 WVPASS bup save -n exclude-from src
73 WVPASSEQ "$(bup ls "exclude-from/latest/$tmpdir/src/")" "a
74 b
75 f"
76 WVPASS rm exclude-list
77
78
79 # bup index --exclude-rx ...
80 # ==========================
81
82 WVSTART "index --exclude-rx '^/foo' (root anchor)"
83 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
84 WVPASS bup init
85 WVPASS mkdir src
86 WVPASS touch src/a
87 WVPASS touch src/b
88 WVPASS mkdir src/sub1
89 WVPASS mkdir src/sub2
90 WVPASS touch src/sub1/a
91 WVPASS touch src/sub2/b
92 WVPASS bup index -u src --exclude-rx "^$(pwd)/src/sub1/"
93 WVPASS bup save --strip -n bupdir src
94 WVPASS bup restore -C buprestore.tmp /bupdir/latest/
95 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
96 WVPASSEQ "$actual" ".
97 ./a
98 ./b
99 ./sub2
100 ./sub2/b"
101
102 WVSTART "index --exclude-rx '/foo$' (non-dir, tail anchor)"
103 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
104 WVPASS bup init
105 WVPASS mkdir src
106 WVPASS touch src/a
107 WVPASS touch src/b
108 WVPASS touch src/foo
109 WVPASS mkdir src/sub
110 WVPASS mkdir src/sub/foo
111 WVPASS touch src/sub/foo/a
112 WVPASS bup index -u src --exclude-rx '/foo$'
113 WVPASS bup save --strip -n bupdir src
114 WVPASS bup restore -C buprestore.tmp /bupdir/latest/
115 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
116 WVPASSEQ "$actual" ".
117 ./a
118 ./b
119 ./sub
120 ./sub/foo
121 ./sub/foo/a"
122
123 WVSTART "index --exclude-rx '/foo/$' (dir, tail anchor)"
124 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
125 WVPASS bup init
126 WVPASS mkdir src
127 WVPASS touch src/a
128 WVPASS touch src/b
129 WVPASS touch src/foo
130 WVPASS mkdir src/sub
131 WVPASS mkdir src/sub/foo
132 WVPASS touch src/sub/foo/a
133 WVPASS bup index -u src --exclude-rx '/foo/$'
134 WVPASS bup save --strip -n bupdir src
135 WVPASS bup restore -C buprestore.tmp /bupdir/latest/
136 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
137 WVPASSEQ "$actual" ".
138 ./a
139 ./b
140 ./foo
141 ./sub"
142
143 WVSTART "index --exclude-rx '/foo/.' (dir content)"
144 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
145 WVPASS bup init
146 WVPASS mkdir src
147 WVPASS touch src/a
148 WVPASS touch src/b
149 WVPASS touch src/foo
150 WVPASS mkdir src/sub
151 WVPASS mkdir src/sub/foo
152 WVPASS touch src/sub/foo/a
153 WVPASS bup index -u src --exclude-rx '/foo/.'
154 WVPASS bup save --strip -n bupdir src
155 WVPASS bup restore -C buprestore.tmp /bupdir/latest/
156 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
157 WVPASSEQ "$actual" ".
158 ./a
159 ./b
160 ./foo
161 ./sub
162 ./sub/foo"
163
164
165 # bup index --exclude-rx-from ...
166 # ===============================
167 WVSTART "index --exclude-rx-from"
168 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
169 WVPASS bup init
170 WVPASS mkdir src
171 WVPASS touch src/a
172 WVPASS touch src/b
173 WVPASS mkdir src/sub1
174 WVPASS mkdir src/sub2
175 WVPASS touch src/sub1/a
176 WVPASS touch src/sub2/b
177 # exclude-rx-file includes blank lines to check that we ignore them.
178 WVPASS echo "^$(pwd)/src/sub1/
179
180 " > exclude-rx-file
181 WVPASS bup index -u src --exclude-rx-from exclude-rx-file
182 WVPASS bup save --strip -n bupdir src
183 WVPASS bup restore -C buprestore.tmp /bupdir/latest/
184 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
185 WVPASSEQ "$actual" ".
186 ./a
187 ./b
188 ./sub2
189 ./sub2/b"
190
191
192 # bup restore --exclude-rx ...
193 # ============================
194
195 WVSTART "restore --exclude-rx '^/foo' (root anchor)"
196 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
197 WVPASS bup init
198 WVPASS mkdir src
199 WVPASS touch src/a
200 WVPASS touch src/b
201 WVPASS mkdir src/sub1
202 WVPASS mkdir src/sub2
203 WVPASS touch src/sub1/a
204 WVPASS touch src/sub2/b
205 WVPASS bup index -u src
206 WVPASS bup save --strip -n bupdir src
207 WVPASS bup restore -C buprestore.tmp --exclude-rx "^/sub1/" /bupdir/latest/
208 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
209 WVPASSEQ "$actual" ".
210 ./a
211 ./b
212 ./sub2
213 ./sub2/b"
214
215 WVSTART "restore --exclude-rx '/foo$' (non-dir, tail anchor)"
216 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
217 WVPASS bup init
218 WVPASS mkdir src
219 WVPASS touch src/a
220 WVPASS touch src/b
221 WVPASS touch src/foo
222 WVPASS mkdir src/sub
223 WVPASS mkdir src/sub/foo
224 WVPASS touch src/sub/foo/a
225 WVPASS bup index -u src
226 WVPASS bup save --strip -n bupdir src
227 WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo$' /bupdir/latest/
228 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
229 WVPASSEQ "$actual" ".
230 ./a
231 ./b
232 ./sub
233 ./sub/foo
234 ./sub/foo/a"
235
236 WVSTART "restore --exclude-rx '/foo/$' (dir, tail anchor)"
237 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
238 WVPASS bup init
239 WVPASS mkdir src
240 WVPASS touch src/a
241 WVPASS touch src/b
242 WVPASS touch src/foo
243 WVPASS mkdir src/sub
244 WVPASS mkdir src/sub/foo
245 WVPASS touch src/sub/foo/a
246 WVPASS bup index -u src
247 WVPASS bup save --strip -n bupdir src
248 WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo/$' /bupdir/latest/
249 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
250 WVPASSEQ "$actual" ".
251 ./a
252 ./b
253 ./foo
254 ./sub"
255
256 WVSTART "restore --exclude-rx '/foo/.' (dir content)"
257 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
258 WVPASS bup init
259 WVPASS mkdir src
260 WVPASS touch src/a
261 WVPASS touch src/b
262 WVPASS touch src/foo
263 WVPASS mkdir src/sub
264 WVPASS mkdir src/sub/foo
265 WVPASS touch src/sub/foo/a
266 WVPASS bup index -u src
267 WVPASS bup save --strip -n bupdir src
268 WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo/.' /bupdir/latest/
269 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
270 WVPASSEQ "$actual" ".
271 ./a
272 ./b
273 ./foo
274 ./sub
275 ./sub/foo"
276
277
278 # bup restore --exclude-rx-from ...
279 # =================================
280
281 WVSTART "restore --exclude-rx-from"
282 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
283 WVPASS bup init
284 WVPASS mkdir src
285 WVPASS touch src/a
286 WVPASS touch src/b
287 WVPASS mkdir src/sub1
288 WVPASS mkdir src/sub2
289 WVPASS touch src/sub1/a
290 WVPASS touch src/sub2/b
291 WVPASS bup index -u src
292 WVPASS bup save --strip -n bupdir src
293 WVPASS echo "^/sub1/" > exclude-rx-file
294 WVPASS bup restore -C buprestore.tmp \
295     --exclude-rx-from exclude-rx-file /bupdir/latest/
296 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
297 WVPASSEQ "$actual" ".
298 ./a
299 ./b
300 ./sub2
301 ./sub2/b"
302
303 WVPASS rm -rf "$tmpdir"