Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement