Last active
March 20, 2017 22:59
-
-
Save krispayne/8b5380b08ab20b100970f001c3f5f0e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Mount a network time machine sparsebunble who's claimed to have gotten corrupt and no longer backs up. | |
# I do this from a different mac than the one doing the backups. | |
if [[ $(whoami) != 'root' ]]; then | |
echo "Must be run as root, dude." | |
exit 1 | |
fi | |
read -p 'Enter path of TimeMachine Server (i.e. 123.45.6.7/TimeMachine): ' TM_PATH | |
read -p 'Enter sparsebundle name: ' TM_NAME | |
read -p 'Enter Username: ' USERNAME | |
read -s -p 'Enter Password: ' PASSWORD | |
echo " " | |
echo "For encrypted backups you will be asked for the password to the disk after chflags is run" | |
echo " " | |
echo "---------------------" | |
MOUNT=/Volumes/TimeMachine | |
SPARSEBUNDLE="$MOUNT"/"$TM_NAME".sparsebundle | |
PLIST="$SPARSEBUNDLE"/com.apple.TimeMachine.MachineID.plist | |
echo "Mounting volume" | |
mkdir "$MOUNT" | |
mount_afp afp://"$USERNAME":"$PASSWORD"@"$TM_PATH" "$MOUNT" | |
echo "Changing file and folder flags. This can take some time..." | |
chflags -R nouchg "$SPARSEBUNDLE" | |
echo "Attaching sparse bundle" | |
DISK=`hdiutil attach -nomount -readwrite -noverify -noautofsck "$SPARSEBUNDLE" | grep Apple_HFS | cut -f 1` | |
echo "$DISK" | |
echo "Repairing volume. This WILL take some time..." | |
#diskutil repairVolume $DISK | |
/sbin/fsck_hfs -p "$DISK" | |
/sbin/fsck_hfs -fry "$DISK" | |
echo "Fixing Properties" | |
cp "$PLIST" "$PLIST.backup" | |
sed -e '/RecoveryBackupDeclinedDate/{N;d;}' \ | |
-e '/VerificationState/{n;s/2/0/;}' \ | |
"$PLIST.backup" \ | |
> "$PLIST" | |
echo "Unmounting volumes" | |
hdiutil detach /dev/"$DISK" | |
umount "$MOUNT" | |
exit 0 |
it also has trouble dismounting sometimes. :-/
diskutil unmountDisk $DISK
hdiutil detach /dev/$DISK
These might be better that the umount commands in the script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has worked reasonably well for me. It's gathered from several different blog posts with steps guiding people how to do it. I should go and find those again to give credit.
When I was committing/sanitizing, I added the
read
for the IP/path to the Time Machine share. I was using a hardcoded value before, but this should work.