Advertisement
Guest User

fix NAS sparsebundle errors script

a guest
Jan 15th, 2014
2,238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.52 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # http://www.garth.org/archives/2011,08,27,169,fix-time-machine-sparsebundle-nas-based-backup-errors.html
  4.  
  5. BUNDLE=???
  6.  
  7. set -e
  8.  
  9. date
  10. echo 'chflags...'
  11. chflags -R nouchg "$BUNDLE/"
  12.  
  13. date
  14. echo 'hdutil...'
  15. DISKS=`hdiutil attach -nomount -noverify -noautofsck "$BUNDLE/"`
  16. echo $DISKS
  17. HFS_DISK=`echo $DISKS | grep Apple_HFS | cut -f 1 | tr -d ' \t'`
  18. echo "identified HFS(X) volume as $HFS_DISK"
  19.  
  20. date
  21. echo 'fsck...'
  22. fsck_hfs -drfy $HFS_DISK
  23. # this was to wait for the log to finish before we ran fsck explicitly, as above
  24. # grep -q 'was repaired successfully|could not be repaired' <(tail -f -n 0 /var/log/fsck_hfs.log)
  25.  
  26. date
  27. echo 'fixing plist...'
  28. cat "$BUNDLE/com.apple.TimeMachine.MachineID.plist" |
  29.   # change VerificationState to zero
  30.   awk 'BEGIN { RS = "" } { gsub(/VerificationState<\/key>[ \t\n]*<integer>2/, "VerificationState</key>\n\t<integer>0"); print }' |
  31.   # remove RecoveryBackupDeclinedDate and write to a temp file
  32.   awk 'BEGIN { RS = "" } { gsub(/[ \t\n]*<key>RecoveryBackupDeclinedDate<\/key>[ \t\n]*<date>[^<]+<\/date>/, ""); print }' > /tmp/fixed-plist.plist
  33.  
  34. # replace the original (don't use mv; it throws weird errors when moving across this disks)
  35. cp /tmp/fixed-plist.plist "$BUNDLE/com.apple.TimeMachine.MachineID.plist"
  36. rm /tmp/fixed-plist.plist
  37.  
  38. date
  39. echo 'done!'
  40. echo 'eject the disk from your desktop if necessary, then rerun Time Machine'
  41.  
  42. # this command will tell you who's using the disk, if ejecting is a problem:
  43. # sudo lsof -xf +d /Volumes/disk<?> # or possibly just $BUNDLE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement