Ransomware encrypts your files and demands payment. A solid backup and monitoring system stops it from destroying your business. This guide walks you through building that system from scratch, even if you've never configured automated backups before.
What ransomware actually does
Ransomware is malware that locks your files with encryption you can't break. Attackers then demand cryptocurrency in exchange for the decryption key. Modern strains also steal data before encrypting it, threatening to publish sensitive information if you don't pay.
The attack usually starts with a phishing email, a compromised password, or an unpatched vulnerability. Once inside, the malware spreads laterally across your network, encrypting databases, websites, email archives, and backups it can reach.
Paying the ransom doesn't guarantee you'll get your data back. In support tickets I handled, roughly half the organizations that paid either received a broken decryption tool or never heard from the attackers again.
Why backups alone aren't enough
You need backups that ransomware can't reach or encrypt. If your backup drive is mounted 24/7 or your backup credentials are stored on the compromised server, the malware will encrypt those backups too.
Three things make a backup actually useful:
- Immutability — the backup can't be modified or deleted for a set retention period
- Isolation — stored off-site or air-gapped, not continuously accessible from production systems
- Verification — regular automated tests confirm the backup can be restored
Without all three, you're one incident away from discovering your backups are useless.
The 3-2-1-1 backup rule explained
This is the industry-standard framework. Keep three copies of your data: the production copy plus two backups. Store them on two different media types (local disk and cloud, or disk and tape). Keep one copy off-site or in a different cloud region. Keep one copy offline or immutable.
Here's what that looks like for a typical cPanel server:
- Production data on the server itself
- Local backup on a separate partition or external USB drive (disconnected after backup runs)
- Cloud backup to AWS S3, Backblaze B2, or Wasabi with versioning and object lock enabled
- The cloud copy configured with immutability for at least seven days
The USB drive or local backup gives you fast recovery for small incidents. The cloud copy protects against total server loss or a fire in your data center.
Step 1: Set up automated local backups
Start with cPanel's built-in backup system if you're on shared or managed hosting. Go to cPanel → Backup → Backup Wizard and enable full account backups on a daily schedule.
For a VPS or dedicated server, use a simple shell script with tar and rsync. Create /root/backup.sh:
#!/bin/bash
BACKUP_DIR="/mnt/backup"
DATE=$(date +%Y%m%d)
mkdir -p ${BACKUP_DIR}/${DATE}
# Backup web files
tar -czf ${BACKUP_DIR}/${DATE}/www.tar.gz /var/www/html
# Backup databases
mysqldump --all-databases --single-transaction > ${BACKUP_DIR}/${DATE}/databases.sql
gzip ${BACKUP_DIR}/${DATE}/databases.sql
# Backup configs
tar -czf ${BACKUP_DIR}/${DATE}/configs.tar.gz /etc/httpd /etc/php.ini /etc/my.cnf
# Keep only last 7 days locally
find ${BACKUP_DIR} -type d -mtime +7 -exec rm -rf {} +
Make it executable and add to cron:
chmod +x /root/backup.sh
echo "0 2 * * * /root/backup.sh" | crontab -
This runs every night at 2 AM. The local copy stays on the server for seven days, giving you quick recovery from accidental deletions or small corruptions.
Step 2: Configure off-site immutable backups
Local backups won't survive ransomware. Push a copy to S3 with object lock enabled.
Install the AWS CLI:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Create an S3 bucket with versioning and object lock through the AWS console. Under Object Lock, choose Governance mode with a retention period of 14 days. This prevents anyone—including someone with root access to your AWS account—from deleting backups for two weeks.
Add the sync command to your backup script:
aws s3 sync ${BACKUP_DIR}/${DATE} s3://your-backup-bucket/${DATE}/ --storage-class GLACIER_IR
Glacier Instant Retrieval is cheaper than standard S3 for data you rarely access but need immediately during a disaster.
Store your AWS credentials in /root/.aws/credentials, not in the script itself. If an attacker gets root, they can read the file, but they can't delete the locked S3 objects.
Step 3: Verify backup integrity automatically
Backups fail silently. A corrupted database dump or an incomplete file transfer won't scream at you until you need to restore.
Add verification to your script:
# Test database backup
gunzip -c ${BACKUP_DIR}/${DATE}/databases.sql.gz | mysql --protocol=tcp --host=127.0.0.1 --user=testuser --password=testpass testdb > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Database backup verification failed" | mail -s "Backup Alert" [email protected]
fi
# Verify tar archives
tar -tzf ${BACKUP_DIR}/${DATE}/www.tar.gz > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Web files backup verification failed" | mail -s "Backup Alert" [email protected]
fi
This tests that the SQL dump is valid and the tar archive isn't corrupted. For a full test, spin up a separate test server once a month and restore the entire backup there.
Step 4: Monitor backup jobs in real time
You need to know immediately when a backup fails. Use a dead man's switch monitoring service.
Sign up for a free account at Healthchecks.io or cronitor.io. Create a new check with a schedule matching your backup cron (daily at 2 AM). Copy the ping URL.
Add this to the end of your backup script:
curl -fsS -m 10 --retry 5 https://hc-ping.com/your-uuid-here
The monitoring service expects a ping every 24 hours. If the ping doesn't arrive—because the script failed, the server crashed, or an attacker killed the cron job—you get an email or Slack alert within an hour.
I've seen servers run for weeks with failed backups before anyone noticed. This catches it the first day.
Step 5: Write your incident response runbook
When you discover ransomware at 3 AM, you won't remember the restoration steps. Write them down now.
Create a document with these sections:
Immediate actions (first 15 minutes):
- Disconnect the infected server from the network (unplug Ethernet or disable the network interface)
- Do NOT shut down the server yet—RAM contains forensic evidence
- Take a screenshot of any ransom note and record the time you discovered the infection
- Contact your hosting provider and payment processor to freeze transactions
- Notify your legal and PR teams if customer data might be involved
Assessment (next 30 minutes):
- Check how many systems are affected—log in to other servers from a clean workstation
- Identify the ransomware strain if possible (check the file extension or ransom note against public databases)
- Determine the earliest infection time by reviewing logs for suspicious authentication attempts or new scheduled tasks
- Confirm your most recent clean backup predates the infection
Recovery (next 2-4 hours):
- Provision a new clean server or VM
- Download backups from your immutable S3 bucket
- Restore files and databases to the new server
- Update all passwords and SSH keys
- Review firewall rules and close unnecessary ports
- Patch all software to current versions
- Point DNS to the new server after testing
Keep a printed copy in your desk drawer and a copy in a password manager. You can't access Google Docs if your Google Workspace account is locked.
Step 6: Test your response plan quarterly
Schedule a recovery drill every three months. Treat it like a real incident.
Pick a random backup from two weeks ago. Spin up a new VPS. Restore the backup without looking at your production server for reference. Time how long it takes. Document what went wrong.
Common problems I see during drills:
- Forgotten database passwords not stored in the password manager
- Backup script missing a critical config file
- Restoration instructions assume tools are already installed
- DNS TTL set to 24 hours, delaying failover
Fix these issues before they matter. Update your runbook after each drill.
Step 7: Lock down backup access
Ransomware often spreads through compromised credentials. Protect your backup system the same way you protect production.
Use a dedicated AWS IAM user for backups with write-only permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::your-backup-bucket/*"
}
]
}
This user can upload backups but cannot list, download, or delete objects. Even if an attacker steals the credentials, they can't touch existing backups.
For restoration, use a separate IAM user with read permissions that you only activate when needed. Store those credentials offline in your password manager, not on the server.
Enable MFA on your AWS root account and never use root credentials for automated tasks.
What to do if you're already infected
Don't panic. Don't pay immediately.
Isolate the infected systems first. Disconnect network cables and disable Wi-Fi. Take photos of any ransom screens showing the contact info and payment address.
Check if a free decryption tool exists. Some ransomware strains have been broken by security researchers. Search for your specific variant at the No More Ransom Project website.
Contact law enforcement. The FBI and Europol track ransomware campaigns and occasionally recover decryption keys from seized infrastructure. File a report even if you plan to restore from backups—it helps them build cases.
Restore from your most recent clean backup. If you're not sure when the infection started, go back further. A three-day-old backup is better than paying ransom.
After restoration, scan every system on your network with updated antivirus tools. Change every password. Review user accounts for unauthorized additions.
How much this costs
A basic setup costs very little. AWS S3 with Glacier Instant Retrieval runs about $4 per terabyte per month for storage, plus minimal request fees. Healthchecks.io monitoring is free for up to 20 checks.
The real cost is time—expect to spend 4-6 hours on initial setup and 30 minutes per quarter on testing drills.
Compare that to the median ransomware payment, which sits in the mid five figures, plus weeks of downtime and permanent reputation damage.
Questions I get about backup monitoring
How long should I keep backups?
Keep daily backups for 30 days, weekly backups for 90 days, and monthly backups for a year. This lets you recover from slow-moving attacks that aren't discovered immediately.
Can I use Dropbox or Google Drive?
No. Those sync services mirror deletions and encryption back to the cloud almost instantly. You need versioning with retention policies that prevent immediate overwrites.
What if my server is too big for nightly backups?
Switch to incremental backups with tools like rsnapshot or Duplicity. Only changed files are copied each night. Full backups run weekly.
Should I encrypt my backups?
Yes, especially if they contain customer data. Use GPG to encrypt archives before uploading to S3, or enable S3 server-side encryption with KMS keys you control.
How do I test database backups without a spare server?
Restore to a temporary database on the same server: mysql testdb < backup.sql. Compare table counts and a few sample records, then drop the test database.
Start with the backup, then add monitoring
Get your first automated backup running this week. Pick local or cloud—doesn't matter which—and verify it completes successfully. Next week, add the second backup target. The week after, set up monitoring.
Perfect is the enemy of done. A basic backup you test monthly beats an elaborate system you never finish building.
Once you have three months of successful backups, schedule your first drill. You'll find gaps in your runbook. Fix them. Schedule the next drill.
Ransomware isn't a technical problem you solve once. It's an operational discipline you practice until restoration becomes muscle memory.
