How to Set Up Incremental Backups with Borg
BorgBackup (Borg) is a deduplicating backup program that efficiently stores incremental backups with compression and encryption. It is one of the most space-efficient backup solutions available for your Breeze server, as it only stores changed data blocks between backups.
Installing Borg
# Ubuntu/Debian
sudo apt update && sudo apt install -y borgbackup
# RHEL/AlmaLinux/Rocky
sudo dnf install -y borgbackup
# Verify installation
borg --version
Initializing a Backup Repository
Create an encrypted repository for storing backups:
# Local repository
borg init --encryption=repokey /backup/borg-repo
# Remote repository via SSH
borg init --encryption=repokey ssh://backup-user@backup-server/~/borg-repo
Choose your encryption mode:
repokey— encryption key stored in the repo (protected by passphrase)keyfile— encryption key stored locally (more secure, but key must be backed up separately)none— no encryption (not recommended for sensitive data)
Important: Back up your encryption key and passphrase separately. Without them, your backups are unrecoverable.
Creating Your First Backup
borg create --stats --progress \
/backup/borg-repo::'{hostname}-{now:%Y-%m-%d_%H:%M}' \
/home \
/etc \
/var/www \
--exclude '*.pyc' \
--exclude '/home/*/.cache' \
--exclude '/var/www/*/node_modules'
Automated Backup Script
Create /usr/local/bin/borg-backup.sh:
#!/bin/bash
set -euo pipefail
export BORG_REPO="/backup/borg-repo"
export BORG_PASSPHRASE="your-secure-passphrase"
LOG="/var/log/borg-backup.log"
echo "$(date): Starting Borg backup" >> "$LOG"
# Create backup
borg create --stats --compression zstd,3 \
::'breeze-{now:%Y-%m-%d_%H:%M}' \
/home \
/etc \
/var/www \
/var/lib/mysql-backup \
--exclude '*.pyc' \
--exclude '*/node_modules' \
--exclude '*/.cache' \
2>&1 >> "$LOG"
# Prune old backups
borg prune --stats \
--keep-daily=7 \
--keep-weekly=4 \
--keep-monthly=6 \
2>&1 >> "$LOG"
# Compact repository to reclaim freed space
borg compact 2>&1 >> "$LOG"
echo "$(date): Backup completed successfully" >> "$LOG"
chmod +x /usr/local/bin/borg-backup.sh
Scheduling with Cron
# Run nightly at 2 AM
echo "0 2 * * * /usr/local/bin/borg-backup.sh" | sudo crontab -
Listing and Inspecting Backups
# List all archives
borg list /backup/borg-repo
# Show archive details
borg info /backup/borg-repo::breeze-2026-03-01_02:00
# List files in an archive
borg list /backup/borg-repo::breeze-2026-03-01_02:00 | head -50
Restoring Files
# Restore entire archive to current directory
cd /tmp/restore
borg extract /backup/borg-repo::breeze-2026-03-01_02:00
# Restore specific files or directories
borg extract /backup/borg-repo::breeze-2026-03-01_02:00 home/user/important-file.txt
# Restore to original location
cd /
borg extract /backup/borg-repo::breeze-2026-03-01_02:00 var/www/mysite
Pruning Strategy
Configure retention policies that match your needs:
borg prune \
--keep-within=2d \ # Keep all backups from last 2 days
--keep-daily=7 \ # Keep 1 per day for 7 days
--keep-weekly=4 \ # Keep 1 per week for 4 weeks
--keep-monthly=12 \ # Keep 1 per month for 12 months
--keep-yearly=2 # Keep 1 per year for 2 years
Best Practices
- Always encrypt your repository, especially for off-site backups
- Store the encryption key and passphrase in a separate, secure location
- Test restores regularly to verify backup integrity
- Use
--compression zstdfor the best balance of speed and compression ratio - Run
borg checkperiodically to verify repository consistency - Dump databases to files before running Borg so they are in a consistent state
- Use
borg compactafter pruning to reclaim disk space on your Breeze server