If the music was purchased from the iTunes store, just hook it up to your computer and it will ask you if you want to transfer your purchases back to the computer.
If they weren't bought from iTunes, you'll have to find 3rd party software (google "senuti" if you're using a mac) to help you get it back.