Nov 10, '09 07:30:00AM • Contributed by: valvoline
on open names set volumeName to names as text set macAddress to (do shell script "ifconfig en0 | grep ether | tr -d '\\011' | sed s/ether// | sed 's/ //g' | sed s/://g") set hostName to (do shell script "hostname -fs") tell application "Finder" set theSize to round (((capacity of startup disk) / 1024 / 1024) / 1024) end tell do shell script "defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1" with administrator privileges do shell script "sudo hdiutil create -size " & theSize & " -type SPARSEBUNDLE -nospotlight -volname \"Backup of " & hostName & "\" -fs \"Journaled HFS+\" ~/" & hostName & "_" & macAddress & ".sparsebundle" with administrator privileges do shell script "mv ~/" & hostName & "_" & macAddress & ".sparsebundle /Volumes/" & volumeName & "/" with administrator privileges tell application "Finder" to eject volumeName tell application "System Preferences" activate end tell tell application "System Events" tell application process "System Preferences" set frontmost to true click menu item "Time Machine" of menu "View" of menu bar 1 end tell end tell end open
After using the script on the drive, open the Time Machine System Preferences panel. Now you should be able to use your network volume as a target disk for Time Machine backups. Read on to find out how to then restore from this disk, assuming you've had a complete hard drive failure and you're starting from scratch with the OS X installation disc...
To restore from your NAS, first insert your Mac OS installation disk and start your Mac. After the installer loads, choose Terminal from the Utilities menu, and mount your external disk. The Installer enables (by default) the DHCP for interface en0; if the NAS is configured for DHCP, then it will get a reachable IP address. To discover that address, try to ping the whole submask using the ping tool:
$ ping 169.254.255.255 PING 169.254.255.255 (169.254.255.255): 56 data bytes 64 bytes from 169.254.101.39: icmp_seq=0 ttl=64 time=0.299 ms 64 bytes from 169.254.101.39: icmp_seq=1 ttl=64 time=0.368 ms 64 bytes from 169.254.101.39: icmp_seq=2 ttl=64 time=0.368 ms --- 169.254.255.255 ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.299/0.345/0.368/0.033 msThe address that responds to your ping (169.254.101.39 in the above example) is the NAS. Let's make a mount point for our disk:
$ mkdir /Volumes/myNASNext, you have to mount the NAS in your freshly created mountpoint:
$ mount -t afp afp://admin:admin@169.254.101.39/myshare /Volumes/myNASBe sure to specify the entire address of your NAS server, including the resource (myshare in the above example). Finally, you have to notify the Finder about your newly-mounted device. Start by getting a list of the mounted devices with disktool -l. Look for the rows beginning with:
***Disk Appeared ('something',...
Find the entry containing your NAS mountpoint. Write down the first entry and use it as a parameter (replacing your_entry) in the following command:
$ disktool -m your_entryClose Terminal and proceed as normal with your installation. When asked to resume from a Time Machine backup, choose the network disk.
[robg adds: The above script is recreated here just in case the original linked version ever vanishes. The linked version may contain newer code, though, so check there first. On the linked page, you'll also find screenshots and more detail on the entire process.]
