Server Administration
Website Backups: What to Back Up, How Often, and the 3-2-1 Rule
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربيEvery website eventually meets a bad day: a plugin update that breaks the checkout, a deleted folder, a compromised admin account, or a disk that simply fails. On that day, the only thing that matters is whether you have a recent, complete and working copy of your site somewhere safe. Backups are not glamorous, but they are the single most important safety net you can build on a server. This guide explains what to back up, how often, where to keep copies, and how to make sure a backup will actually restore when you need it.
Why backups matter even on reliable hardware
Good infrastructure reduces hardware failures, but most data loss is not caused by hardware. It comes from human error, buggy updates, ransomware or web shells planted through a vulnerable plugin, and accidental rm -rf commands. Replication and RAID protect against a dead disk; they do not protect against a deleted table, because the deletion is replicated instantly. Only a point-in-time copy that lives separately from the live system lets you go back.
What to back up
A website is more than its files. A complete backup usually includes:
| Component | Typical location | Notes |
|---|---|---|
| Application files | /var/www/your-site | Code, themes, plugins, uploaded media |
| Database | MySQL/MariaDB or PostgreSQL | Use a proper dump, not a raw copy of a running data directory |
| Web server config | /etc/nginx/, /etc/apache2/ | Virtual hosts, redirects, TLS settings |
| Environment and secrets | .env, wp-config.php | Store encrypted; never in a public repository |
| Scheduled tasks | crontab -l, /etc/cron.d/ | Easy to forget, painful to rebuild |
| TLS certificates | /etc/letsencrypt/ | Can be reissued, but copying saves time |
If you can rebuild the server from these pieces, your backup is complete. If you would have to "remember" something, add it to the list.
How often to back up
Frequency depends on how much data you can afford to lose. Ask yourself: if the server vanished right now, how many hours of orders, comments or uploads would be acceptable to lose? That answer is your recovery point objective.
- Brochure or portfolio site: weekly files, daily database is usually plenty.
- Blog with regular posts: daily files and database.
- Online store or membership site: database every few hours or more often, files daily.
- Before any risky change: always take a manual backup or snapshot first.
Also decide on retention. A common pattern is to keep 7 daily, 4 weekly and 3 monthly copies. That way you can recover from a problem you only noticed weeks later, such as a slow malware infection.
The 3-2-1 rule
The 3-2-1 rule is the simplest strategy that survives most disasters:
- Keep 3 copies of your data: the live data plus two backups.
- Store them on 2 different types of storage or systems.
- Keep 1 copy offsite, in a different location or provider account.
On a VPS, a practical version looks like this: the live site on the server, a provider-level snapshot of the whole disk, and a nightly file-and-database backup pushed to object storage or another server in a different region. Many teams add a fourth idea: keep at least one copy that is immutable or offline, so an attacker who gains root on the server cannot delete it.
Snapshots versus file-level backups
Snapshots capture the entire disk at a moment in time. They are excellent before upgrades and for fast full-server recovery. NileVPS servers include snapshots you can take from the control panel. However, snapshots live with the provider and restore the whole machine, so they are not a replacement for granular backups that let you recover one database or one folder. Use both: snapshots for quick rollback, file-level backups for flexibility and offsite safety.
A simple automated backup on Linux
Here is a minimal script that dumps a MariaDB database, archives the site files and uploads both with rclone to a remote you configured beforehand:
#!/usr/bin/env bash
set -euo pipefail
STAMP=$(date +%F_%H%M)
DEST=/var/backups/site
mkdir -p "$DEST"
mysqldump --single-transaction --routines mydb | gzip > "$DEST/db_$STAMP.sql.gz"
tar -czf "$DEST/files_$STAMP.tar.gz" -C /var/www mysite /etc/nginx
rclone copy "$DEST" remote:site-backups
find "$DEST" -type f -mtime +7 -deleteThe --single-transaction flag gives a consistent dump of InnoDB tables without locking the site. Store database credentials in ~/.my.cnf with chmod 600 instead of on the command line. Schedule the script with cron, as explained in our cron jobs guide. For larger sites, tools such as restic or borg add deduplication, encryption and incremental storage, which we cover in full vs incremental backups.
Test your restores
A backup you have never restored is a hope, not a plan. At least once a month, or after changing your backup setup:
- Spin up a temporary server and restore files and database onto it.
- Confirm the site loads, logins work and recent content is present.
- Check that archives are not empty and that the dump finishes with
-- Dump completed. - Write down the restore steps so anyone on the team can follow them under pressure.
Backup checklist
- [ ] Files, database, configs, secrets and cron jobs are all included
- [ ] Schedule matches how much data you can afford to lose
- [ ] At least one copy is offsite and protected from deletion
- [ ] Backups are encrypted when they leave the server
- [ ] Failures send an alert instead of failing silently
- [ ] A restore has been tested recently
If you are planning a new server for your site, compare plans by disk size and remember to budget for backup storage from day one.
FAQ
Are provider snapshots enough on their own?
Snapshots are very useful, but they should not be your only copy. They live in the same provider environment and restore the whole disk. Pair them with file and database backups stored in a separate location so you can recover individual items and survive account-level problems.
Should I compress and encrypt backups?
Yes. Compression saves storage and transfer time, especially for SQL dumps, which compress very well. Encryption protects customer data if the remote storage is ever exposed. Tools like restic and borg encrypt by default; with plain archives you can use gpg before uploading.
How long should I keep old backups?
Keep enough history to catch problems you notice late. A rotation of seven daily, four weekly and three monthly copies suits most sites. Legal or business requirements may demand longer retention for orders and invoices, so check what applies to you.