Last active
November 15, 2020 22:15
-
-
Save aphor/b60981e45508e21b1d55a01387f4ad41 to your computer and use it in GitHub Desktop.
Rescue a Time Machine backup from a failing readonly volume
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ] || [ -z "$2" ] | |
then | |
echo "ERROR: must supply CLI arguments for source and destination paths" >&2 && | |
exit 1 | |
fi | |
export SRCVOL="$1" | |
export DSTVOL="$2" | |
[ -d "${SRCVOL}/Backups.backupdb" ] || | |
echo -n "$(date) waiting for ${SRCVOL}/Backups.backupdb" && | |
until [ -d "${SRCVOL}/Backups.backupdb" ]; | |
do | |
echo -n . | |
sleep 5; | |
done && | |
echo && echo "$(date) found ${SRCVOL}/Backups.backupdb" | |
[ -z "${TMPDIR}" ] && export TMPDIR="${DSTVOL}/.root.rsync_tm.$RANDOM" | |
([ -d "${TMPDIR}" ] || mkdir -p "${TMPDIR}") && echo "Using temporary directory: ${TMPDIR}" >&2 | |
DATERE='[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}-[[:digit:]]{6}' | |
time \ | |
/System/Library/Extensions/TMSafetyNet.kext/Contents/Helpers/bypass \ | |
ls -d "${SRCVOL}/Backups.backupdb/"* | xargs -n1 -IBKVOL \ | |
find "BKVOL" -maxdepth 1 -type d | egrep "${DATERE}" | sort -n | | |
while read line; do echo "'$line'"; done | | |
( | |
A="" | |
B="" | |
C="" | |
while read qDir | |
do | |
A="$B" | |
B="$qDir" | |
HASHEDKEY="$( echo \#$A\#$B\#$C|md5)" | |
tgtdir="$( echo $A|sed 's:'"${SRCVOL}"'/:'"${DSTVOL}"'/:' )" | |
C="$( dirname "${tgtdir}" )" | |
([ -z "$A" ]||[ -z "$B" ]||[ -z "$C" ]||[ -f "$TMPDIR/$HASHEDKEY.done" ]) || ( | |
echo tmrsync -avvHE --progress --specials \ | |
--temp-dir="$TMPDIR" --partial-dir="$TMPDIR" \ | |
--rsync-path='/var/root/tmrsync' \ | |
"$A" \ | |
"$B" \ | |
"$C/'" | |
) | | |
bash && echo "Success: $A + $B --> $C'" | tee $TMPDIR/$HASHEDKEY.done|| exit $? | |
done | |
) | |
[ "$?" -eq 0 ] && rm -rf "${TMPDIR}" | |
echo "$(date) done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# must be found via PATH for use | |
exec /System/Library/Extensions/TMSafetyNet.kext/Contents/Helpers/bypass /opt/local/bin/rsync $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use macports rsync because Apple + brew is behind.