WordPress Security

Hacked Site: Should You Restore a Backup or Clean It? A Decision Guide

Hacked Site: Should You Restore a Backup or Clean It? A Decision Guide

When a WordPress site is hacked, the first question I usually hear is “Can’t we just restore yesterday’s backup?” It’s an understandable instinct. A backup promises to turn the clock back to a time before anything went wrong.

Sometimes that’s exactly the right move. But I’ve also seen restores that brought the site straight back to an infected state, because the infection was older than anyone realised. And I’ve seen restores that removed the visible symptoms while the attacker walked straight back in through the same vulnerability a few days later.

Choosing between restoring and cleaning, or combining both, depends on a few key questions. Here’s how I make the decision.

The two approaches

Restoring from backup

Replace the current site with a copy from a time before the compromise.

Advantages: fast, thorough when the backup is genuinely clean and easy to explain to non-technical stakeholders.

Disadvantages: you lose changes made since the backup, the backup may already be infected, and restoring doesn’t fix the vulnerability that let the attacker in.

Cleaning in place

Remove malicious files, database injections, rogue users and backdoors from the current site.

Advantages: no data loss and a better understanding of what happened.

Disadvantages: slower, requires expertise and risks missing hidden backdoors.

Most real recoveries use a mix of both. Understanding the trade-offs helps you choose the right mix.

Question 1: When did the infection really start?

This is the most important question, and it’s often answered wrongly. The day you noticed the hack is rarely the day it started. Attackers often gain access weeks or months before visible symptoms appear. They may plant backdoors first and only activate spam or redirects later.

To estimate the real start date:

  • Check modification times of malicious files.
  • Look at when rogue administrator accounts were created.
  • Check access logs for the first suspicious requests.
  • Check when spam pages first appeared in Google, using Search Console’s performance data.
  • Look at when vulnerable plugins in use were publicly disclosed.

If your backups only go back two weeks and the infection started six weeks ago, every backup is infected. Restoring them won’t help.

Question 2: Do you have a clean backup?

A backup is only useful if you’re confident it predates the compromise. Check:

  • How far back backups go.
  • Whether backups include both files and database.
  • Whether you can restore a backup to a staging environment and inspect it before using it.

Scan candidate backups on staging the same way you’d scan the live site: checksum checks, searches for backdoors, database searches for injected code and checks for unknown users. A backup that passes those checks is a strong candidate.

Question 3: How much data would you lose?

Restoring a backup from last week means losing everything since: new posts, comments, form submissions, user registrations and, for stores, orders and customer accounts.

For a brochure site that rarely changes, losing a week may not matter. For an active store, losing orders is serious. You’d need to reconcile them from payment gateway records and emails, which is painful.

If data loss is significant, a hybrid approach often works better.

Question 4: Do you know how they got in?

Restoring a backup restores the vulnerability that let the attacker in. If it was an outdated plugin, the restored site has the same outdated plugin. Automated attacks will find it again, sometimes within hours.

Before or immediately after restoring, you must:

  • Update or remove the vulnerable component.
  • Change all passwords and regenerate security keys.
  • Remove any accounts or access the attacker may have obtained outside WordPress, such as FTP accounts or hosting users.

If you don’t know how they got in, assume credentials were compromised and rotate everything, then update everything.

Question 5: How complex is the infection?

Simple infections, like a single injected file or a defacement, are often quick to clean in place. Complex infections, with dozens of backdoors, database injections, malicious cron tasks and SEO spam, are harder to clean completely, which makes a verified clean backup more attractive.

A decision framework

Restore the backup when:

  • You have a verified clean backup from before the real start of the infection.
  • Data loss since that backup is acceptable or can be recovered.
  • The infection is complex or widespread.
  • You can fix the entry point before or right after restoring.

Clean in place when:

  • No clean backup exists, or all backups are too old to be useful.
  • Data since the infection is valuable and hard to recover.
  • The infection is limited and well understood.

Use a hybrid approach when:

  • You have a clean backup of files, but need recent database content.
  • Or you have a clean, older database, but need recent orders or posts.

The hybrid approach in practice

A common, effective hybrid:

  1. Rebuild the files from clean sources. Download fresh WordPress core, plugins and themes from official sources. Restore only custom code and uploads from a clean backup, or from version control, checking uploads for PHP files.
  2. Keep the current database, but clean it. Search for injected scripts, rogue users, malicious options and spam content, and remove them.
  3. Reconfigure wp-config.php with new database credentials and fresh security keys.

This preserves recent content and orders while replacing every file with a known good version. It’s my default approach for active stores.

Step-by-step restore process

If you decide to restore, do it carefully:

  1. Take a backup of the infected site first. It’s evidence, and it may contain data you need to recover.
  2. Restore the candidate backup to staging and verify it’s clean.
  3. Update everything on staging: WordPress core, plugins and themes. Remove anything unused or vulnerable.
  4. Rotate all credentials: hosting, SFTP, database, WordPress administrators, API keys.
  5. Regenerate security keys in wp-config.php.
  6. Replace the live site with the cleaned, updated staging version.
  7. Recover lost data where needed, such as orders from payment gateway records or form entries from email notifications.
  8. Check other sites in the same hosting account. Infections often spread between sites sharing an account.
  9. Request reviews in Search Console if Google flagged the site.
  10. Monitor closely for several weeks: file changes, new administrators, unexpected outgoing connections and Search Console alerts.

Mistakes to avoid

  • Restoring the most recent backup without checking it. It’s often infected.
  • Restoring without updating. The attacker returns through the same hole.
  • Not changing passwords. Stolen credentials still work after a restore.
  • Ignoring other sites in the account. They reinfect the restored site.
  • Deleting the infected copy. You lose evidence and possibly data.
  • Declaring victory too early. Some backdoors activate days later.

Improve your backups for next time

A hack is a good moment to improve backup strategy:

  • Keep longer history, with daily backups for a few weeks and weekly and monthly backups for several months.
  • Store backups off-site, separate from the server and with different credentials.
  • Make backups immutable or versioned where possible, so attackers can’t delete them.
  • Test restores regularly.

A note on communication

During a recovery, tell stakeholders which approach you’re taking and why, what data might be lost and how long it will take. Clear expectations make difficult trade-offs, like losing a day of orders, much easier for business owners to accept.

Write it down afterwards

After any recovery, write a short summary of what happened, how the site was restored, what data was affected and what changed to prevent a repeat. The next time something goes wrong, that record makes decisions much faster.

Keep evidence even after restoring

Store the infected snapshot securely for a while after recovery. If the attacker returns, or questions arise later from customers or payment providers, that snapshot shows exactly what was there.

Frequently asked questions

Is restoring a backup enough to fix a hacked site?

Only if the backup predates the infection and you also fix the entry point and change credentials. Otherwise, the site is likely to be reinfected.

How far back should I restore?

To before the infection actually began, which is often earlier than when you noticed it. Investigate file dates, logs and account creation times to estimate it.

What if all my backups are infected?

Clean the site in place, or use a hybrid approach: rebuild files from official sources and clean the database. Then improve backup retention for the future.

Can I keep my recent WooCommerce orders if I restore?

Not directly from an older backup. A hybrid approach that keeps the current database, cleaned, preserves orders while replacing infected files.

Final thoughts

A backup is a powerful recovery tool, but only when it’s clean and you close the door the attacker used. Work out when the infection really started, verify backups on staging, weigh data loss honestly and choose between restoring, cleaning or a hybrid. Whichever path you take, update everything, rotate every credential, check neighbouring sites and monitor closely afterwards. A careful recovery is the one you only have to do once.