How can I backup my site if it gets hacked?

This is a multi prong question. It sounds like you are asking what to do if your site gets hacked in the future, but it is vague enough that you might be implying it has already been hacked.

If you have not been hacked yet, download a backup of your site as soon as possible and do this frequently. Keeping the last 3 or more site backups can really save you down the road. Second, install a security program of some sort. This could be something like Wordfence or paying your hosting provider. Either way, secure your site to prevent known attacks by using the appropriate service, professionals, or software. Always keep your WordPress Version up to date as well as your plugins.

If you site has already been hacked then your options are limited. You can hire a professional to see if they can find the malicious code. You could say ‘who cares’ and loose all of your data on your site and start over. Or, you can try to reconstruct what you can by using cached versions of your site (like Google) to pull content. Either way, you will need to reinstall your WordPress to overwrite the malicious code and may need to wipe your database clean too.

Remember the old adage that an ounce of prevention is worth a pound of cure.