I think my HD is failing. Can't backup files from recovery mode. How can I preserve my data? I'm really worried, and I'm hoping that you guys can help me salvage some files. Here's what happened:

This morning I woke my iMac up from sleep, but it was hardly responding. I would click something and it would show the colorwheel spinning for 30 seconds before responding. So I rebooted, but then it got stuck on the apple logo with the loading symbol for about 15 minutes, then it started osx but it responded even less and the desktop background disappeared every 20 seconds and turned grey.

So I booted into recovery mode and tried to verify the HD, which failed. Then I tried repairing it but it failed again, saying that I should backup my files and repartition my HD. I have an external HD, but it doesn't have enough space for me to save an image of my entire HD to it. So I'm trying to backup files manually through the terminal, but that's not working either. At first I couldn't even see my HD from the terminal in recovery mode (like it wasn't mounted). After rebooting a couple of times I can now access my HD from the terminal in recovery, but when I try to copy a file to my external drive it gives an "input/output error" most of the time.

This all sounds really bad to me. Is there anything I can do?

ps: I tried booting into my windows bootcamp partition but that didn't work. The error message said something about inserting a boot cd if I remember correctly.
I had this problem too, the best thing you can do is replace the harddrive since it will eventually break beyond repair.
Macs are quite sensitive to faulty hdd's so there is a good chance you can still use the drive as external drive and get your data from it.

so:
Replace the drive yourself if you can (ifixit) or have it replaced
Get a hard drive enclosure for your old drive
plug it in your imac and drag back the files you still need

Once you've removed the failing/failed drive, you can then use an inexpensive USB to SATA adapter and see if any of the off-the-shelf file recovery software can read some of your data from the drive. Data Rescue might be a good tool to start with since the free demo will tell you what it might be able to recover before you have to spend $$ on the software.

Lastly, sending the failed drive into a professional will cost $$$ but if you really need the files or pictures back, that's often the best chance of success.