]> arthur.barton.de Git - bup.git/blob - t/test-save-restore
Move test.sh save/restore tests to test-save-restore
[bup.git] / t / test-save-restore
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . wvtest-bup.sh
4 . t/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 WVPASS cd "$tmpdir"
15
16 WVSTART "init"
17
18 WVPASS bup init
19
20 D=bupdata.tmp
21 WVPASS force-delete $D
22 WVPASS mkdir $D
23 WVPASS touch $D/a
24 WVPASS bup random 128k >$D/b
25 WVPASS mkdir $D/d $D/d/e
26 WVPASS bup random 512 >$D/f
27 WVPASS touch $D/d/z
28 WVPASS touch $D/d/z
29 WVPASS bup index $D
30 WVPASS bup save -t $D
31
32 WVSTART "restore"
33 WVPASS force-delete buprestore.tmp
34 WVFAIL bup restore boink
35 WVPASS touch "$tmpdir/$D/$D"
36 WVPASS bup index -u "$tmpdir/$D"
37 WVPASS bup save -n master /
38 WVPASS bup restore -C buprestore.tmp "/master/latest/$tmpdir/$D"
39 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
40 WVPASS force-delete buprestore.tmp
41 WVPASS bup restore -C buprestore.tmp "/master/latest/$tmpdir/$D/"
42 WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
43 WVPASS diff -ur $D/ buprestore.tmp/
44 WVPASS force-delete buprestore.tmp
45 WVPASS echo -n "" | WVPASS bup split -n split_empty_string.tmp
46 WVPASS bup restore -C buprestore.tmp split_empty_string.tmp/latest/
47 WVPASSEQ "$(cat buprestore.tmp/data)" ""
48
49 (
50     tmp=testrestore.tmp
51     WVPASS force-delete $tmp
52     WVPASS mkdir $tmp
53     export BUP_DIR="$(pwd)/$tmp/bup"
54     WVPASS WVPASS bup init
55     WVPASS mkdir -p $tmp/src/x/y/z
56     WVPASS bup random 8k > $tmp/src/x/y/random-1
57     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
58     WVPASS bup index -u $tmp/src
59     WVPASS bup save --strip -n foo $tmp/src
60
61     WVSTART "restore /foo/latest"
62     WVPASS bup restore -C $tmp/restore /foo/latest
63     WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/latest/
64
65     WVSTART "restore /foo/latest/"
66     WVPASS force-delete "$tmp/restore"
67     WVPASS bup restore -C $tmp/restore /foo/latest/
68     for x in $tmp/src/*; do
69         WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
70     done
71
72     WVSTART "restore /foo/latest/."
73     WVPASS force-delete "$tmp/restore"
74     WVPASS bup restore -C $tmp/restore /foo/latest/.
75     WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/
76
77     WVSTART "restore /foo/latest/x"
78     WVPASS force-delete "$tmp/restore"
79     WVPASS bup restore -C $tmp/restore /foo/latest/x
80     WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/x/
81
82     WVSTART "restore /foo/latest/x/"
83     WVPASS force-delete "$tmp/restore"
84     WVPASS bup restore -C $tmp/restore /foo/latest/x/
85     for x in $tmp/src/x/*; do
86         WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
87     done
88
89     WVSTART "restore /foo/latest/x/."
90     WVPASS force-delete "$tmp/restore"
91     WVPASS bup restore -C $tmp/restore /foo/latest/x/.
92     WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/
93 ) || exit $?
94
95
96 WVSTART "save (no index)"
97 (
98     tmp=save-no-index.tmp
99     WVPASS force-delete $tmp
100     WVPASS mkdir $tmp
101     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
102     WVPASS bup init
103     WVFAIL bup save -n nothing /
104     WVPASS rm -r "$tmp"
105 ) || exit $?
106
107 WVSTART "save disjoint top-level directories"
108 (
109     # Resolve any symlinks involving the top top-level dirs.
110     real_pwd="$(WVPASS resolve-parent .)" || exit $?
111     real_tmp="$(WVPASS resolve-parent /tmp/.)" || exit $?
112     pwd_top="$(echo $real_pwd | WVPASS awk -F "/" '{print $2}')" || exit $?
113     tmp_top="$(echo $real_tmp | WVPASS awk -F "/" '{print $2}')" || exit $?
114
115     if [ "$pwd_top" = "$tmp_top" ]; then
116         echo "(running from within /$tmp_top; skipping test)" 1>&2
117         exit 0
118     fi
119     D=bupdata.tmp
120     WVPASS force-delete $D
121     WVPASS mkdir -p $D/x
122     WVPASS date > $D/x/1
123     tmpdir2="$(WVPASS mktemp -d $real_tmp/bup-test-XXXXXXX)" || exit $?
124     cleanup() { WVPASS rm -r "$tmpdir2"; }
125     WVPASS trap cleanup EXIT
126     WVPASS date > "$tmpdir2/2"
127
128     export BUP_DIR="$tmpdir/bup"
129     WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
130
131     WVPASS bup init
132     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir2"
133     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir2"
134
135     # For now, assume that "ls -a" and "sort" use the same order.
136     actual="$(WVPASS bup ls -AF src/latest)" || exit $?
137     expected="$(echo -e "$pwd_top/\n$tmp_top/" | WVPASS sort)" || exit $?
138     WVPASSEQ "$actual" "$expected"
139 ) || exit $?
140
141 WVPASS rm -rf "$tmpdir"