]> arthur.barton.de Git - bup.git/blob - test/ext/test-save-restore
Teach pytest to handle WVSKIP and use it where we can
[bup.git] / test / ext / test-save-restore
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . wvtest-bup.sh
4 . dev/lib.sh
5
6 set -o pipefail
7
8 top="$(WVPASS pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 export BUP_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 validate-local-and-remote-restore()
15 {
16     local src="$1" dest="$2" cmp_src="$3" cmp_dest="$4"
17     force-delete "$dest"
18     WVPASS bup restore -C "$dest" "$src"
19     WVPASS "$top/dev/compare-trees" "$cmp_src" "$cmp_dest"
20     force-delete "$dest"
21     WVPASS bup restore -r ":$BUP_DIR" -C "$dest" "$src"
22     WVPASS "$top/dev/compare-trees" "$cmp_src" "$cmp_dest"
23 }
24
25
26 WVPASS cd "$tmpdir"
27
28 WVSTART "init"
29 WVPASS bup init
30 # Be independent of git defaults or a configured defaultBranch
31 git --git-dir "$BUP_DIR" symbolic-ref HEAD refs/heads/main
32 D=bupdata.tmp
33 WVPASS force-delete $D
34 WVPASS mkdir $D
35 WVPASS touch $D/a
36 WVPASS bup random 128k >$D/b
37 WVPASS mkdir $D/d $D/d/e
38 WVPASS bup random 512 >$D/f
39 WVPASS touch $D/d/z
40 WVPASS touch $D/d/z
41 WVPASS bup index $D
42 WVPASS bup save -t $D
43
44
45 WVSTART "restore"
46 WVPASS force-delete buprestore.tmp
47 WVFAIL bup restore boink
48 WVPASS touch "$tmpdir/$D/$D"
49 WVPASS bup index -u "$tmpdir/$D"
50 WVPASS bup save -n main /
51 WVPASS bup restore -C buprestore.tmp "/main/latest/$tmpdir/$D"
52 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
53 WVPASS force-delete buprestore.tmp
54 WVPASS bup restore -C buprestore.tmp "/main/latest/$tmpdir/$D/"
55 WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
56 WVPASS diff -ur $D/ buprestore.tmp/
57 WVPASS force-delete buprestore.tmp
58 WVPASS echo -n "" | WVPASS bup split -n split_empty_string.tmp
59 WVPASS bup restore -C buprestore.tmp split_empty_string.tmp/latest/
60 WVPASSEQ "$(cat buprestore.tmp/data)" ""
61
62
63 (
64     tmp=testrestore.tmp
65     WVPASS force-delete $tmp
66     WVPASS mkdir $tmp
67     export BUP_DIR="$(pwd)/$tmp/bup"
68     WVPASS WVPASS bup init
69     WVPASS mkdir -p $tmp/src/x/y/z
70     WVPASS bup random 8k > $tmp/src/x/y/random-1
71     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
72     WVPASS bup index -u $tmp/src
73     WVPASS bup save --strip -n foo $tmp/src
74
75     WVSTART "restore /foo/latest"
76     validate-local-and-remote-restore \
77         /foo/latest  "$tmp/restore" \
78         "$tmp/src/" "$tmp/restore/latest/"
79
80     WVSTART "restore /foo/latest/."
81     WVPASS force-delete "$tmp/restore"
82     validate-local-and-remote-restore \
83         /foo/latest/.  "$tmp"/restore \
84         "$tmp"/src/ "$tmp"/restore
85
86     WVSTART "restore /foo/latest/x"
87     WVPASS force-delete "$tmp/restore"
88     validate-local-and-remote-restore \
89         /foo/latest/x  "$tmp"/restore \
90         "$tmp"/src/x/ "$tmp"/restore/x/
91
92     WVSTART "restore /foo/latest/x/"
93     WVPASS force-delete "$tmp/restore"  
94     WVPASS bup restore -C "$tmp"/restore /foo/latest/x/
95     for x in "$tmp"/src/x/*; do
96         WVPASS "$top/dev/compare-trees" "$x/" "$tmp/restore/$(basename $x)"
97     done
98     WVPASS force-delete "$tmp/restore"  
99     WVPASS bup restore -r ":$BUP_DIR" -C "$tmp"/restore /foo/latest/x/
100     for x in "$tmp"/src/x/*; do
101         WVPASS "$top/dev/compare-trees" "$x/" "$tmp/restore/$(basename $x)"
102     done
103
104     WVSTART "restore /foo/latest/x/."
105     WVPASS force-delete "$tmp/restore"
106     validate-local-and-remote-restore \
107         /foo/latest/x/.  "$tmp"/restore \
108         "$tmp"/src/x/ "$tmp"/restore/
109 ) || exit $?
110
111
112 WVSTART "save (no index)"
113 (
114     tmp=save-no-index.tmp
115     WVPASS force-delete $tmp
116     WVPASS mkdir $tmp
117     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
118     WVPASS bup init
119     WVFAIL bup save -n nothing /
120     WVPASS rm -r "$tmp"
121 ) || exit $?
122
123
124 WVSTART "save disjoint top-level directories"
125 (
126     # Resolve any symlinks involving the top top-level dirs.
127     real_pwd="$(WVPASS resolve-parent .)" || exit $?
128     real_tmp="$(WVPASS resolve-parent /tmp/.)" || exit $?
129     pwd_top="$(echo $real_pwd | WVPASS awk -F "/" '{print $2}')" || exit $?
130     tmp_top="$(echo $real_tmp | WVPASS awk -F "/" '{print $2}')" || exit $?
131
132     if [ "$pwd_top" = "$tmp_top" ]; then
133         echo "(running from within /$tmp_top; skipping test)" 1>&2
134         exit 0 # FIXME: allow intermixed WVSKIPs
135     fi
136     D=bupdata.tmp
137     WVPASS force-delete $D
138     WVPASS mkdir -p $D/x
139     WVPASS date > $D/x/1
140     tmpdir2="$(WVPASS mktemp -d $real_tmp/bup-test-XXXXXXX)" || exit $?
141     cleanup() { WVPASS rm -r "$tmpdir2"; }
142     WVPASS trap cleanup EXIT
143     WVPASS date > "$tmpdir2/2"
144
145     export BUP_DIR="$tmpdir/bup"
146     WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
147
148     WVPASS bup init
149     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir2"
150     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir2"
151
152     # For now, assume that "ls -a" and "sort" use the same order.
153     actual="$(WVPASS bup ls -AF src/latest)" || exit $?
154     expected="$(echo -e "$pwd_top/\n$tmp_top/" | WVPASS sort)" || exit $?
155     WVPASSEQ "$actual" "$expected"
156 ) || exit $?
157
158
159 WVPASS cd "$top"
160 WVPASS rm -rf "$tmpdir"