BorgBackup on Ubuntu: ‘Super-Compressed’ Backup Solution and Secure Encryption for Sysadmins

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

The 2 AM Phone Call and a Lesson I’ll Never Forget

2 AM, the phone rang incessantly. On the other end, the night-shift junior broke the news: the staging server’s hard drive had just crashed due to a filesystem error. I bolted upright, breaking into a cold sweat as I checked the old backup script running on rsync. The result was even worse: the 1TB drive I thought was spacious was suddenly full because of dozens of duplicate copies, causing the latest backup to fail halfway through.

After that night, I ditched all manual tar or rsync scripts. On the more than 20 Ubuntu VPSs I manage, the BorgBackup setup process is always my number one priority. If you’re running a server, don’t wait until you lose everything to start looking for a solution.

Why are Sysadmins so Obsessed with BorgBackup?

Unlike rsync which simply copies files, BorgBackup (Borg for short) handles data much more intelligently thanks to two heavy-hitting features:

  • Deduplication: Borg breaks files into small chunks. If you backup a 100GB folder for 10 consecutive days with minimal changes, instead of costing 1TB, Borg might only take up about 110GB.
  • Client-side Encryption: Data is locked with AES-256 right on your server before it’s sent out. Even if a hacker gets hold of the backup drive, they’ll only see a bunch of meaningless characters without the passphrase.
  • Super Compression: With algorithms like LZ4 or Zstandard, storage usage typically drops another 30-50% after deduplication.

Step 1: Quick Installation on Ubuntu

Borg is available in the official repositories, so installation takes less than a minute. I usually run this command on Ubuntu 22.04 or 24.04 LTS.

sudo apt update
sudo apt install borgbackup -y

Check if everything is ready with the command:

borg --version

Step 2: Initialize a Repository

You need a place to store your backups, called a Repository. This can be on an external drive or a remote server via SSH. Here, I’m using repokey mode to encrypt data with a passphrase.

# Create the repo directory
mkdir -p /mnt/backup/my_webapp_repo

# Initialize the repo with the strongest encryption standard
borg init --encryption=repokey /mnt/backup/my_webapp_repo

‘Life-saving’ Note: Borg will ask you to enter a passphrase. Save this password in a manager like Bitwarden or write it down. Losing the passphrase means losing all your data—there’s no ‘Forgot Password’ button here!

Step 3: Run Your First Backup

Suppose I need to backup code at /var/www/html and Nginx config at /etc/nginx. I’ll name this backup after the date for easy tracking.

borg create --stats --progress /mnt/backup/my_webapp_repo::web-2026-05-12 /var/www/html /etc/nginx

When the command finishes, the --stats section will show you the real numbers: the original size and how much Borg ‘shaved’ it down to in MB. The first time will take a while, but subsequent runs will be lightning fast because Borg only sends newly changed data.

Step 4: How to Restore When Disaster Strikes

To see the list of backups performed, use the list command:

borg list /mnt/backup/my_webapp_repo

If you accidentally delete an important config file, you don’t need to restore gigabytes of data. Just ‘extract’ that specific file:

cd /tmp/restore
borg extract /mnt/backup/my_webapp_repo::web-2026-05-12 etc/nginx/nginx.conf

Another ‘killer’ feature is Mount. You can mount the entire backup repository to a folder to browse files like a normal drive using ls and cp. This is much more convenient than manual extraction.

Step 5: Automation and Repository Maintenance

A true Sysadmin never types backup commands by hand every day. Use a simple Bash script and add it to Crontab. Don’t forget to use the prune command to automatically delete old backups, preventing the drive from filling up again.

# Sample automated backup script
export BORG_PASSPHRASE='your_password_here'

borg create /mnt/backup/my_webapp_repo::web-{now:%Y-%m-%d} /var/www/html

# Keep only 7 daily, 4 weekly, and 6 monthly backups
borg prune -v --list --keep-daily=7 --keep-weekly=4 --keep-monthly=6 /mnt/backup/my_webapp_repo

Set this script to run at 1 AM via crontab -e, and you can sleep soundly without worrying about midnight surprises.

Conclusion

Real-world experience has shown me: backup isn’t for fun storage; it’s so you can restore immediately when needed. BorgBackup has saved me at least three times when servers ‘suddenly died.’ It’s fast, efficient, and extremely reliable.

Take 10 minutes to set up Borg today. Don’t wait until you’ve lost all your data to wish you had installed it sooner.

Share: