When you've lost the data on your computer thanks to a hard drive crash or a power surge that fried your computer, there are a few steps you take to get back up and running: a repair, a new hard drive, restoring from backup, a new computer. If you're an iPod or iPhone user, though--and especially if you don't have a backup--there are some steps you should take.
Time Required: Varies based on what steps you need; allow 30-90 minutes
Whatever you do, don't sync! If you get a new hard drive or computer and plug your iPod or iPhone into it, iTunes will ask if you want to sync/set up the device again. That's because the iPod/iPhone sees the new hard drive as a whole new computer. If you sync/set up, this will erase everything. Unless you have a backup of all your data, don't do this.
Instead, don't start by plugging in your device. Start with your data.
Now then, you did have a backup of all the data on your hard drive, right? If you did, congratulations for being conscientious and planning ahead. Give yourself a high five, restore your data from backup, and skip to step 6.
Even if you didn't have a backup of your data, you have at least some data backed up on your iPod/iPhone. Depending on what you synced to your device, you'll have at least some music, movies, TV, apps, and data on your iPod/iPhone. You can transfer this data to your new hard drive/computer in two ways: using the Transfer Purchases command in iTunes or iPod copy/rip software.
Transfer Purchases will only move items bought at the iTunes Store from your device to your computer, but it's a start. To use this, connect your iPod/iPhone (and don't sync it!), go to File -> Transfer Purchases.
If most or all of your music, movies, etc. aren't from the iTunes Store, you'll want to use an iPod copy/rip program.
There are dozens on the market; most cost $20-$30, though a few are free. Find one that works for you and use it to copy the data on your iPod/iPhone to your computer. Even if you didn't have a backup, at least you didn't lose everything.
Remember step 2? The one where, if you didn't already have a backup plan, you figured one out? This is where you should start using it.
Once you've copied the contents of your iPod/iPhone to the new hard drive/computer, eject the device and run your backup software. That way you'll at least have this data backed up in case something goes wrong in the future.
Once you know for sure that your data is backed up (or restored from backup), open iTunes and connect your iPod or iPhone to it.
If the window pops up that offers to sync your device with this iTunes library, click the "Erase and Sync" button. This will delete everything from your iPod/iPhone (thus the importance of steps 4 and 5!) and set it up from scratch as if you're doing it with a new device.
Configure the syncing options as you like them to make sure you get the content you want on your iPod or iPhone.
Your computer now has at least some of its old data on it and your iPod or iPhone has been set up to work with the new computer and that data. If you lost some data, there are a few ways to get things back--though you won't be able to get everything back:
If you got a new hard drive, motherboard, or computer, you'll need to authorize the computer to play content from the iTunes Store again. ITunes views new hardware as an entirely new computer (even if it's just a new hard drive in an old computer).