You just need to restore from a backup to get back your contacts and messages. So, backup the 3GS before the restore. For added safety for your contacts, you should sync your contacts to iTunes (via Address Book, Outlook, etc.).
Theres no way to choose which apps to backup.