Complete Guide to Backups with BorgBackup on Debian 13

Automated English translation of the original Spanish article. Code examples keep their original identifiers.

When Backups Fail

It was 2 AM on a Tuesday. A poorly written script began traversing /home and wiped out configuration files for dozens of users. The team had backups… but they were stored on the exact same server. And that server was already compromised.

This story happens far more often than people admit publicly. It is rarely due to a lack of tooling, but rather the result of a negligent backup architecture.

This guide shows you how to set up a serious and robust backup strategy using BorgBackup on Debian 13: deduplicated, end-to-end encrypted, automated, and—above all—recoverable when you actually need it.

Why BorgBackup?

Borg is not the only backup tool around, but it is one of the few that brings together several critical features in a single utility:

  • Block-level deduplication: It only saves changes between snapshots, drastically reducing required storage space.
  • Zero-knowledge client-side encryption: Your data leaves the server encrypted. The remote provider can never access it.
  • Efficient compression: Supports LZ4 (prioritizing speed) and Zstandard (better compression ratio).
  • FUSE mounting: You can mount and explore any backup just like a normal filesystem.

How It Works Internally (Without the Complexity)

Before running the first command, it pays to understand the workflow:

  • Chunking: Borg splits files into variable-sized chunks.
  • Local deduplication: It compares these chunks with the ones it already has and only uploads new ones.
  • Encryption: Each chunk is encrypted with the repository key before transmission.
  • SSH transport: Uses standard SSH without additional dependencies.
  • Remote storage: The destination receives only opaque chunks that it cannot decrypt.

This design explains why Borg’s incremental backups are so fast. You can modify ten 1 GB files, and if only 50 MB changed overall, Borg will only transfer those ~50 MB.

Prerequisites

  • A server running Debian 13 (in our case) with root access.
  • An active internet connection.
  • An account on BorgBase (our choice here) or your own SSH server.
  • 10-15 minutes for the initial setup.

1. Installation

BorgBackup is available directly in the Debian 13 repositories:

apt update && apt install borgbackup -y

Verify the installed version:

borg --version

2. Generating SSH Keys

For automation, we need passwordless SSH access:

ssh-keygen -t ed25519 -a 100 -C "root@tu-servidor-borg"

Two files will be generated:

FilePurpose
/root/.ssh/id_ed25519Private key (never leaves the server)
/root/.ssh/id_ed25519.pubPublic key (uploaded to the destination)

You can view the public key with:

cat /root/.ssh/id_ed25519.pub

3. Remote Repository Setup

BorgBase is a hosting service purpose-built for Borg.

  1. Upload your public key in the control panel.
  2. Create a new repository.
  3. Grant Full Access permissions to the key.
  4. Copy the repository URL (format: [email protected]:repo).

Option B: Self-Hosted SSH Server

Any Linux server running Borg will work. You just need an empty directory for the repository and SSH key access.

4. Initializing the Repository

This command only needs to be run once:

export BORG_RSH='ssh -i ~/.ssh/id_ed25519'
borg init --encryption=repokey-blake2 usuario@repo:repo

Borg will prompt you for a passphrase.

Important: Without this passphrase and the repository key, your data is permanently unrecoverable. Store them securely away from this server.

5. First Manual Backup

borg create --stats --progress --compression lz4 \
    usuario@repo:repo::home-{now:%Y-%m-%d} \
    /home

The initial run will upload all data. Subsequent runs will only transmit changed chunks. At the end, you will see detailed deduplication and compression statistics.

6. Automation via Script

Backup Script (/root/backupborg.sh)

#!/bin/bash

export BORG_RSH='ssh -i ~/.ssh/id_ed25519'
export BORG_PASSPHRASE='TU_CONTRASEÑA_SEGURA'
REPO='usuario@repo:repo'

# Crear backup
borg create --stats $REPO::home-{now:%Y-%m-%d_%H%M} /home

# Política de retención
borg prune -v --list \
    --keep-daily=7 \
    --keep-weekly=4 \
    $REPO

# Liberar espacio
borg compact $REPO

Security note: Keeping the passphrase in the script is a pragmatic tradeoff. The file must have strictly restricted permissions (chmod 700). If you require higher security, consider systemd credentials, pass, or an external secret manager.

Apply the permissions:

chmod 700 /root/backupborg.sh

Scheduling with Cron

crontab -e

Add the entry:

00 03 * * 0 /root/backupborg.sh >> /var/log/borg_backup.log 2>&1

(Runs every Sunday at 3:00 AM). Check the log file after the first run.

7. Disaster Recovery Plan (DRP)

This is where most backup strategies fail.

Exporting the Recovery Key

borg key export --paper usuario@repo:repo > llave_recuperacion.txt

Store this file offsite (printed paper key, offline password manager, or an offsite USB drive).

What You Need to Recover

Exactly three things:

  1. SSH access to the repository (private key).
  2. The passphrase.
  3. The repository key (or the exported paper key).

If any of these three is missing, your data is completely inaccessible.

Recovery Operations

Listing backups:

borg list $REPO

Restoring a full backup:

borg extract $REPO::home-2025-06-15 /ruta/destino

Browsing without extracting (via FUSE):

borg mount $REPO::home-2025-06-15 /mnt/borg-restore
ls /mnt/borg-restore
borg umount /mnt/borg-restore

Strong recommendation: Perform at least one full recovery dry run before you actually need it. Panic under pressure is a terrible counselor.

8. Self-Hosted vs. Managed Service

Self-Hosted (NAS, Secondary Server, Raspberry Pi)

Pros:

  • Complete control.
  • No recurring third-party costs.
  • Zero external dependencies.

Significant Cons:

  • Requires ongoing maintenance.
  • Vulnerable to physical disasters or concurrent hardware failures.
  • No automated alerting if jobs fail silently.

BorgBase (Our Setup)

Pros:

  • Professional, monitored infrastructure.
  • Append-only mode (a compromised source server cannot delete old snapshots).
  • Automated failure alerts.
  • Clear visual dashboard and useful statistics.
  • Optimized specifically for Borg.

Cons:

  • Monthly usage-based cost.
  • Reliance on a third-party vendor (though client-side encryption mitigates data exposure risks).

Key takeaway: If your backup server can go down at the same time as your primary server (e.g., same provider, same datacenter), self-hosting loses its biggest advantage. A managed offsite service guarantees proper isolation.

Proper Backups Are Part of Security

BorgBackup on Debian 13—especially paired with BorgBase—provides one of the most balanced setups available today: bandwidth- and storage-efficient, highly secure thanks to zero-knowledge encryption, and reliable in day-to-day operations.

However, the best tool in the world is useless if you have never tested it in a real recovery drill.

The real difference lies in operational discipline: set up the backup, automate it, safeguard your keys, and, above all, practice restoring your data at least once.

Do it right from day one. When disaster strikes and you actually need your data back, you will be glad you put in the extra time.