To backup the data on your iPhone, connect your device to the USB port on your computer and launch iTunes. Right click on your iPhone in the panel on the left side of your screen and select "Back Up." iTunes will then automatically backup all of your iPhone's user data and files and store it in your iTunes account as of that date.
How to Erase All Content and Settings
To erase all data, turn your iPhone on and go to Settings » General » Scroll all the way down to Reset. From there, tap Reset and you should see two options: "Reset all settings" and "Erase all content and settings." To completely remove all your iPhone’s data and restore the phone to its original factory settings, choose "Erase all content and settings.". Your phone is now ready to be sold safely!