]> arthur.barton.de Git - bup.git/blob - t/test-save-restore-excludes.sh
test-ls.sh: handle Cygwin's coupling of timestamp/permission modifications.
[bup.git] / t / test-save-restore-excludes.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh
3 . t/lib.sh
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 WVPASS echo "^$(pwd)/src/sub1/" > exclude-rx-file
178 WVPASS bup index -u src --exclude-rx-from exclude-rx-file
179 WVPASS bup save --strip -n bupdir src
180 WVPASS bup restore -C buprestore.tmp /bupdir/latest/
181 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
182 WVPASSEQ "$actual" ".
183 ./a
184 ./b
185 ./sub2
186 ./sub2/b"
187
188
189 # bup restore --exclude-rx ...
190 # ============================
191
192 WVSTART "restore --exclude-rx '^/foo' (root anchor)"
193 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
194 WVPASS bup init
195 WVPASS mkdir src
196 WVPASS touch src/a
197 WVPASS touch src/b
198 WVPASS mkdir src/sub1
199 WVPASS mkdir src/sub2
200 WVPASS touch src/sub1/a
201 WVPASS touch src/sub2/b
202 WVPASS bup index -u src
203 WVPASS bup save --strip -n bupdir src
204 WVPASS bup restore -C buprestore.tmp --exclude-rx "^/sub1/" /bupdir/latest/
205 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
206 WVPASSEQ "$actual" ".
207 ./a
208 ./b
209 ./sub2
210 ./sub2/b"
211
212 WVSTART "restore --exclude-rx '/foo$' (non-dir, tail anchor)"
213 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
214 WVPASS bup init
215 WVPASS mkdir src
216 WVPASS touch src/a
217 WVPASS touch src/b
218 WVPASS touch src/foo
219 WVPASS mkdir src/sub
220 WVPASS mkdir src/sub/foo
221 WVPASS touch src/sub/foo/a
222 WVPASS bup index -u src
223 WVPASS bup save --strip -n bupdir src
224 WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo$' /bupdir/latest/
225 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
226 WVPASSEQ "$actual" ".
227 ./a
228 ./b
229 ./sub
230 ./sub/foo
231 ./sub/foo/a"
232
233 WVSTART "restore --exclude-rx '/foo/$' (dir, tail anchor)"
234 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
235 WVPASS bup init
236 WVPASS mkdir src
237 WVPASS touch src/a
238 WVPASS touch src/b
239 WVPASS touch src/foo
240 WVPASS mkdir src/sub
241 WVPASS mkdir src/sub/foo
242 WVPASS touch src/sub/foo/a
243 WVPASS bup index -u src
244 WVPASS bup save --strip -n bupdir src
245 WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo/$' /bupdir/latest/
246 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
247 WVPASSEQ "$actual" ".
248 ./a
249 ./b
250 ./foo
251 ./sub"
252
253 WVSTART "restore --exclude-rx '/foo/.' (dir content)"
254 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
255 WVPASS bup init
256 WVPASS mkdir src
257 WVPASS touch src/a
258 WVPASS touch src/b
259 WVPASS touch src/foo
260 WVPASS mkdir src/sub
261 WVPASS mkdir src/sub/foo
262 WVPASS touch src/sub/foo/a
263 WVPASS bup index -u src
264 WVPASS bup save --strip -n bupdir src
265 WVPASS bup restore -C buprestore.tmp --exclude-rx '/foo/.' /bupdir/latest/
266 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
267 WVPASSEQ "$actual" ".
268 ./a
269 ./b
270 ./foo
271 ./sub
272 ./sub/foo"
273
274
275 # bup restore --exclude-rx-from ...
276 # =================================
277
278 WVSTART "restore --exclude-rx-from"
279 WVPASS rm -rf src "$BUP_DIR" buprestore.tmp
280 WVPASS bup init
281 WVPASS mkdir src
282 WVPASS touch src/a
283 WVPASS touch src/b
284 WVPASS mkdir src/sub1
285 WVPASS mkdir src/sub2
286 WVPASS touch src/sub1/a
287 WVPASS touch src/sub2/b
288 WVPASS bup index -u src
289 WVPASS bup save --strip -n bupdir src
290 WVPASS echo "^/sub1/" > exclude-rx-file
291 WVPASS bup restore -C buprestore.tmp \
292     --exclude-rx-from exclude-rx-file /bupdir/latest/
293 actual="$(WVPASS cd buprestore.tmp; WVPASS find . | WVPASS sort)" || exit $?
294 WVPASSEQ "$actual" ".
295 ./a
296 ./b
297 ./sub2
298 ./sub2/b"
299
300 WVPASS rm -rf "$tmpdir"