How to Back Up SQL Databases and Perform Command-Line Backups in DirectAdmin

DirectAdmin provides multiple advanced methods for backing up SQL databases, generating full system backups via command line, restoring SQL dumps, checking disk usage before backups, and using rsync for lightweight home directory backups. This article explains each method in detail, including CustomBuild SQL backups, restore scripts, task.queue restore commands, disk‑space validation, and automated rsync rotation.

DirectAdmin SQL BackupCustomBuild MySQLCommand-Line Backup

~3 min read · Updated Feb 27, 2026

1. Backing Up SQL Files Using CustomBuild


DirectAdmin allows you to generate standalone SQL backups using the mysql_backup option in CustomBuild. These backups are separate from the standard DirectAdmin User backups.


1.1 Creating SQL Backups


da build set mysql_backup yes
da build mysql_backup

To prevent future backups from overwriting the existing SQL dumps, rename the backup directory:


mv mysql_backups mysql_backups.`date +%F`

Note: SQL files generated by CustomBuild include DROP DATABASE and CREATE DATABASE commands, unlike DirectAdmin User backups. They cannot be interchanged.


2. Restoring SQL Files


Once MySQL is running and the da_admin credentials are valid, restore SQL files using:


cd /usr/local/directadmin/custombuild/mysql_backups
wget http://files.directadmin.com/services/mysql/restore_sql_files.sh
chmod 755 restore_sql_files.sh
./restore_sql_files.sh

To also restore the mysql.* tables (only if absolutely necessary):


./restore_sql_files.sh with_mysql

Warning: Restoring mysql.sql overwrites the da_admin password.


2.1 Version Compatibility Warning


SQL backups are not always compatible across MySQL/MariaDB versions. For example:


  • MySQL 5.7 replaced the password column with authentication_string.

Always restore using the same database version when possible.


3. Creating Full Backups via Command Line


3.1 Full Backup of All Users


/usr/local/directadmin/directadmin admin-backup --destination=/home/admin/admin_backups

3.2 Backup Specific Users


/usr/local/directadmin/directadmin admin-backup --destination=/home/admin/admin_backups --user=testuser1 --user=testuser2

3.3 Restoring a Single User


echo "action=restore&ip%5Fchoice=file&local%5Fpath=%2Fhome%2Fadmin%2Fadmin%5Fbackups&owner=admin&select%30=user%2Eadmin%2Etestuser%2Etar%2Egz&type=admin&value=multiple&when=now&where=local" >> /usr/local/directadmin/data/task.queue

To restore to a specific IP:


ip_choice=select&ip=1.2.3.4

4. Automated Restore Script Example


#!/bin/sh
OWNER=admin
LOCAL_PATH=/home/${OWNER}/admin_backups
IP_CHOICE=select
IP=1.2.3.4

echo -n "action=restore&local_path=${LOCAL_PATH}&owner=${OWNER}&when=now&where=local&type=admin";

if [ "${IP_CHOICE}" = "select" ]; then
       echo -n "&ip_choice=select&ip=${IP}";
else
       echo -n "&ip_choice=${IP_CHOICE}";
fi

cd ${LOCAL_PATH}
COUNT=0
for i in `/bin/ls *.gz`; do
{
       echo -n "&select${COUNT}=$i";
       COUNT=$(( $COUNT + 1 ))
};
done;

echo "";
exit 0;

Then pipe the output to the task queue:


/root/restore_all.sh >> /usr/local/directadmin/data/task.queue

5. Checking Disk Usage Before Running Backups


This script prevents backups from running if disk usage exceeds a threshold.


#!/bin/sh
PARTITION=/dev/mapper/VolGroup00-LogVol00
MAXUSED=90

checkfree()
{
        DISKUSED=`df -P $PARTITION | awk '{print $5}' | grep % | cut -d% -f1`
        echo "$DISKUSED < $MAXUSED" | bc
}
if [ `checkfree` -eq 0 ]; then
        echo "$PARTITION disk usage is above $MAXUSED% Aborting backup.";
        exit 1;
fi

exit 0;

Make executable:


chmod 755 /usr/local/directadmin/scripts/custom/user_backup_pre.sh

6. Backing Up /home Using rsync


This method is ideal for large servers or when you want minimal system load.


#!/bin/sh

BACKUP_SOURCE="/home"

DAY_OF_WEEK=`date +%w`
ZERO_ONE=$(($DAY_OF_WEEK % 2))
BACKUP_DESTINATION="/backup/$ZERO_ONE"

mkdir -p ${BACKUP_DESTINATION}

ionice -c3 nice -n 19 rsync -q -a -W --delete $BACKUP_SOURCE $BACKUP_DESTINATION >/var/log/rsync.log 2>&1

echo `date` > ${BACKUP_DESTINATION}/last_rsync.txt

Enable script:


chmod 700 /root/rsync.sh

Schedule via cron:


30 4 * * 2,5 /root/rsync.sh

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