BorgBackup, usually called Borg, is an open-source deduplicating backup program that stores point-in-time archives of files in a repository, splitting data into chunks so that each unique chunk is saved only once. In backup & recovery for Linux and Unix servers, it is valued for space-efficient daily snapshots, built-in compression and authenticated encryption, and efficient transfers to remote repositories over SSH.
Borg began in 2015 as a community fork of the Attic project and is written mainly in Python with performance-critical parts in C and Cython. It runs on the command line, which makes it a natural fit for scheduled server backups driven by cron, systemd timers or wrapper tools such as borgmatic.
How Borg deduplicates data
Borg deduplicates by cutting every file into variable-length chunks with content-defined chunking, hashing each chunk and storing only chunks whose identifier is not already present in the repository. A rolling hash called buzhash decides where chunk boundaries fall, so inserting a few bytes into a large file shifts only nearby boundaries instead of changing every chunk that follows.
Each backup run creates an archive, which is a named list of files and pointers to chunks. Because unchanged chunks are referenced rather than copied, every archive looks like a full backup when restored while consuming storage close to an incremental one. A local chunks cache lets Borg skip unchanged files quickly by comparing file metadata before reading content.
The table below lists the main building blocks of a Borg repository and what each one contributes.
| Component | Role | Practical effect |
|---|---|---|
| Repository | Storage location for all chunks and metadata | One target can hold years of archives |
| Archive | Named snapshot of selected paths | Restorable as a complete file tree |
| Chunk | Deduplicated piece of file content | Stored once, referenced many times |
| Manifest | Index of archives in the repository | Lets clients list and select archives |
| Chunks cache | Client-side record of known chunks | Speeds up repeated backup runs |
Encryption and compression options
Borg applies compression and then encryption on the client before any data leaves the server, so a remote repository host never sees plaintext. The encryption mode is chosen once with borg init and cannot be changed later without creating a new repository.
The modes differ mainly in where the key is stored. With repokey modes, the encrypted key sits inside the repository and is unlocked by a passphrase; with keyfile modes, the key stays on the client, which protects against passphrase guessing on a stolen repository but makes exporting the key mandatory for disaster recovery.
| Mode | Key location | Typical use |
|---|---|---|
| repokey-blake2 | Inside the repository, passphrase protected | Default choice for most servers |
| keyfile-blake2 | Client home directory | Untrusted repository hosts |
| authenticated | Repository, integrity only | Trusted storage needing tamper detection |
| none | No key | Testing or already encrypted storage |
Compression is selectable per run. lz4 is the fast default, zstd offers the best balance at levels around 3 to 6, and lzma yields the smallest output at a high CPU cost. The auto setting first tests whether data is compressible, which avoids wasting time on media files and encrypted blobs.
Core commands and repository workflow
A Borg workflow follows a create, prune, compact and check cycle that keeps the repository consistent and bounded in size. Remote repositories are reached through SSH, where the server side runs borg serve and can be restricted to a single path or to append-only mode.
| Command | Purpose | When it runs |
|---|---|---|
| borg init | Creates a repository and sets encryption | Once, at setup |
| borg create | Writes a new archive | Every scheduled backup |
| borg prune | Removes archives outside the retention policy | After each backup run |
| borg compact | Frees space left by deleted chunks | Weekly or after pruning |
| borg check | Verifies repository and archive integrity | Weekly or monthly |
| borg mount | Exposes archives as a FUSE file system | During restores and audits |
Retention is expressed with options such as --keep-daily 7 --keep-weekly 4 --keep-monthly 12, which implements a classic grandfather-father-son rotation. Since version 1.2, pruning only marks data as deleted, and space is reclaimed only by compact, a detail that often explains why a pruned repository does not shrink.
Borg compared with Restic and rsync
Borg competes most directly with Restic, another deduplicating, encrypted backup tool, while rsync solves a narrower problem of file synchronization. The right choice depends on storage targets, platform mix and how much tooling a team wants around the core program.
| Aspect | BorgBackup | Restic | rsync |
|---|---|---|---|
| Deduplication | Content-defined chunks | Content-defined chunks | None, file-level copying |
| Encryption | Built in, client side | Built in, always on | Not provided |
| Remote targets | SSH with borg serve | SSH, S3 and many clouds | SSH or rsync daemon |
| Version history | Many archives per repository | Many snapshots per repository | Single mirror unless scripted |
| Platform focus | Linux, BSD, macOS | Linux, BSD, macOS, Windows | Unix-like systems |
Borg typically achieves strong compression ratios and fast incremental runs, whereas Restic wins on native object storage support and Windows clients. Borg users who need cloud storage often sync the repository with Rclone or use a hosting service that offers Borg over SSH.
Limitations and operational risks
Borg is reliable when operated with discipline, but several design constraints and common mistakes can turn a working setup into an unrecoverable one.
- Lost key or passphrase: encrypted repositories cannot be recovered without them, so
borg key exportoutput belongs in a separate safe location. - Single-writer locking: only one client can write to a repository at a time, so many servers should use separate repositories rather than sharing one.
- No native object storage: S3-style targets require extra layers in the 1.x series.
- Borg 2.0 format change: the new repository format is not compatible with 1.x, so migration needs a planned transfer of archives.
- Untested restores: archives that are never extracted or mounted may hide exclusion mistakes until a real incident.
Pairing Borg with append-only remote access and a periodic restoration test addresses the most serious risk, which is an attacker or faulty script deleting backups from a compromised server.
The simple explanation
BorgBackup is a tool that copies a server’s files into a safe storage place every day. It is clever about space. When a file has not changed, Borg does not store it again. It simply notes that yesterday’s copy is still valid.
Imagine a photo album where you only glue in the pictures that are new, yet every page still shows the whole collection. That is how Borg can keep months of daily backups in little extra space. It also locks everything with a secret key, so only the owner can read the backups.
How it is used in practice
A small web agency runs 12 Linux servers hosting customer websites and databases, about 900 GB of data in total. Each night at 02:00, a systemd timer starts borgmatic, which dumps the databases and runs borg create to a dedicated storage server over SSH in append-only mode. Daily changes average 6 GB, and after compression and deduplication each new archive adds only about 2 GB to the repository.
The retention policy keeps 14 daily, 8 weekly and 12 monthly archives. After a year, the repositories hold 34 restore points per server in roughly 1.4 TB of disk. When a faulty plugin update corrupts a customer site, an administrator runs borg mount, browses the archive from three days earlier and restores the site in about 20 minutes without touching any other data.