BorgBackup

Also known as: Borg

On this page 7

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.

ComponentRolePractical effect
RepositoryStorage location for all chunks and metadataOne target can hold years of archives
ArchiveNamed snapshot of selected pathsRestorable as a complete file tree
ChunkDeduplicated piece of file contentStored once, referenced many times
ManifestIndex of archives in the repositoryLets clients list and select archives
Chunks cacheClient-side record of known chunksSpeeds up repeated backup runs
Building blocks of a Borg repository

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.

ModeKey locationTypical use
repokey-blake2Inside the repository, passphrase protectedDefault choice for most servers
keyfile-blake2Client home directoryUntrusted repository hosts
authenticatedRepository, integrity onlyTrusted storage needing tamper detection
noneNo keyTesting or already encrypted storage
Encryption modes in the Borg 1.x series

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.

CommandPurposeWhen it runs
borg initCreates a repository and sets encryptionOnce, at setup
borg createWrites a new archiveEvery scheduled backup
borg pruneRemoves archives outside the retention policyAfter each backup run
borg compactFrees space left by deleted chunksWeekly or after pruning
borg checkVerifies repository and archive integrityWeekly or monthly
borg mountExposes archives as a FUSE file systemDuring restores and audits
Essential Borg commands

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.

AspectBorgBackupResticrsync
DeduplicationContent-defined chunksContent-defined chunksNone, file-level copying
EncryptionBuilt in, client sideBuilt in, always onNot provided
Remote targetsSSH with borg serveSSH, S3 and many cloudsSSH or rsync daemon
Version historyMany archives per repositoryMany snapshots per repositorySingle mirror unless scripted
Platform focusLinux, BSD, macOSLinux, BSD, macOS, WindowsUnix-like systems
Borg versus related backup tools

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 export output 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.