Logo

Redundant Linux backups with a single command

Set up military-grade, cost-effective backups with Borgmatic—combining local USB and Hetzner cloud storage—in just 15 minutes, ensuring your data is safe even if your laptop takes a coffee bath.

Published: 08 Mar, 2025


As someone who’s used Linux since the days of CD-ROM installations, I’ve tried every backup solution under the sun. But Borgmatic combined with Hetzner Storage Box + local USB drive has become my ultimate backup setup. Here’s why:

  1. Military-grade encryption your data stays yours
  2. Deduplication magic store years of backups in small space
  3. Single config file simplicity
  4. Local + cloud redundancy for easy disaster recovery
  5. Cheap backup everything almost free of charge.

What You’ll Need

  • Ubuntu 24.04 LTS (or any modern Linux distro)
  • External USB drive
  • Hetzner Storage Box ($4/TB month)
  • 15 minutes of time

Step 1: Setting up repositories

Mount your USB drive somewhere. I’ll assume it’s at /media/me/mydrive.

Then, initialize a Borg repository on the drive:

sudo borg init -e authenticated /media/me/mydrive

You should use full disk encryption for your USB drive, so you don’t encrypt the borg repository itself. You’ll still have authentication to ensure data integrity.

If you’re not using full disk encryption, feel free to encrypt the repo.

Next, buy a storage box from Hetzner, and setup your SSH key from the control panel.

Then, initialize a borg repo on it:

ssh -p23 [email protected] mkdir borg
borg init --encryption=repokey ssh://[email protected]:23/./borg/mylaptop

Step 2: Setup borgmatic

sudo apt install borgmatic
sudo borgmatic config generate

A config file will be generated at /etc/borgmatic/config.yaml. Edit the file to your liking, using the comments to guide you. Here’s an example:

source_directories:
  - /home
  - /etc
  - /var/log

repositories:
  - path: /mnt/borg
    label: local
  - path: ssh://[email protected]:23/./borg/mylaptop
    label: hetzner

exclude_patterns:
  - /home/*/.cache
  - "*.tmp"

keep_daily: 7
keep_weekly: 4
keep_monthly: 6
keep_yearly: 1

encryption_passphrase: abcd1234

before_backup:
  - findmnt /media/me/mydrive > /dev/null || exit 75

The before_backup hook ensures that the USB drive is attached before trying to backup to it, quite handy.

Step 3: Execute backup

I usually run the borgmatic command at the end of every day for my laptop, but I’ll setup a Systemd timer on servers.

First, create the service file:

touch /etc/systemd/system/backup.service
touch /etc/systemd/system/backup.timer

In the backup.service file, paste the following:

[Unit]
Description=Borgmatic backup

[Service]
Type=oneshot
ExecStart=borgmatic --verbosity 1 --list --stats

Inside the backup.timer, paste this code:

[Unit]
Description=Daily Borgmatic Backups

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable the timer:

systemctl daemon-reload
systemctl enable --now backup.timer

This will run backups daily.

Why This Setup Rocks

  • Cost: $4/month for 1TB cloud + free local copies
  • Speed: Initial backup in ~1hr (subsequent ones in minutes)
  • Safety: Encrypted even if Hetzner gets hacked
  • Simplicity: One command to rule them all

This setup is good for both personal and professional. Use it to backup your family photos, as well as critical business data.

I'm currently available for freelance work. If you know someone who would benefit from my expertise, please direct them to my work page, or email me their contact details.


Email me if you have any questions about this post.

Subscribe to the RSS feed to keep updated.