Server Backups: The 3-2-1 Rule and Methods
How to back up a server: the 3-2-1 rule, snapshots vs file backups, database dumps, encrypted offsite backups with restic and testing your restores.

Contents
Server backup means regularly taking a copy of the files, databases and settings on your server and storing it somewhere else. A disk failure, an accidentally deleted folder, a bad update or a ransomware attack can wipe out months of work in seconds. A good backup setup means being able to recover from any of these in a few minutes.
This guide covers the 3-2-1 rule, the types of backups, how databases should be backed up, taking encrypted offsite backups with restic, automation and the most neglected step of all: testing your restores.
Why should you take backups?
The causes of data loss are far more ordinary than people think:
- Human error: An
rm -rfrun in the wrong folder, an accidentally dropped table or an overwritten configuration file. This is the most common cause. - Bad updates: A plugin, mod or software update can corrupt the database.
- Attacks: On a compromised server, attackers delete data or encrypt it with ransomware.
- Hardware failure: Disks can fail, even in the best data centers.
- Account problems: Being unable to reach your server because of a payment issue or lost access.
However reliable the provider's hardware is, the only solution to most of these causes is for the data to exist somewhere else too.
The 3-2-1 backup rule
The most widely accepted rule in backups is simple:
- 3 copies: The original data and two backups.
- 2 different media: For example the server's own disk and separate storage.
- 1 copy somewhere else: In a different data center or with a different provider.
For a server, in practice this means: your original data lives on the server, your provider's automatic backups make up the second copy, and the encrypted backups you send to another provider make up the third. Today one more requirement is often added to this rule: at least one of the copies should be immutable or impossible to delete from the server, so an attacker who takes over the server can't delete the backups too.
Types of backups
| Type | What is backed up? | Advantage | Disadvantage |
|---|---|---|---|
| Server backup / snapshot | The entire disk | Brings back the whole server in one go | Restoring a single file is more work |
| File backup | Selected folders | Flexible, small, single files can be restored | You have to choose what gets backed up |
| Database dump | A consistent copy of the database | Consistent, portable | Only covers the database |
The most robust setup is to use them together: the provider's server backup gives you fast disaster recovery, while file and database backups give you the flexibility to bring back a single file or table and to move to another server.
What should you back up?
- Application and site files:
/var/www, game server folders, bot code and content uploaded by users. - Databases: Not as a file copy, but as a dump taken with the database's own tool.
- Configuration files: Nginx, service and firewall settings under
/etc;.envfiles; the output ofcrontab -l. - Docker data: Compose files and volumes or bind-mounted folders.
You don't need to add the operating system itself or files that can be downloaded again (for example a game server's files downloaded with SteamCMD) to your file backup; only the data and settings you created matter.
Backing up databases correctly
Copying the files of a running database can result in a backup that won't open. First take a dump with the database's own tool, then include that dump in your file backup:
mariadb-dump --single-transaction --all-databases | gzip > /var/backups/db.sql.gz
If you use PostgreSQL, pg_dump does the same job. We covered installing and backing up MariaDB in detail in our How to install MariaDB guide.
Encrypted offsite backups with restic
restic is a free, open-source backup tool. It encrypts backups, stores repeated data only once (deduplication) and sends only the changed parts with each backup. It can send backups to another server over SFTP or to S3-compatible object storage.
- Install restic:
sudo apt install restic - Write the encryption password to a file and protect it so only root can read it:
sudo sh -c 'openssl rand -base64 32 > /root/.restic-password' sudo chmod 600 /root/.restic-password
Save this password somewhere safe as well. Without the password, the backups can't be opened. - Create the backup repository on another server. For example, over SFTP:
sudo restic -r sftp:backup@198.51.100.20:/srv/restic init --password-file /root/.restic-password - Take the first backup:
sudo restic -r sftp:backup@198.51.100.20:/srv/restic --password-file /root/.restic-password \ backup /var/www /etc /var/backups - Clean up old backups according to a retention policy:
sudo restic -r sftp:backup@198.51.100.20:/srv/restic --password-file /root/.restic-password \ forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
This policy keeps one backup for each of the last 7 days, the last 4 weeks and the last 6 months. For the SFTP connection, your server needs to be able to connect to the backup server with a key, without a password; we explained how to create an SSH key in our What is SSH? post.
Automating backups
A backup taken by hand will be forgotten one day. Put the steps in a script, for example /root/backup.sh:
#!/bin/sh
set -e
REPO="sftp:backup@198.51.100.20:/srv/restic"
PASS="/root/.restic-password"
mariadb-dump --single-transaction --all-databases | gzip > /var/backups/db.sql.gz
restic -r "$REPO" --password-file "$PASS" backup /var/www /etc /var/backups
restic -r "$REPO" --password-file "$PASS" forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
Make the script executable and run it every night with sudo crontab -e:
30 3 * * * /root/backup.sh >> /var/log/backup.log 2>&1
Check the log file now and then, or use a monitoring service that notifies you when a backup fails. A backup that fails silently is the same as no backup at all.
Test your restores
An untested backup is a backup you don't know actually works. Run these checks once a month:
- List the backups: Use
restic snapshotsto see that backups are being taken regularly. - Restore a file: Bring back a single file with
restic restore latest --target /tmp/test --include /var/www/site/index.phpand check its contents. - Try the database dump: Load the dump into a separate test database and check that the tables come back.
- Check integrity:
restic checkverifies that the repository is intact.
Even better, a few times a year try restoring everything from scratch onto an empty server. That's the only way to find out how quickly you can recover in a real disaster.
Backups at Nodesty
Nodesty AMD Ryzen 9 9950X VPS and EPYC VPS plans include free automatic daily backups kept for 7 days, which you can turn on and off from the panel. On web hosting plans you reach your backups from the control panel with JetBackup, and on game servers daily backups are kept for 7 days as well. These backups provide the second copy in the 3-2-1 rule. For your important data, we recommend keeping an independent copy somewhere else, as in this guide.
Frequently Asked Questions
Aren't my provider's backups enough?
Provider backups are very valuable against hardware failures and accidental changes, but they shouldn't be your only backup. You need a copy that is independent of the provider for situations such as losing access to your account, noticing a problem only after it's older than the backup retention period, or an attacker who reaches the backups along with the server.
How often should I take backups?
Decide based on the longest period of data you can afford to lose. An e-commerce database that changes often during the day may need hourly backups; for a brochure site updated once a week, a daily backup is more than enough. For game servers, daily backups plus a manual backup before major updates is a good balance.
How long should I keep backups?
Keeping only the last few days doesn't protect you against problems that are noticed late. A common scheme is to keep the backups from the last 7 days, one backup for each of the last 4 weeks and one for each of the last few months. Tools like restic apply this scheme with a single command.
Is RAID a replacement for backups?
No. RAID keeps the server running when a disk fails. But a deleted file, a corrupted database or data encrypted by ransomware is reflected on all the disks at the same time. RAID is for uptime; a backup is for being able to go back.
Is copying the files of a running database enough?
Usually not. Copying the files while the database is running can result in an inconsistent backup that won't open. Take a dump with the database's own tools, such as mariadb-dump or pg_dump, and include that dump in your file backup.
Do I need to encrypt my backups?
Backups contain sensitive information such as customer data, passwords and API keys. Always encrypt backups kept with another provider or in cloud storage. Tools like restic and Borg encrypt backups by default; keep the encryption password in a safe place separate from the backups as well.
About the author
Nodesty Team · Infrastructure & Support
The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.
Related articles

Website Hacked? What to Do, Step by Step
Website hacked? What to do: the signs, first response, passwords, finding malicious files, restoring a clean backup, WordPress cleanup and prevention.

Linux Server Security: A Step-by-Step Checklist
A Linux server security checklist: automatic updates, SSH keys, a firewall, Fail2ban, unneeded services, isolation, backups and security audits.

How to Set Up WireGuard: Run Your Own VPN Server
How to set up WireGuard as your own VPN on an Ubuntu server: generating keys, wg0.conf, IP forwarding and NAT, client settings and QR codes for phones.