Monday, October 29, 2007

Leopard for the Web Developer - Restoration Stategy

One of the goals I have for installing Leopard is to start with a clean installation, so I can use it to restore if I should ever mess things up sufficiently, as to require starting over. My intention was to install a clean OS onto an external hard drive, then create a disk image of that prefect system so I can use it to restore from. I was inspired with this idea after reading this fantastic set of instructions for backing up a Mac, and reading the man pages of asr and hdiutil. With these feathers in my cap, I wrote up a VERY CRUDE shell script to do it all, being the nerd that I am. Here it is:


# This is a script designed to build a restorable disk image
# from a specified volume

# set up the variables.

# Help method
echo "This is the help"

# This is the create method
#if [$volname] ; then
#echo $volname
# volname="Mac Restore"
#1. use hdiutil to create the image - make it a read write version
echo "hdiutil create $tempImage -ov -format UDRW -nocrossdev -srcfolder $volume -volname $volname"
hdiutil create $tempImage -ov -format UDRW -nocrossdev -srcfolder $volume -volname $volname

#2. mount the image
echo "hdiutil attach $tempImage.dmg"
hdiutil attach $tempImage.dmg

#3. Clean it up manually
echo "rm -f /Volumes/$volname/var/db/BootCache.playlist"
rm -f /Volumes/$volname/var/db/BootCache.playlist
echo "rm -f /Volumes/$volname/var/db/volinfo.database"
rm -f /Volumes/$volname/var/db/volinfo.database
echo "rm -rf /Volumes/$volname/var/vm/swap*"
rm -rf /Volumes/$volname/var/vm/swap*

#4. unmount the volume
echo "hdiutil detach /Volumes/$volname"
hdiutil detach /Volumes/$volname

#5. Convert the image into a read only compressed version
echo "hdiutil convert -format UDZO $tempImage.dmg -o $image"
hdiutil convert -format UDZO $tempImage.dmg -o $image

#6. Delete the temp image
echo "rm $tempImage"
rm $tempImage

#7. use asr to build the checksums so I can use the image to do a restore
echo "asr -imagescan $image.dmg"
asr -imagescan $image.dmg

# Default method restores the image $1 to the volume $2
image = $1
volume = $2

echo "asr restore --source $image --target $volume --erase"

case $method in
create $2 $3 $4

restore $2 $3


The only problem is that it didn't work for me. I'd run this, saving the image file to a location on another partition of my external harddrive, and it would fail every time. Thinking that I was a little too ambitious and amateur to build my own shell script to handle it, I thought I'd try Carbon Copy Cloner, which is a fabulous backup software. In various configurations, it too failed every time. As a last resort, I tried using the DiskUtility app that ships with OS X. Once again failure.

What's interesting is how each of these approaches fail. Each time, creating an image file failed when the file size approached 4 Gigabytes. That was my key. It turns out that the partition that I use to do my backups on the external harddrive is formatted with a FAT32 file system. This is unfortunately required because I need my wife's PC to access the drive as well. After doing a little research, I found that FAT32 has a file size limit of just under 4 Gigs. Drats!

Now, my strategy for creating a perfect restorable disk image must change. I can't save the image on the backup drive as I intended. Instead of creating a restorable image, which I just think would be super cool, I think I'm going to have to do something else. I'll probably just restore from one disk to the other, and figure out how to save a disk image later. I'm thinking that I might just save it to a server on the network. I just have to set up the server :-)

Instead of focusing on the image creation, I think I'll push forward with the set up and install.

Up next: Apache, MySQL and PHP customization in Lepoard.

No comments: