5 # Test that src and dest trees are as identical as bup is capable of
6 # making them. For now, use rsync -niaHAX ...
10 Usage: compare-trees [-h] [-c] [-x] SOURCE DEST
15 Check file content (default)
17 Don't check file content (rely on size/timestamps, etc.)
21 verify_content=" --checksum"
23 while getopts "hcx" OPTION
27 c) verify_content=" --checksum";;
28 x) verify_content="";;
29 ?) usage 1>&2; exit 1;;
33 shift $(($OPTIND - 1)) || exit $?
44 tmpfile="$(mktemp /tmp/bup-test-XXXXXXX)" || exit $?
45 trap "rm -rf '$tmpfile'" EXIT || exit $?
47 rsync_opts="-niaH$verify_content --delete"
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
55 echo "Not comparing ACLs (not yet supported on $OSTYPE)" 1>&2
58 rsync_opts="$rsync_opts -A"
64 if [[ ! "$rsync_version" =~ "xattrs" ]] || [[ "$rsync_version" =~ "no xattrs" ]]; then
65 echo "Not comparing xattrs (not supported by available rsync)" 1>&2
70 # Even in dry-run mode, rsync may fail if -X is specified and the
71 # filesystems don't support xattrs.
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 $?
80 rsync $rsync_opts "$src" "$dest" > "$tmpfile" || exit $?
83 if test $(wc -l < "$tmpfile") != 0; then
84 echo "Differences between $src and $dest" 1>&2