Back it up first, then restore from backup afterwards. See http://support.apple.com/kb/HT1766. Be sure to import your photos to your computer (http://support.apple.com/kb/HT4083) and back up your contacts separately (such as by using an app like My Contacts Backup) as these are sometimes not restored from the backup.