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