Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #!/bin/bash
  2. # Mount a network time machine sparsebunble who's claimed to have gotten corrupt and no longer backs up.
  3. # I do this from a different mac than the one doing the backups.
  4.  
  5. if [[ $(whoami) != 'root' ]]; then
  6. echo "Must be run as root, dude."
  7. exit 1
  8. fi
  9.  
  10. read -p 'Enter path of TimeMachine Server (i.e. 123.45.6.7/TimeMachine): ' TM_PATH
  11. read -p 'Enter sparsebundle name: ' TM_NAME
  12. read -p 'Enter Username: ' USERNAME
  13. read -s -p 'Enter Password: ' PASSWORD
  14.  
  15. echo " "
  16. echo "For encrypted backups you will be asked for the password to the disk after chflags is run"
  17. echo " "
  18. echo "---------------------"
  19.  
  20. MOUNT=/Volumes/TimeMachine
  21. SPARSEBUNDLE="$MOUNT"/"$TM_NAME".sparsebundle
  22. PLIST="$SPARSEBUNDLE"/com.apple.TimeMachine.MachineID.plist
  23.  
  24. echo "Mounting volume"
  25. mkdir "$MOUNT"
  26. mount_afp afp://"$USERNAME":"$PASSWORD"@"$TM_PATH" "$MOUNT"
  27.  
  28. echo "Changing file and folder flags. This can take some time..."
  29. chflags -R nouchg "$SPARSEBUNDLE"
  30.  
  31. echo "Attaching sparse bundle"
  32. DISK=`hdiutil attach -nomount -readwrite -noverify -noautofsck "$SPARSEBUNDLE" | grep Apple_HFS | cut -f 1`
  33.  
  34. echo "$DISK"
  35.  
  36. echo "Repairing volume. This WILL take some time..."
  37. #diskutil repairVolume $DISK
  38. /sbin/fsck_hfs -p "$DISK"
  39. /sbin/fsck_hfs -fry "$DISK"
  40.  
  41. echo "Fixing Properties"
  42. cp "$PLIST" "$PLIST.backup"
  43. sed -e '/RecoveryBackupDeclinedDate/{N;d;}' \
  44. -e '/VerificationState/{n;s/2/0/;}' \
  45. "$PLIST.backup" \
  46. > "$PLIST"
  47.  
  48. echo "Unmounting volumes"
  49. hdiutil detach /dev/"$DISK"
  50. umount "$MOUNT"
  51.  
  52. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement