Restoring From Backup Is Best
Before we go any further, a note: if you’ve got a backup of your hard drive, it’s better to try to restore from that since it’s more comprehensive and will contain more than just iTunes. If you do have a backup, congratulations on being conscientious and planning ahead. Give yourself a high five and proceed to restore your data from backup. If you didn’t have a backup, research backup software and service options and start using one as soon as you get everything back up and running.
Whatever You Do, Don’t Sync!
In theory, your iPhone, iPad, or other device has most or all of your iTunes library on it. If you’ve been syncing content from iTunes to the device, this should be true (assuming your device has enough storage capacity for all of your content to be synced to it). That means that your portable device can function as a backup of your iTunes content. Once you get a new hard drive or computer or get your existing equipment repaired, plug your iPhone or another device into it. At this point, iTunes will ask if you want to sync/setup the device again. DON’T DO THAT! If you sync/setup, this will erase everything on your device. Instead, follow the advice in the next section.
Get Music off Your iPhone and Onto Your Computer
You can transfer the music, movies, apps, TV, and other content from your iPhone, iPad, or iPad to your new hard drive/computer in two ways: using the Transfer Purchases feature in iTunes or iPhone copy/rip software. Transfer Purchases is the more limited option, but it’s also the one that’s built into iTunes for free. It’s limited because it only works with items bought at the iTunes Store (and on computers that are authorized for this content; see the next section for more on that). If you’ve got a lot of that kind of content, connect your device (and don’t sync it!), then go to File > Devices > Transfer Purchases from [device name]. If most or all of your music, movies, and other content came from places other than the iTunes Store, you’ll want to use copy/rip software. There are dozens of these programs 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 iPhone or another device to your computer. Even if you didn’t have a backup, at least you didn’t lose everything.
Re-Authorize Your Computer
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. You have to do this because iTunes views new hardware as an entirely new computer (even if it’s just a new hard drive in an old computer) and it needs to know that this computer is signed into the Apple ID that was used to get all of your old iTunes content.
Set Your iPhone up for Syncing Again
Once you know for sure that your data is backed up (or restored from backup) and 100% available on your computer, you may want to set it up to sync with your computer again. (Alternatively, you could sync it with iCloud.)
Get the Rest of Your iTunes Content Back
If your iPhone or iPad didn’t have 100% of the content you’ve bought from iTunes on it, that doesn’t mean its gone. In fact, virtually everything you’ve ever downloaded from iTunes can be redownloaded again — for free! — to your new computer or device.
Avoid All of This by Using Apple Music
One way you can avoid losing your music without making a backup is to use Apple Music, thanks to its iCloud Music Library feature. This feature stores a record of every song you’ve got in your music library in your iCloud account and then — as long as you continue to pay for your Apple Music subscription — makes them available to you on any compatible device. If you use Apple Music and lose your hard drive, all you need to do is sign into your account on a new device and all your music will be waiting for you!