BorgBackup Linux Encrypted Deduplicated Backup Guide

Need a Cloud Server to Follow This Guide?
Deploy your Linux VPS or Docker container with free credits from our vetted cloud partners:

Data loss is an inevitable risk in modern systems administration. Whether facing hardware failure, software corruption, or malicious ransomware attacks, having a reliable disaster recovery plan is non-negotiable. Traditional backup utilities copy entire files or rely on simple incremental chains that degrade over time. Enter BorgBackup (commonly known as Borg), a modern, highly efficient deduplicating backup program designed for Linux environments.

By utilizing content-defined chunking, Borg significantly reduces storage consumption by ensuring identical data blocks are only stored once. Furthermore, it incorporates authenticated client-side encryption, ensuring that your sensitive workloads remain secure even when backed up to untrusted remote cloud storage.

Core Concepts and Architecture

Before diving into practical implementation, understanding Borg’s underlying architecture helps clarify why it excels as a Linux backup solution:

  • Repositories: A repository is a secure, compressed, and encrypted database containing all backup archives and deduplicated chunks.
  • Archives: An archive represents a point-in-time snapshot of your files and directories. Multiple archives share the same repository efficiently.
  • Deduplication: Borg breaks files into variable-length chunks using a cryptographic rolling hash. If a file changes slightly, only the modified chunks are stored.
  • Authenticated Encryption: Using HMAC-SHA-256 and AES-OCB, Borg guarantees both the confidentiality and integrity of your data.

Prerequisites and Installation

Borg is packaged for virtually all major Linux distributions. To install it, use your system’s native package manager.

On Debian, Ubuntu, or Linux Mint:

sudo apt update && sudo apt install borgbackup

On RHEL, AlmaLinux, or Rocky Linux (via EPEL):

sudo dnf install epel-release && sudo dnf install borgbackup

Step 1: Initializing a Borg Repository

The first step in establishing your backup workflow is creating the target repository. You can host repositories locally, on secondary drives, or remotely via SSH. For maximum security, always use passphrase-based encryption.

Initialize a repository with authenticated encryption:

export BORG_REPO="/mnt/backup-drive/borg-repo"
borg init --encryption=repokey

Borg will prompt you to set a strong passphrase. Store this passphrase and your exported key safely; losing them means permanent data loss.

Step 2: Creating Your First Backup Archive

With the repository initialized, you can create your first backup archive. Borg allows you to name archives dynamically using environment variables or command-line syntax.

Run the following command to back up your /var/www directory:

borg create --stats --progress ::archive-{now:%Y-%m-%d_%H:%M:%S} /var/www

The --stats flag provides a summary of data reduction, deduplication ratios, and transfer speeds, while --progress outputs real-time progress indicators.

Step 3: Automating Maintenance and Retention Policies

Backups accumulate quickly. To manage storage space effectively, Borg provides a robust pruning mechanism through the borg prune command, which implements generational retention schemes (grandfather-father-son).

To retain the last 7 daily, 4 weekly, and 6 monthly archives while automatically pruning older ones, execute:

borg prune --list --keep-daily=7 --keep-weekly=4 --keep-monthly=6 ::

Step 4: Restoring Data from an Archive

Restoring files from a Borg repository is fast and non-destructive. You can extract an entire archive or mount the repository as a FUSE filesystem to selectively copy specific files.

To list all available archives in your repository:

borg list

To extract a specific archive into a recovery directory:

mkdir /tmp/restore && cd /tmp/restore
borg extract ::archive-2026-03-30_12:00:00

Alternatively, mount the repository to browse it like a standard directory tree:

mkdir /mnt/borg-mount
borg mount :: /mnt/borg-mount

When finished, unmount the filesystem cleanly:

:

fusermount -u /mnt/borg-mount

Frequently Asked Questions

How does BorgBackup achieve deduplication?

Borg uses content-defined chunking with a rolling cryptographic hash algorithm. Instead of splitting files at fixed byte intervals, it analyzes the data stream for specific byte patterns, creating variable-length chunks. This ensures that inserting or deleting data in the middle of a file only affects local chunks, leaving surrounding blocks untouched for future deduplication.

Is it safe to store Borg repositories on untrusted cloud storage?

Yes. Borg uses strong client-side encryption (such as AES-OCB) before any data leaves your local machine. Because encryption and authentication occur locally, cloud providers only see ciphertext and cannot read your data or tamper with it without detection.

How can I automate Borg backups via cron or systemd timers?

You can automate backups by writing a shell script that exports the BORG_REPO and BORG_PASSPHRASE variables, executes the borg create command, and follows up with borg prune. Wrap this script in a systemd service and timer pair for reliable, unattended execution.

Conclusion

Implementing a robust backup strategy is the ultimate safeguard for any Linux server environment. By combining efficient chunk-level deduplication with robust client-side encryption, BorgBackup delivers enterprise-grade data protection with minimal resource overhead. Start integrating Borg into your server maintenance routines today, and ensure your critical data remains secure, compact, and effortlessly recoverable.

Recommended Hardware for This Setup

Tested, power-efficient gear curated for 24/7 home servers, Docker containers, and local labs.

Curated on Amazon
TOP PICK: HOME SERVER

Intel N100 Mini PC (16GB RAM, 500GB SSD)

Whisper-quiet, ultra-low 6W idle power. The undisputed favorite for 24/7 Docker, Jellyfin hardware transcoding, and Proxmox.

Check Price on Amazon
COMPACT LAB

Raspberry Pi 5 (8GB Starter Kit)

Blazing quad-core ARM performance. Ideal for dedicated Pi-hole ad-blocking, WireGuard mesh nodes, and lightweight automation.

Check Price on Amazon
STORAGE & SPEED

Crucial P3 Plus 1TB/2TB PCIe 4.0 NVMe

Up to 5000MB/s speeds. Essential for high-IOPS database operations, Docker container images, and snappy Nextcloud sync.

Check Price on Amazon
HOMELAB NETWORK

TP-Link 8-Port Gigabit Switch (TL-SG108)

Silent fanless steel housing, plug-and-play, traffic prioritization (QoS). Essential for wiring up your Home Server, NAS, and Pi with zero Wi-Fi lag.

Check Price on Amazon

Disclosure: BriteHacks is reader-supported. When you buy through links on our site or deploy infrastructure, we may earn an affiliate commission at no extra cost to you. As an Amazon Associate, we earn from qualifying purchases.

AH

Alex Hayes

Lead Systems Architect & DevOps Editor

Alex is a senior systems administrator and Linux architect specializing in self-hosted cloud infrastructure, Docker containerization, Kubernetes, and network reliability. Every tutorial is verified in live home lab and cloud VPS environments before publication.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
BriteHacks is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. As an Amazon Associate, we earn from qualifying purchases.