-
Notifications
You must be signed in to change notification settings - Fork 12
/
timediff
executable file
·87 lines (81 loc) · 2.75 KB
/
timediff
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
#!/bin/bash
#
# Copyright (c) 2009 Nathan Fiedler
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# $Id$
#
######################################################################
#
# Given two supposedly identical Time Machine volumes, run the timedog
# script on each backup (e.g. 2008-02-19-005705) in both volumes and
# compare the output to determine that they are indeed truly identical.
#
# Usage: sudo timediff.sh /usr/local/bin/timedog \
# /Volume/OldBackup/Backups.backupdb/hostname \
# /Volume/NewBackup/Backups.backupdb/hostname
#
# You must supply the path to the timedog script as the first argument
# to this script, and the paths to the old and new Time Machine volumes,
# including the host name of the backups to compare. Run the 'hostname'
# command in the Terminal to get the name of your machine.
#
# Typically must be run with sudo to visit certain directories, otherwise
# you will get false negatives.
#
######################################################################
[ -z "$1" ] && echo "Missing path to timedog script!" && exit 3
if [ ! -x "$1" ]; then
echo "$1 must exist and be executable!"
exit 3
fi
TIMEDOG=$1
[ -z "$2" ] && echo "Missing required source path!" && exit 3
SRC=`echo $2 | sed -e 's|/$||'`
[ -z "$3" ] && echo "Missing required target path!" && exit 3
TGT=`echo $3 | sed -e 's|/$||'`
PWD=`pwd`
SCRIPT=`basename $0`
TMP1=`mktemp -t ${SCRIPT}`
if [ $? != 0 ]; then
echo "Failed to create temporary file!"
exit 1
fi
TMP2=`mktemp -t ${SCRIPT}`
if [ $? != 0 ]; then
echo "Failed to create temporary file!"
exit 1
fi
# Get all of the snapshots, except the first one, and the other cruft.
# We trust that ls sorts the entries for us, as stated in the man page.
for SNAP in `ls $SRC | egrep -v '(Latest|*.inProgress)' | sed -e '1d'`; do
if [ ! -d "$TGT/$SNAP" ]; then
echo "$SNAP missing in $TGT location!"
exit
fi
echo "Processing $SNAP, please be patient..."
cd $SRC
$TIMEDOG $SNAP > $TMP1
cd $TGT
$TIMEDOG $SNAP > $TMP2
diff -q $TMP1 $TMP2
if [ $? = 1 ]; then
echo "$SNAP differs between $SRC and $TGT!"
exit 2
fi
done
cd $PWD
rm -f $TMP1
rm -f $TMP2