How can I back up my iMac from the Recovery Partition?

Things in my iMac are failing, most notably the hard drive. I can only reliably boot to the Recovery Partition. Booting to the regular system, either normally or in Safe Mode, does not work, and causes the machine to power off midway through boot.

This computer is most likely fubarred. Is it possible to initiate a backup through the Recovery console? I'd prefer to get a Time Machine update, but I'll take whatever backup I can get.

I am running the latest version of Lion (OS X 10.7).


Unfortunately you cannot backup the Mac through the recovery partition. However starting the Mac in Target disk mode or booting the Mac from a bootable external drive may allow you to mount the iMac's drive and copy files from it.


The Recovery Partition includes Disk Utility, which you can use to clone your hard drive to a new drive. However it's worth noting that if your disk doesn't reliably boot, at least some of the files on it are corrupt (at best), or the mechanism is damaged, and you may be causing further damage by trying to do a heavy read operation.


You can clone the volume in Terminal with the rsync command (replacing "Macintosh HD" and "Backup" with the actual volume names):

dev=$(hdik -drivekey system-image=yes -nomount ram://1024)
newfs_hfs $dev
mount -t hfs -o union -o nobrowse $dev /private/tmp
/Volumes/"Macintosh HD"/usr/bin/rsync -axE /Volumes/"Macintosh HD"/ /Volumes/"Backup"

Note: it's very important that the source path ends in "/", and the destination path not end in "/".

Note: this could be optimized a bit by excluding irrelevant things like /private//var/vm, but since you'll be typing it by hand it probably best to keep it simple. Also, @CanuckSkier's warnings about corrupt files and disk damage apply here too.

EDIT: after testing, found that I need to create a ramdisk on /private/tmp so it can store its metadata files. I added steps to the procedure above.

EDIT: fixed typo