Servers and DevOps

Backups for small businesses: the 3-2-1 rule and restore testing

Why a copy on the disk next door is not yet a backup, how to apply the 3-2-1 rule in a small company, and why a backup only counts as existing once a restore has been tested. With a restic example.

Alexei Sergeev 4 min read

In small companies, the question "do we have backups?" is usually asked after something has happened: a disk died, ransomware encrypted the shared folder, an employee deleted the database. And it often turns out that there were copies, but they cannot be restored: the wrong things were copied, the copy sat on the same server, or the last good one was six months old.

This article covers the minimum set of rules I follow when setting up backups.

The 3-2-1 rule

The classic rule goes like this:

  • 3 copies of the data: the working data and at least two backups;
  • 2 different media: for example, a local NAS and cloud storage;
  • 1 copy off-site: in case of fire, theft or ransomware that reaches everything visible on the local network.

Today one more requirement is often added: at least one copy must be protected from being changed or deleted from the production server. Ransomware deliberately looks for and destroys any backups it can reach.

What exactly to back up

Start not by choosing software but with a list of what the company cannot work without, and how much data it can afford to lose. The list usually includes:

  • databases of business systems (copied with the database's own tools, not by copying files while it runs);
  • shared folders and file storage;
  • email, if it runs on your own server;
  • server and network equipment configurations, since rebuilding router settings from memory is slow and risky;
  • documentation: diagrams, passwords in a password manager, instructions.

For each item, decide how often to copy it and how long to keep the copies. For example, the accounting database nightly with 30 days of retention, files daily with weekly and monthly restore points.

Example: restic on a Linux server

For Linux servers I often use restic: it encrypts data, stores it with deduplication (repeated blocks do not take up space twice) and works with many storage backends, from SFTP to S3-compatible clouds.

backup.sh
#!/usr/bin/env bash
set -euo pipefail

export RESTIC_REPOSITORY="sftp:backup@backup.example.com:/srv/restic/office"
export RESTIC_PASSWORD_FILE="/root/.restic-password"

# the database is backed up with a proper dump, not by copying files
pg_dump --format=custom --file=/srv/backup/db.dump accounting

restic backup /srv/data /srv/backup/db.dump /etc --exclude-caches --tag nightly

# keep 7 daily, 4 weekly and 6 monthly snapshots
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

# verify the integrity of part of the repository data
restic check --read-data-subset=5%

The script runs on a schedule (a systemd timer or cron), and the result of every run should go into monitoring: a backup that did not happen is an event you need to know about right away, not a month later.

A backup exists only once you have restored from it

This is the most important rule. Backups that have never been tested with a restore are hope, not protection. I build testing into the maintenance schedule:

  1. Once a month, I restore a random set of files to a separate folder and compare them with the originals.
  2. Once a quarter, I restore a copy of the database on a test server and check that the business system starts with it.
  3. I record how long the restore took. That answers the question "how long will we be down if the server dies".
bash
# restore the latest snapshot to a temporary folder for testing
restic restore latest --target /tmp/restore-test --include /srv/data/documents
diff -r /srv/data/documents /tmp/restore-test/srv/data/documents && echo "Match"

A short checklist

  • There is a list of critical data and requirements for backup frequency.
  • At least one copy is stored off-site and cannot be deleted from work computers.
  • Backups are encrypted, and the keys are stored separately.
  • Backup errors trigger an immediate notification.
  • Restores are tested regularly, and the results are recorded.

Backups are part of server and DevOps work and a mandatory item in infrastructure maintenance.

Not sure you could recover after a failure?

Tell me what data and systems your company has. I will assess your current backups and propose a scheme with restore testing.

Discuss your task

Alexei SergeevEngineer, IT infrastructure and DevOps

Read next

IT infrastructure monitoring: how to learn about outages before your staff do

If you learn about server problems from your employees, you effectively have no monitoring. I cover what a small company should track, how to set up alerts that people do not ignore, and how to choose between Zabbix and…

Linux server security: what to configure right after installation

The minimum set of measures I apply to every new Linux server: key-only SSH login, a firewall, automatic security updates, brute-force protection and a check of open ports.

Office network segmentation on MikroTik: VLANs for staff, guests and servers

Why a flat network where every device sees every other one is the main source of trouble in a small office, and how to split it into VLANs on MikroTik with RouterOS 7: the layout, bridge configuration, firewall rules an…