]> arthur.barton.de Git - bup.git/blob - t/compare-trees
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / t / compare-trees
1 #!/usr/bin/env bash
2
3 set -u
4
5 # Test that src and dest trees are as identical as bup is capable of
6 # making them.  For now, use rsync -niaHAX ...
7
8 usage() {
9 cat <<EOF
10 Usage: compare-trees [-h] [-c] [-x] SOURCE DEST
11 OPTIONS:
12   -h
13     Display help
14   -c
15     Check file content (default)
16   -x
17     Don't check file content (rely on size/timestamps, etc.)
18 EOF
19 }
20
21 verify_content=" --checksum"
22
23 while getopts "hcx" OPTION
24 do
25     case "$OPTION" in
26         h) usage; exit 0;;
27         c) verify_content=" --checksum";;
28         x) verify_content="";;
29         ?) usage 1>&2; exit 1;;
30     esac
31 done
32
33 shift $(($OPTIND - 1)) || exit $?
34
35 if ! test $# -eq 2
36 then
37     usage 1>&2
38     exit 1
39 fi
40
41 src="$1"
42 dest="$2"
43
44 tmpfile="$(mktemp /tmp/bup-test-XXXXXXX)" || exit $?
45 trap "rm -rf '$tmpfile'" EXIT || exit $?
46
47 rsync_opts="-niaH$verify_content --delete"
48
49 rsync_version=$(rsync --version)
50 if [[ ! "$rsync_version" =~ "ACLs" ]] || [[ "$rsync_version" =~ "no ACLs" ]]; then
51     echo "Not comparing ACLs (not supported by available rsync)" 1>&2
52 else
53     case $OSTYPE in
54         cygwin|darwin|netbsd)
55             echo "Not comparing ACLs (not yet supported on $OSTYPE)" 1>&2
56             ;;
57         *)
58             rsync_opts="$rsync_opts -A"
59             ;;
60     esac
61 fi
62
63 xattrs_available=''
64 if [[ ! "$rsync_version" =~ "xattrs" ]] || [[ "$rsync_version" =~ "no xattrs" ]]; then
65     echo "Not comparing xattrs (not supported by available rsync)" 1>&2
66 else
67     xattrs_available=yes
68 fi
69
70 # Even in dry-run mode, rsync may fail if -X is specified and the
71 # filesystems don't support xattrs.
72
73 if test "$xattrs_available"; then
74     rsync $rsync_opts -X "$src" "$dest" > "$tmpfile"
75     if test $? -ne 0; then
76         # Try again without -X
77         rsync $rsync_opts "$src" "$dest" > "$tmpfile" || exit $?
78     fi
79 else
80     rsync $rsync_opts "$src" "$dest" > "$tmpfile" || exit $?
81 fi
82
83 if test $(wc -l < "$tmpfile") != 0; then
84     echo "Differences between $src and $dest" 1>&2
85     cat "$tmpfile"
86     exit 1
87 fi
88
89 exit 0