]> arthur.barton.de Git - bup.git/blob - t/test-save-strip-graft.sh
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / t / test-save-strip-graft.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 compare-trees() { "$top/t/compare-trees" "$@"; }
15
16 WVPASS cd "$tmpdir"
17
18
19 WVSTART "save --strip"
20 WVPASS force-delete "$BUP_DIR" src restore
21 WVPASS bup init
22 WVPASS mkdir -p src/x/y/z
23 WVPASS bup random 8k > src/x/y/random-1
24 WVPASS bup random 8k > src/x/y/z/random-2
25 WVPASS bup index -u src
26 WVPASS bup save --strip -n foo src/x/y
27 WVPASS bup restore -C restore /foo/latest
28 WVPASS compare-trees src/x/y/ restore/latest/
29
30
31 WVSTART "save --strip-path (relative)"
32 WVPASS force-delete "$BUP_DIR" src restore
33 WVPASS bup init
34 WVPASS mkdir -p src/x/y/z
35 WVPASS bup random 8k > src/x/y/random-1
36 WVPASS bup random 8k > src/x/y/z/random-2
37 WVPASS bup index -u src
38 WVPASS bup save --strip-path src -n foo src/x
39 WVPASS bup restore -C restore /foo/latest
40 WVPASS compare-trees src/ restore/latest/
41
42
43 WVSTART "save --strip-path (absolute)"
44 WVPASS force-delete "$BUP_DIR" src restore
45 WVPASS bup init
46 WVPASS mkdir -p src/x/y/z
47 WVPASS bup random 8k > src/x/y/random-1
48 WVPASS bup random 8k > src/x/y/z/random-2
49 WVPASS bup index -u src
50 WVPASS bup save --strip-path "$tmpdir" -n foo src
51 WVPASS bup restore -C restore /foo/latest
52 WVPASS compare-trees src/ "restore/latest/src/"
53
54
55 WVSTART "save --strip-path (no match)"
56 if test $(WVPASS path-filesystems . | WVPASS sort -u | WVPASS wc -l) -ne 1
57 then
58     # Skip the test because the attempt to restore parent dirs to the
59     # current filesystem may fail -- i.e. running from
60     # /foo/ext4/bar/btrfs will fail when bup tries to restore linux
61     # attrs above btrfs to the restore tree *inside* btrfs.
62     # FIXME: add WVSKIP
63     echo "(running from tree with mixed filesystems; skipping test)" 1>&2
64     exit 0
65 else
66     WVPASS force-delete "$BUP_DIR" src restore
67     WVPASS bup init
68     WVPASS mkdir -p src/x/y/z
69     WVPASS bup random 8k > src/x/y/random-1
70     WVPASS bup random 8k > src/x/y/z/random-2
71     WVPASS bup index -u src
72     WVPASS bup save --strip-path foo -n foo src/x
73     WVPASS bup restore -C restore /foo/latest
74     WVPASS compare-trees src/ "restore/latest/$tmpdir/src/"
75 fi
76
77
78 WVSTART "save --graft (empty graft points disallowed)"
79 WVPASS force-delete "$BUP_DIR" src restore
80 WVPASS bup init
81 WVPASS mkdir src
82 WVFAIL bup save --graft =/grafted -n graft-point-absolute src 2>&1 \
83     | WVPASS grep 'error: a graft point cannot be empty'
84 WVFAIL bup save --graft $top/$tmp= -n graft-point-absolute src 2>&1 \
85     | WVPASS grep 'error: a graft point cannot be empty'
86
87
88 WVSTART "save --graft /x/y=/a/b (relative paths)"
89 WVPASS force-delete "$BUP_DIR" src restore
90 WVPASS bup init
91 WVPASS mkdir -p src/x/y/z
92 WVPASS bup random 8k > src/x/y/random-1
93 WVPASS bup random 8k > src/x/y/z/random-2
94 WVPASS bup index -u src
95 WVPASS bup save --graft src=x -n foo src
96 WVPASS bup restore -C restore /foo/latest
97 WVPASS compare-trees src/ "restore/latest/$tmpdir/x/"
98
99
100 WVSTART "save --graft /x/y=/a/b (matching structure)"
101 WVPASS force-delete "$BUP_DIR" src restore
102 WVPASS bup init
103 WVPASS mkdir -p src/x/y/z
104 WVPASS bup random 8k > src/x/y/random-1
105 WVPASS bup random 8k > src/x/y/z/random-2
106 WVPASS bup index -u src
107 WVPASS bup save -v --graft "$tmpdir/src/x/y=$tmpdir/src/a/b" -n foo src/x/y
108 WVPASS bup restore -C restore /foo/latest
109 WVPASS compare-trees src/x/y/ "restore/latest/$tmpdir/src/a/b/"
110
111
112 WVSTART "save --graft /x/y=/a (shorter target)"
113 WVPASS force-delete "$BUP_DIR" src restore
114 WVPASS bup init
115 WVPASS mkdir -p src/x/y/z
116 WVPASS bup random 8k > src/x/y/random-1
117 WVPASS bup random 8k > src/x/y/z/random-2
118 WVPASS bup index -u src
119 WVPASS bup save -v --graft "$tmpdir/src/x/y=/a" -n foo src/x/y
120 WVPASS bup restore -C restore /foo/latest
121 WVPASS compare-trees src/x/y/ "restore/latest/a/"
122
123
124 WVSTART "save --graft /x=/a/b (longer target)"
125 WVPASS force-delete "$BUP_DIR" src restore
126 WVPASS bup init
127 WVPASS mkdir -p src/x/y/z
128 WVPASS bup random 8k > src/x/y/random-1
129 WVPASS bup random 8k > src/x/y/z/random-2
130 WVPASS bup index -u src
131 WVPASS bup save -v --graft "$tmpdir/src=$tmpdir/src/a/b/c" -n foo src
132 WVPASS bup restore -C restore /foo/latest
133 WVPASS compare-trees src/ "restore/latest/$tmpdir/src/a/b/c/"
134
135
136 WVSTART "save --graft /x=/ (root target)"
137 WVPASS force-delete "$BUP_DIR" src restore
138 WVPASS bup init
139 WVPASS mkdir -p src/x/y/z
140 WVPASS bup random 8k > src/x/y/random-1
141 WVPASS bup random 8k > src/x/y/z/random-2
142 WVPASS bup index -u src
143 WVPASS bup save -v --graft "$tmpdir/src/x=/" -n foo src/x
144 WVPASS bup restore -C restore /foo/latest
145 WVPASS compare-trees src/x/ "restore/latest/"
146
147
148 #WVSTART "save --graft /=/x/ (root source)"
149 # FIXME: Not tested for now -- will require cleverness, or caution as root.
150
151
152 WVSTART "save collision"
153 WVPASS force-delete "$BUP_DIR" src restore
154 WVPASS bup init
155 WVPASS mkdir -p src/x/1 src/y/1
156 WVPASS bup index -u src
157 WVFAIL bup save --strip -n foo src/x src/y 2> tmp-err.log
158 WVPASS grep -F "error: ignoring duplicate path 1 in /" tmp-err.log
159
160
161 WVPASS rm -rf "$tmpdir"