← All resources

Backing up a Linux box: 3-2-1 for normal people.

One script, one external drive, one offsite copy. The cheapest good backup setup on Linux costs less than a takeaway dinner and runs without you ever thinking about it.

An editorial photograph of several Linux machines on a clean desk, an external SSD, and a small home NAS beside them, dim warm light.
Three copies. Two media. One offsite. The 3-2-1 rule is older than most of the people who follow it. It works because the failure modes are independent.

Backups are the kind of thing everyone agrees they need and almost nobody sets up before they need one. The reason it doesn’t get done is that every backup tool you hear about sounds like enterprise software: agents, dashboards, deduplication, retention windows. None of that is required. You can have a backup system that is good enough with one shell script and one external drive.

This guide will take you from “my files exist only in one place” to a working 3-2-1 backup in about twenty minutes. No new software to install, no subscription, no “enterprise” anything.

What you are aiming for: the 3-2-1 rule

The 3-2-1 rule has been the default professional backup setup since long before personal computers had hard drives:

You do not need three copies of everything. You need three copies of the files you cannot replace: documents, photos, the project you have been working on for six months, your password database, your tax records. The operating system itself is reinstallable in an hour. Your photos are not.

What you need

Step 1: pick the files you are actually backing up

Before writing any commands, decide what you are protecting. Most home directories look like this:

/home/yourname/
├── Documents/        ← keep
├── Projects/         ← keep
├── Pictures/         ← keep
├── Videos/           ← maybe, large
├── Music/            ← maybe, large
├── .ssh/             ← keep (small, irreplaceable)
└── .config/          ← keep (small, settings)

Make a list. Most people end up with two or three top-level folders. Videos and Music are optional — they can be re-downloaded and they bloat your backup.

Put the paths into a single text file. We will use it:

# /etc/backup-paths.txt  — one absolute path per line
/home/yourname/Documents
/home/yourname/Pictures
/home/yourname/Projects
/home/yourname/.ssh
/home/yourname/.config

Step 2: format and mount the external drive

Plug the external drive in. Find it:

lsblk

You will see something like sda1 or nvme0n1p1. The drive with no mountpoint and the right size is your external drive.

Format it with ext4 (Linux-native, fast, reliable):

sudo mkfs.ext4 -L backup /dev/sdX1

(Replace sdX1 with the actual partition. Double-check with lsblk — formatting the wrong disk is unrecoverable.)

Create a permanent mount point so the drive always appears at the same path:

sudo mkdir -p /mnt/backup
echo "LABEL=backup /mnt/backup ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
sudo mount /mnt/backup

The nofail option means your machine will still boot if the drive is unplugged.

Step 3: write the backup script

This is the whole backup system. Save it as /usr/local/bin/backup:

#!/usr/bin/env bash
set -euo pipefail

DEST="/mnt/backup/snapshot-$(date +%Y-%m-%d-%H%M)"
LIST="/etc/backup-paths.txt"
KEEP=14  # keep two weeks of snapshots

# Stale external drive? Warn loudly instead of silently missing the backup.
if ! mountpoint -q /mnt/backup; then
  echo "ERROR: backup drive not mounted at /mnt/backup" >&2
  exit 1
fi

mkdir -p "$DEST"
while IFS= read -r path; do
  [[ -z "$path" || "$path" =~ ^# ]] && continue
  rsync -a --delete "$path" "$DEST/"
done < "$LIST"

# Trim old snapshots.
cd /mnt/backup || exit 1
ls -dt snapshot-* 2>/dev/null | tail -n +$((KEEP + 1)) | xargs -r rm -rf

Make it executable:

sudo chmod +x /usr/local/bin/backup

That’s the whole thing. rsync -a --delete makes an exact mirror (the --delete removes files on the backup that no longer exist in the source, so the backup stays clean). Each run goes into a fresh timestamped directory. Old snapshots beyond two weeks are pruned automatically.

Step 4: schedule it

Open your user crontab:

crontab -e

Add a line that runs the backup every night at 02:30:

30 2 * * * /usr/local/bin/backup >> /var/log/backup.log 2>&1

That is the whole scheduling setup. Linux will quietly back up your files in the background. Plug the drive in whenever the computer is on overnight; leave it off whenever you don’t need it.

To verify the cron job exists:

crontab -l | grep backup

Step 5: the offsite copy

You have two good, cheap, no-install options for the offsite copy:

Option A: Backblaze B2 + rclone (recommended for power users)

rclone supports dozens of cloud providers. Backblaze B2 costs about USD 6 per TB per month — a fraction of what AWS, Google, or Microsoft charge.

sudo apt install rclone
rclone config            # walk through the wizard, name it "b2"
rclone sync /mnt/backup/ b2:your-bucket-name/

Add the sync to the same crontab, after the local backup finishes:

30 3 * * * rclone sync /mnt/backup/ b2:your-bucket-name/ >> /var/log/backup.log 2>&1

Option B: Free cloud accounts (easiest)

Most people’s actual important files fit in 15 GB — that’s a free Google Drive or Microsoft OneDrive account. Install the corresponding sync client:

sudo apt install rclone        # rclone can also do this
rclone config                  # follow the wizard for Google Drive or OneDrive

Then sync your Documents folder straight to the cloud, no external drive required:

rclone sync /home/yourname/Documents gdrive:Documents-Backup

Restore: the part most guides skip

A backup you have never restored from is a backup you do not actually have. Once a quarter, do this:

  1. Pick a random file from your backup. Delete it from your main machine.
  2. Restore it from the external drive: rsync -a /mnt/backup/snapshot-latest/your/file /home/yourname/
  3. If that worked, restore the same file from the offsite copy.
  4. If that worked, your backup is real.

This takes ten minutes. It is the difference between “a backup I trust” and “a backup I think I have”.

What you do not need

If you only do one thing

Buy an external SSD. Plug it in. Run the rsync command once a week by hand. That is a 50% solution. It is infinitely better than no solution.

Found this useful? We’re publishing more guides over the coming weeks. Back to all resources →