Save the script as a *.sh file, add execute permissions (chmod u+x <file>.sh), then mount your sparsebundle location. In Terminal, type "cd " then drag the folder containing your sparsebundle into the Terminal window, resulting in "cd <path to bundle>", and press enter. Now drag the script file into the window, and press enter again.
The script should begin, checking the bundle for common problems, but halting on error. I do not make any promises with this script, use at your own discretion.
#!/bin/bash
set -e
sprs=`ls -d *.sparsebundle 2>/dev/null | head -1`
if [ ! $sprs ]; then echo "No sparsebundle found…exiting";exit 1;fi
echo -n "Making metadata changes..."
chflags nouchg $sprs/token
defaults write $PWD/$sprs/com.apple.TimeMachine.MachineID VerificationState -int 0
defaults delete $PWD/$sprs/com.apple.TimeMachine.MachineID RecoveryBackupDeclinedDate
echo "Done"
echo -n "Soft-mounting bundle..."
disks=`hdiutil attach -nomount -noverify -noautofsck $sprs | awk '{print $1}'`
disk=`echo $disks | awk '{print $1}'`
echo -n "Done"
echo "Starting Disk Repair as root..."
sudo fsck_hfs -df /dev/$disk's2'
echo -n "Detaching..."
hdiutil detach $disk
echo "Done"
echo "Script Complete"--edit
The Applescript
try
display dialog "This script will prompt you for the sparsebundle location, then open a new TextEdit document with \"live\" output. Do not close it until the script is complete. You will be prompted for the administrator password for repairs." with icon stop
on error
return
end try
set mount to POSIX path of (choose file of type "com.apple.disk-image-sparse-bundle" with prompt "Select the affected sparsebundle")
set dname to "Repair Output " & (do shell script "date +%Y%m%d%H%M%S")
tell application "System Events" to set runs to (name of processes) contains "TextEdit"
tell application "TextEdit"
activate
if runs then
set doc to make new document with properties {name:dname}
else
set name of first document to dname
set doc to first document
end if
end tell
set dname to quoted form of dname
append(doc, "Processing " & mount)
set mount to quoted form of mount
append(doc, "Turning off TimeMachine: " & (do shell script "defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -bool no 2>&1" with administrator privileges))
append(doc, "Making Metadata changes...")
append(doc, "chflags: " & (do shell script "chflags nouchg " & mount & " " & mount & "token 2>&1"))
append(doc, "VerificationState: " & (do shell script "defaults write " & mount & "com.apple.TimeMachine.MachineID VerificationState -int 0 2>&1"))
append(doc, "RecoveryBackupDeclinedDate: " & (do shell script "defaults delete " & mount & "com.apple.TimeMachine.MachineID RecoveryBackupDeclinedDate 2>&1 || true"))
append(doc, "Soft-mounting bundle...")
set disks to do shell script "hdiutil attach -nomount -noverify -noautofsck " & mount & " 2>&1"
append(doc, disks)
activate
append(doc, "Stopping autofsck: " & (do shell script "killall fsck_hfs 2>&1 || true" with administrator privileges))
set disks to quoted form of (do shell script "echo " & quoted form of disks & " | awk '{print $1}'")
set disk to quoted form of (do shell script "echo " & disks & " | awk '{print $1}'")
append(doc, "Starting Disk Repair as root...")
do shell script "dname=" & dname & ";osascript -e \"tell application \\\"TextEdit\\\" to activate\";fsck_hfs -gdf " & disk & "s2 2>&1 | while read line; do line=`echo $line|cut -f2 -d\\\"|tr -d \"()\"`;osascript -e \"tell application \\\"TextEdit\\\" to make new paragraph at end of (get first document whose name is \\\"$dname\\\") with data \\\"$line\\\"&return\";done" with administrator privileges
append(doc, "Detaching...")
append(doc, do shell script "hdiutil detach " & disk & " 2>&1")
append(doc, "Renaming: " & (do shell script "mount=" & mount & ";mount1=`echo $mount | perl -p -e \"s/_\\d{4}-\\d{2}-\\d{2}-\\d{6}//\"`;if [ \"$mount\" != \"$mount1\" ]; then mv $mount $mount1;fi"))
append(doc, "Turning on TimeMachine: " & (do shell script "defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -bool yes 2>&1" with administrator privileges))
tell application "TextEdit" to make new paragraph at end of doc with data "Script Complete"
on append(doc1, txt1)
tell application "TextEdit" to make new paragraph at end of doc1 with data txt1 & return
end append









Contributor
Back to top








