CLI Backup with Borg in DirectAdmin: Incremental Backup Strategy, Automation Script, and Full Restore Guide

This article provides a complete guide to using Borg as an advanced incremental backup system for DirectAdmin. It covers preparing DirectAdmin backups, installing Borg, creating local or remote repositories, automating backups with a post-backup script, managing retention policies, and performing full restores by mounting Borg archives. Borg serves as a powerful, free alternative to FTP-based remote backups.

Borg BackupDirectAdmin CLI BackupIncremental Backup

~2 min read · Updated Mar 1, 2026

1. Why Use Borg for DirectAdmin Backups?


If you are not satisfied with FTP as a remote backup method and want a more advanced solution, Borg is an excellent choice. It provides:


  • Incremental backups
  • Deduplication and compression
  • Retention policies (daily, weekly, monthly)
  • Local or remote repository support

2. Step 1: Create DirectAdmin Backups Without Heavy Data


Go to:


Admin Backup/Transfer → Schedule

Then configure:


  • Schedule backups daily (or as needed)
  • Unselect Domains Directory and E-mail Data
  • Set backup path to /home/admin/admin_backups

3. Step 2: Install Borg


CentOS:


yum -y install epel-release
yum -y install borgbackup

Debian/Ubuntu:


apt install borgbackup

4. Step 3: Initialize a Borg Repository


Local repository:


borg init --encryption=none /backups

Remote repository:


REPOSITORY=borgbackup@YOUR_SERVER_IP:/backups/`hostname -f`

Set up SSH keys for passwordless access if needed.


5. Step 4: Automate Borg Backups After Each DirectAdmin Backup


Create the script:


/usr/local/directadmin/scripts/custom/all_backups_post.sh

Insert the following content:


#!/bin/sh
REPOSITORY=borgbackup@YOUR_SERVER_IP:/backups/`hostname -f`

borg create -v --stats \
    $REPOSITORY::'{hostname}-{now:%Y-%m-%d_%H:%M}' \
    /home \
    /var/www/html \
    /etc \
    /usr/local/directadmin > /tmp/borg-stat.tmp 2>&1

if [ "$?" -le 1 ]; then
    borg prune -v $REPOSITORY --prefix '{hostname}-' \
        --keep-daily=7 --keep-weekly=4 --keep-monthly=6
else
    date >> /tmp/borg-stat.tmp
    mail -s "backup failed on server `hostname -f`" [email protected] \
        < /tmp/borg-stat.tmp
fi

Set permissions:


chmod 700 /usr/local/directadmin/scripts/custom/all_backups_post.sh

6. Retention Policy


The script keeps:


  • 7 daily backups
  • 4 weekly backups
  • 6 monthly backups

You can adjust these values as needed.


7. Restoring From Borg


The repository path is defined in the script. Example:


REPOSITORY=ssh://[email protected]:2200/home/rbackup/`hostname -f`

7.1 List all backups:


borg list ssh://[email protected]:2200/home/rbackup/`hostname -f`

7.2 Mount a specific backup


Create a mount point:


mkdir /mnt/mybackup

Mount the desired backup:


borg mount ssh://[email protected]:2200/home/rbackup/`hostname -f`::server.mycompany.tld-2019-11-13_05:06 /mnt/mybackup

Check contents:


ls -l /mnt/mybackup

7.3 Restore a specific file


cd /mnt/mybackup/home/admin/domains/clientdomain.com/public_html/wp-admin
cp -a index.php /home/admin/

7.4 Unmount the backup


umount /mnt/mybackup
rmdir /mnt/mybackup

8. Restoring Databases


Databases are stored in:


/home/admin/admin_backups/

Extract the desired backup and restore the required database manually.


Written & researched by Dr. Shahin Siami

Related Articles

Email Client Configuration & Dovecot Quota/Monitoring Guide for DirectAdmin Users

This guide explains how to configure popular email clients (iPhone Mail, Thunderbird, Gmail POP/SMTP), enable Dovecot LMTP quota warnings, and check the last login time for all email accounts on a DirectAdmin server. It includes step by step instructions, recommended IMAP/SMTP settings, and useful administrative scripts.

Continue

Troubleshooting Dovecot in DirectAdmin – Fixing IMAP Errors, Authentication Issues, and SSL Certificate Checks

Dovecot is the IMAP/POP3 server used by DirectAdmin. Sometimes users encounter errors such as “Connection dropped by IMAP server” or “unknown user” during authentication. This guide explains how to fix corrupted Dovecot indexes, understand authentication logs, hide unnecessary warnings, and manually inspect SSL certificates on IMAP ports 143 and 993.

Continue

DNS Troubleshooting in DirectAdmin – When named is Running but Domains Do Not Resolve

Sometimes the named (BIND) service runs normally, yet DNS queries fail or domains do not resolve from outside. This guide provides a complete troubleshooting workflow for checking named listeners, firewall rules, named.conf configuration, DNS propagation issues, subdomain problems, resolv.conf errors, and common Apache/Nginx misconfigurations.

Continue

Managing DNS Records in DirectAdmin – Complete Practical Guide for Administrators

DirectAdmin provides a powerful DNS management system that allows administrators to control TTL values, create SRV records, enable DNSSEC, manage subdomain delegation, automate TLSA records, and perform mass DNS updates. This guide explains all essential DNS operations in DirectAdmin with real-world examples and best practices.

Continue

DNS and Nameservers in DirectAdmin – Complete, Practical, and Professional Guide

DNS is the backbone of the internet, responsible for translating domain names into IP addresses. DirectAdmin allows you to create private nameservers (ns1/ns2), manage DNS zones, configure DNS clustering, use external DNS, and troubleshoot common issues. This guide provides a complete, clear, and practical explanation of DNS concepts and their implementation in DirectAdmin.

Continue

CustomBuild in DirectAdmin – Complete Guide to Installation, Updates, Configuration, and Advanced Customization

CustomBuild is DirectAdmin’s primary software management system. It installs, updates, configures, and rebuilds essential services such as Apache, Nginx, PHP, MariaDB/MySQL, Exim, Dovecot, FTP servers, and more. Because most components are compiled from source, CustomBuild offers exceptional flexibility, fast access to new versions, and optimized performance.

Continue