You’re picking between restic and Borg for the next backup deployment. Both encrypt client-side, both deduplicate, both have good operator stories. Borg’s distinguishing feature is the SSH+append-only repository model — a host can push backups to a server but cannot delete previous archives, even if the host is fully compromised. This article walks the Borg install, repo init in append-only mode on a remote server, the backup script, and the prune cadence run from the trusted side.
How to verify
On a Borg-backed host you can see the repo, the archives, and the storage footprint:
borg --version
borg list "$BORG_REPO" | head
borg info "$BORG_REPO"
systemctl list-timers '*borg*'
journalctl -u borg-backup.service --since=yesterday
borg check --verify-data "$BORG_REPO"
borg info reports unique/dedup/compressed sizes — the column to watch is “Storage size”, which is what the dedup actually buys you on disk. borg check is the integrity step.
What’s happening
Borg writes a content-addressed repository: each file is chunked with Buzhash (or fixed-size if specified), each chunk is hashed, encrypted with AES-CTR, MAC’d with HMAC-SHA256, and stored. Two archives that share content share chunks on disk. The repo holds a manifest, an index, and the chunk segments; a backup creates a new archive (named like host::myapp-2026-06-02T02:00:00) pointing at the chunks for that snapshot.
The model that matters: the repository lives on a remote server, the host SSHes in and runs borg serve on the other side, and the server SSH config restricts the host’s key to command="borg serve --append-only --restrict-to-repository /var/borg/host-01". From the host, borg create works; borg delete fails. Deletion (and prune) happens from a separate trusted operator account that has a non-restricted key, on a different schedule.
The procedure
-
Install borg on host and on the backup server. Ubuntu ships a recent version; pip works too.
sudo apt update && sudo apt install -y borgbackup borg --version -
Create the repo on the server. On the server, create the user, the repo directory, and the SSH key restriction.
sudo useradd -m -d /var/borg -s /bin/bash borg sudo install -m 0700 -d -o borg -g borg /var/borg/host-01On the host, generate the key, copy the public part to the server, and lock it down in
~borg/.ssh/authorized_keys:# /var/borg/.ssh/authorized_keys on the server, one line per host command="borg serve --append-only --restrict-to-repository /var/borg/host-01",restrict ssh-ed25519 AAAAC3Nz... host-01-backup -
Initialize the repo from the host.
repokey-blake2keeps the encryption key inside the repo, protected by a passphrase;keyfile-blake2separates the key from the repo and is stricter at the cost of operator complexity.export BORG_REPO='ssh://borg@backup.example.com/var/borg/host-01' export BORG_PASSPHRASE_FILE=/root/.borg-passphrase sudo install -m 0400 /dev/null /root/.borg-passphrase openssl rand -base64 48 | sudo tee /root/.borg-passphrase >/dev/null borg init --encryption=repokey-blake2 "$BORG_REPO" -
Wire the backup service+timer. The host’s job only ever creates archives; prune runs from the trusted side.
# /etc/systemd/system/borg-backup.service [Unit] Description=Borg backup Wants=network-online.target After=network-online.target [Service] Type=oneshot Environment=BORG_REPO=ssh://borg@backup.example.com/var/borg/host-01 Environment=BORG_PASSPHRASE_FILE=/root/.borg-passphrase Environment=BORG_RSH=ssh -i /root/.ssh/borg_ed25519 -o StrictHostKeyChecking=yes ExecStart=/usr/bin/borg create \ --stats --compression zstd,9 \ --exclude-from /etc/borg/excludes \ ::myapp-{now:%Y-%m-%dT%H:%M:%S} \ /etc /home /var/lib/myapp -
Run prune from the trusted side. On the backup server (or a dedicated maintenance host with the unrestricted key),
borg pruneenforces retention. Because the host’s key cannot delete, this is the only path that frees space.borg prune --list --keep-daily 7 --keep-weekly 4 --keep-monthly 12 "$BORG_REPO" borg compact "$BORG_REPO" -
Check integrity monthly. Read-the-data check is heavy on bandwidth but essential.
borg check --verify-data --progress "$BORG_REPO" -
Mount and verify.
borg mountexposes an archive via FUSE; tail the audit log or diff against the live data to confirm a restore would work.sudo apt install -y borgbackup fuse borg mount "${BORG_REPO}::myapp-2026-06-02T02:00:00" /mnt/restore ls /mnt/restore/etc | head sudo umount /mnt/restore
Common pitfalls
- An append-only repo is not write-once forever — a malicious operator with the trusted prune key can still delete archives; rotate the prune key separately from the backup key.
borg compactrewrites segments after prune and is when storage actually frees — without it, pruned archives still consume disk.- The passphrase plus the keyfile (for
keyfile-blake2) are both required to read the repo — losing either is unrecoverable. - A single Borg repo per host scales fine; one shared repo across many hosts dedups across them but couples their fates.
BORG_RELOCATED_REPO_ACCESS_IS_OKexists because legitimate operators get bitten by repo relocation — keep the path stable.
In the engagements we run, Borg is the choice when the customer’s threat model includes a compromised host being able to wipe its own backups — append-only with separate trusted prune keys, repo per host, and the prune host on its own network segment. See /en/services/managed-operations/ and the broader backup tier discussion in /en/knowledge-base/disaster-recovery-drill/.