Over the past couple of weeks I have helped out many people who have been hacked. There are many ways in which you can protect your site, but the most important thing is having a recent backup from before you were hacked.
There are many plugins available for WordPress that will help you make a backup of your database. Click here to see them all. I use WP-DB-Backup on many of my client’s sites. It has the option to backup to your server or your desktop. I suggest doing both. You can never have too many backups. I always save my backups in multiple places, and I also keep two or three previous backups, just in case.
If you are not using WordPress, there are many scripts out there that can help you with making a database backup. If your server has PHPMyAdmin installed, you can make manual backups very easily. But whatever you do, be certain to backup your database often.
Backing up your database is extremely important but so is backing up your site. Doing both regularly will not stop hackers from attacking you, but it will make it easier for you to repair the damage they make.