Deployment guide

Encrypted VPS Backups with BorgBackup

Deploy on a VPS Cloud →

Security & Monitoring8 min read

Encrypted VPS Backups with BorgBackup

BorgBackup is one of the most battle-tested deduplicating backup engines in the Linux ecosystem. Its content-based chunk deduplication and authenticated encryption make it a reference choice for archiving a VPS over time. Self-hosted, it gives you dense, encrypted backups that are restorable down to the individual file.

Why back up your VPS with BorgBackup

Borg takes deduplication to a remarkable level: it splits files into chunks with variable boundaries, which detects identical data even when it is shifted within a file. As a result, weeks of daily archives fit in a fraction of the space of a single full copy. To this are added configurable compression (lz4, zstd, zlib), authenticated encryption (the repository resists tampering, not just reading) and a robust repository format. Self-hosting Borg on the VPS, pushing archives to a remote repository (ideally a BorgBackup-compatible service), gives you economical backups entirely under your cryptographic control, without entrusting your keys to a third party.

The strengths of BorgBackup

  • Variable-boundary chunk deduplication, formidably efficient on data that changes little.
  • Authenticated encryption: confidentiality and integrity guarantee against any tampering with the repository.
  • Compression of your choice (zstd, lz4, zlib) to trade off between size and speed.
  • Named and timestamped archives, mountable via FUSE to browse a backup like a folder.
  • Granular retention policy via borg prune (daily, weekly, monthly, yearly).
  • Efficient transfer to a remote repository over SSH, sending only the new chunks.

Prerequisites for this deployment

Borg stays light on CPU, but its deduplication keeps an index in memory: plan for a VPS with 1 to 2 GB of RAM, with consumption growing with the number of chunks in the repository. Install the borgbackup package (and borgmatic to orchestrate more simply). On the destination side, you need either a Borg-compatible storage service or a second server accessible over SSH where Borg is also installed. An SSH key pair for non-interactive transfer and a location outside the VPS to keep the repository passphrase round out the prerequisites. Borgmatic, driven by a YAML file, considerably simplifies automation.

Configure Borg backups with borgmatic

01

Install Borg and borgmatic

On the VPS, install both packages (apt install borgbackup borgmatic). Check the version with borg --version. Borgmatic adds a declarative configuration layer on top of the raw Borg commands.

02

Initialize the remote encrypted repository

With an SSH key already deployed, initialize the repository: borg init --encryption=repokey-blake2 ssh://user@backup-host/./borg-repo. The repokey mode stores the encrypted key in the repository; you must keep the passphrase in a safe place outside the VPS.

03

Write the borgmatic configuration file

In /etc/borgmatic/config.yaml, declare the source_directories (for example /etc, /var/www, /opt), the remote repositories, the passphrase via an environment variable, and zstd compression. Borgmatic will chain create, prune and check in a single call.

04

Add database hooks

Borgmatic can dump your databases before the backup. Declare a postgresql_databases or mariadb_databases hook: the dump is generated, included in the archive, then cleaned up automatically, guaranteeing a consistent copy of the database.

05

Set retention and run a backup

Configure keep_daily: 7, keep_weekly: 4, keep_monthly: 6 in the retention section, then run borgmatic --verbosity 1. Borg transfers only the new chunks, making subsequent runs very fast.

06

Schedule and verify restores

Enable the systemd timer provided by borgmatic (systemctl enable --now borgmatic.timer) for daily execution. Test a restore with borgmatic extract --archive latest to a test folder, and let borgmatic check validate integrity regularly.

BorgBackup or Restic: which to choose?

CriterionBorgBackupRestic
Storage modelSingle-machine repository, SSH accessMulti-source to a single object repository
Native backendsLocal and SSH (Borg server required)S3, B2, Azure, SFTP, rest-server
DeduplicationVariable chunks, very denseVariable chunks, efficient
CompressionConfigurable (zstd, lz4, zlib)Limited (historically no compression)
EncryptionAuthenticated (tamper-proof)Client-side AES-256
Concurrent accessOne client at a time on the repositoryMultiple clients in parallel
Object storage (S3)Indirect (via a third-party layer)Native and direct
Orchestration toolborgmatic (YAML)Scripts or third-party wrappers

Borg's Achilles' heel is that it allows only one client at a time on a repository and can leave a residual lock if a run is interrupted: monitor and automate clearing stuck locks with borg break-lock in your script, but only after verifying that no other process is writing. To guard against a VPS compromise, create on the backup server side a restricted SSH key with command="borg serve --append-only": the attacker will then only be able to add archives, never destroy the existing history.

Archive your VPS without compromise

With a ServOrbit Cloud VPS and its preconfigured template, deploy BorgBackup and borgmatic in a few minutes for encrypted, deduplicating and automated backups.

Need help?

Browse our help center and FAQ, or write to our team — support in French, English and Arabic.