Emergency server help: get in touch

Restore a File, Database or Account from a DirectAdmin Backup (CLI, Tested)

Restore one file, one database or a whole account from a DirectAdmin .tar.zst backup on the command line. Tested on DirectAdmin 1.712 with real screenshots.

Published Updated 15 min read

Update, 9 October 2026 (second review): the file, folder and database restores are now scripts that check every step before changing anything. The previous file recipe renamed the restored file inside the pipeline, so a truncated archive could replace a working file with a fragment; we reproduced that (exit status 0, 26 KB left in place of 200 KB). The database restore now refuses an incomplete dump and runs the mysql client as the account, because a dump can contain shell commands. All three were tested against damaged archives on DirectAdmin 1.712.

Applies to DirectAdmin 1.712 on AlmaLinux 9.8 with MariaDB

Update, 9 October 2026: the single-file and database restore recipes were rewritten after an independent review. The old file recipe extracted and copied the archive member as root without checking whether it was a link, and the database recipe imported with DirectAdmin’s server-wide login. We tested the new recipes on DirectAdmin 1.712 with regular, symbolic-link, hard-link, duplicate, path-traversal and corrupted archive members: only the regular file was restored, a root-only test file never reached the account, and a dump that reached for another database was refused.

Update, 9 October 2026: the single-file restore example now restores wp-config.php with mode 600 instead of 644, which let other accounts read it. Found in an independent review.

Short answer: A DirectAdmin backup is one compressed tar file per account (user.CREATOR.NAME.tar.zst on current versions). Website files sit under domains/ inside it and each database is a plain SQL dump under backup/. To bring back one file or one database you do not need to restore the whole account: list the archive with tar --zstd -tf, check the member, let the account write it back, or import the SQL dump as the database’s own MySQL user. The scripts below refuse to change anything if the archive is damaged. (Reviewed October 2026.)

We ran every command below on our DirectAdmin test server on 6 October 2026 (DirectAdmin 1.712, AlmaLinux 9.8, MariaDB, three WordPress sites). We broke a site on purpose, restored it from the backup and checked the result; the screenshots are the real terminal output with IP addresses masked.

How DirectAdmin names and packs backups

Current DirectAdmin versions compress backups with zstd, so the files end in .tar.zst; older backups and servers set to gzip end in .tar.gz. The name tells you who made the backup and whose it is:

File nameWhat it is
user.admin.bob.tar.zstUser bob, created by the reseller or admin admin
reseller.admin.res1.tar.zstReseller account res1
admin.root.admin.tar.zstThe admin account itself (what our test produced)

Inside, the layout we found on DirectAdmin 1.712 is:

  • domains/DOMAIN/public_html/…: the website files, at the top level of the archive
  • backup/USER_DBNAME.sql: one dump per database, for example backup/admin_wp3.sql. Each table starts with DROP TABLE IF EXISTS, and there is no CREATE DATABASE or USE line, so you choose the target database when you import
  • imap/DOMAIN/MAILBOX/Maildir/…: the mailboxes, also at the top level
  • backup/home.tar.zst: the rest of the home directory (dotfiles, .php logs)
  • backup/*.conf, backup/user.conf, backup/.shadow, backup/login_keys/ and similar: account settings, password hashes and API login keys. Treat backup files as secret and keep them readable by root and the owner only.

Make a fresh backup from the command line

If you are about to change something, take a backup first. As root, da admin-backup runs the same job as Admin Level → Admin Backup/Transfer and writes the file straight away:

mkdir -p /home/admin/admin_backups/manual
chown admin:admin /home/admin/admin_backups/manual
da admin-backup --destination=/home/admin/admin_backups/manual --user=bob

--user can be repeated for several accounts. On our one-vCPU test server a 132 MB admin account with three WordPress sites took under 7 seconds.

Restore one file or folder

Treat the archive as untrusted input. A user backup contains files the account controlled, and a tampered archive can hold a symbolic link or hard link where you expect wp-config.php. If root extracts and copies such a member, it can read a root-only file and hand its contents to the account. A damaged backup is the other risk: if the archive is truncated or corrupted, the restore must fail before the working file is touched. Checking the exit status after a pipeline that already renamed the file is too late, so the script below lists the member, lets the account write a temporary file, checks both sides of the pipe and the size, and only then renames it. Save it as restore-file.sh and run it as root:

#!/bin/bash
# restore-file.sh - restore one file from a DirectAdmin user backup. Run as root:
#   bash restore-file.sh BACKUP ACCOUNT MEMBER
#   bash restore-file.sh /home/admin/admin_backups/manual/user.admin.bob.tar.zst bob domains/example.com/public_html/wp-config.php
# Root only reads the archive. The account writes a temporary file with its own rights, and the
# live file is replaced only after every step succeeded. On any failure the live file is left as it was.
set -u
B=$1 U=$2 F=$3
die() { echo "Refusing: $*. The live file was not changed." >&2; exit 1; }
H=$(getent passwd "$U" | cut -d: -f6); [ -n "$H" ] || die "no such account: $U"
case "$F" in /*|*..*) die "the member must be a relative path inside the backup" ;; esac
D="$H/$F"
[ ! -d "$D" ] || die "$D is a folder; use restore-folder.sh"
# 1. The listing must succeed and show exactly one regular file ("-", not "l" link, "h" hard link or "d" folder).
L=$(tar --zstd -tvf "$B" -- "$F") || die "the archive could not be read completely, or $F is not in it"
[ "$(printf '%s\n' "$L" | wc -l)" -eq 1 ] && [ "${L:0:1}" = "-" ] || die "$F is duplicated or not a regular file"
SIZE=$(printf '%s\n' "$L" | awk '{print $3}')
# 2. The account creates a unique temporary file next to the live file (mode 600).
T=$(runuser -u "$U" -- mktemp -- "$D.restore.XXXXXX") || die "could not create a temporary file next to $D"
# 3. Root reads the archive; the account writes the temporary file. Both exit codes are kept.
tar --zstd -xOf "$B" -- "$F" | runuser -u "$U" -- sh -c 'cat > "$1"' sh "$T"
S=("${PIPESTATUS[@]}")
# 4. Rename only if tar and the writer both succeeded and the size matches the listing.
if [ "${S[0]}" -ne 0 ] || [ "${S[1]}" -ne 0 ] || [ "$(runuser -u "$U" -- stat -c %s -- "$T")" != "$SIZE" ]; then
  runuser -u "$U" -- rm -f -- "$T"; die "extraction or writing failed (tar exit ${S[0]}, writer exit ${S[1]})"
fi
# 5. Replace the live path itself (-T: never move the file into a folder that appeared there), then check the result.
runuser -u "$U" -- mv -fT -- "$T" "$D" || { runuser -u "$U" -- rm -f -- "$T"; die "could not move the restored file into place ($D may have become a folder)"; }
runuser -u "$U" -- test -f "$D" -a ! -L "$D" && [ "$(runuser -u "$U" -- stat -c %s -- "$D")" = "$SIZE" ] || { echo "The rename finished, but $D is not the restored file; check it." >&2; exit 1; }
echo "Restored $D ($SIZE bytes, mode 600)"

If the archive cannot be listed completely, if the member is a link, a hard link, a folder or appears twice, if decompression or writing fails part way (for example because the account is out of disk space) or if the size does not match the listing, the script exits with status 1, removes its temporary file and leaves the live file exactly as it was. Root never unpacks or writes anything, so a planted link in the archive or in the account’s home cannot redirect a root-owned read or write. The restored file is mode 600; set ordinary web files back to 644 with chmod. For an older .tar.gz backup, change --zstd to --gzip.

For a whole folder, the account unpacks it into a private scratch folder, and live files are copied over only after the listing and the extraction both succeeded. Links inside the archive are created with the account’s rights only, and GNU tar refuses member names containing ... Save this as restore-folder.sh:

#!/bin/bash
# restore-folder.sh - restore one folder from a DirectAdmin user backup. Run as root:
#   bash restore-folder.sh BACKUP ACCOUNT FOLDER
#   bash restore-folder.sh /home/admin/admin_backups/manual/user.admin.bob.tar.zst bob domains/example.com/public_html/wp-content/uploads
# The account unpacks the folder into its own scratch folder. Live files are touched only after
# the listing and the extraction both succeeded.
set -u
B=$1 U=$2 P=${3%/}
die() { echo "Refusing: $*. Live files were not changed." >&2; exit 1; }
H=$(getent passwd "$U" | cut -d: -f6); [ -n "$H" ] || die "no such account: $U"
case "$P" in ''|/*|*..*) die "the folder must be a relative path inside the backup" ;; esac
# 1. Read the whole listing first: a damaged or truncated archive fails here.
tar --zstd -tf "$B" -- "$P" > /dev/null || die "the archive could not be read completely, or $P is not in it"
# 2. The account unpacks into a private scratch folder; root only opens the archive for reading.
W=$(runuser -u "$U" -- mktemp -d -- "$H/.restore.XXXXXX") || die "could not create a scratch folder in $H"
trap 'runuser -u "$U" -- rm -rf -- "$W"' EXIT
runuser -u "$U" -- tar --zstd -xf - -C "$W" --no-same-owner -- "$P" < "$B" || die "extraction failed"
runuser -u "$U" -- test -d "$W/$P" -a ! -L "$W/$P" || die "$P is not a folder in this backup"
# 3. Only now copy into place, as the account.
runuser -u "$U" -- rsync -a -- "$W/$P/" "$H/$P/" || { echo "rsync stopped part way; check $H/$P" >&2; exit 1; }
echo "Restored $H/$P"

We tested both scripts on DirectAdmin 1.712 (GNU tar 1.34, zstd) on 9 October 2026, using copies taken from this page. We used archives cut off at eleven different points (inside the compressed stream and inside the tar data), archives corrupted in the middle and at the end, random bytes, links, hard links, folders and duplicated members, and an account whose disk was full. Every damaged case exited with status 1 and left the live file or folder unchanged with no temporary files behind. The good archive restored the exact bytes. In the same test the previous version of this recipe returned 0 and left a 26 KB fragment in place of a 200 KB file.

Extracting into a scratch directory, rather than with -C /, means a typo cannot overwrite live files. Give each file the permissions it needs. wp-config.php holds the database password and security keys, so restore it as 600 (or 640 if your web server reads it through a shared group). DirectAdmin’s default PHP-FPM runs PHP as the account, so 600 is enough. Ordinary WordPress core files are 644. On our DirectAdmin 1.712 lab server (PHP 8.3, PHP-FPM, 9 October 2026), the site returned HTTP 200 with wp-config.php at 600, and another account could not read the file. At 644 that other account could read it.

In our test we deleted wp-includes/version.php from a WordPress site, which made the site return HTTP 500, then restored that one file from the backup. The site returned 200 again straight away:

Terminal: Restoring one deleted WordPress core file from a DirectAdmin backup: HTTP 500 before, 200 after. DirectAdmin 1.712, 6 Oct 2026.
Restoring one deleted WordPress core file from a DirectAdmin backup: HTTP 500 before, 200 after. DirectAdmin 1.712, 6 Oct 2026. IP addresses masked.

Restore one database

Import the dump as that database’s own MySQL user (the password is in the site’s wp-config.php), not with DirectAdmin’s da_admin login from da my-cnf: that login can change every database on the server, so a tampered dump could reach other accounts. Two more checks matter. The dump must be complete before anything is imported, because each table is dropped and recreated as the import runs; a mysqldump file ends with a -- Dump completed line. And the mysql client understands shell commands (\!), so a tampered dump can run commands as whoever runs the client; the script runs the client as the account, never as root. Save it as restore-db.sh:

#!/bin/bash
# restore-db.sh - import one database dump from a DirectAdmin user backup. Run as root:
#   bash restore-db.sh BACKUP ACCOUNT DATABASE [DB_USER]
#   bash restore-db.sh /home/admin/admin_backups/manual/user.admin.bob.tar.zst bob bob_wp
# Asks for the database user's password (from the site's wp-config.php). The dump is checked to be
# complete before anything is imported, and the mysql client runs as the account, never as root.
set -u
B=$1 U=$2 DB=$3 DBU=${4:-$3} S=backup/$3.sql
die() { echo "Refusing: $*. The database was not changed." >&2; exit 1; }
H=$(getent passwd "$U" | cut -d: -f6); [ -n "$H" ] || die "no such account: $U"
L=$(tar --zstd -tvf "$B" -- "$S") || die "the archive could not be read completely, or $S is not in it"
[ "$(printf '%s\n' "$L" | wc -l)" -eq 1 ] && [ "${L:0:1}" = "-" ] || die "$S is duplicated or not a regular file"
SIZE=$(printf '%s\n' "$L" | awk '{print $3}')
T=$(runuser -u "$U" -- mktemp -- "$H/.restore-db.XXXXXX") || die "could not create a temporary file in $H"
trap 'runuser -u "$U" -- rm -f -- "$T"' EXIT
tar --zstd -xOf "$B" -- "$S" | runuser -u "$U" -- sh -c 'cat > "$1"' sh "$T"
X=("${PIPESTATUS[@]}")
[ "${X[0]}" -eq 0 ] && [ "${X[1]}" -eq 0 ] && [ "$(runuser -u "$U" -- stat -c %s -- "$T")" = "$SIZE" ] || die "extraction or writing failed (tar exit ${X[0]}, writer exit ${X[1]})"
runuser -u "$U" -- tail -n 1 -- "$T" | grep -q '^-- Dump completed' || die "the dump is incomplete (its last line is not '-- Dump completed')"
[ -n "${MYSQL_PWD-}" ] || { read -rsp "Password for MySQL user $DBU: " MYSQL_PWD; echo; }
export MYSQL_PWD
# Import as the database's own MySQL user (not da_admin), with the client running as the account.
runuser -u "$U" -- sh -c 'mysql --no-defaults -u "$1" "$2" < "$3"' sh "$DBU" "$DB" "$T" || { echo "The import stopped with an error; tables before that point were replaced. Check the site." >&2; exit 1; }
runuser -u "$U" -- mysql --no-defaults -u "$DBU" -e "SELECT COUNT(*) AS tables_now FROM information_schema.tables WHERE table_schema = DATABASE()" "$DB"

In our test (DirectAdmin 1.712, MariaDB 10.6, 9 October 2026) the script restored a dropped wp_posts table, refused a truncated archive and a dump cut in half without changing the database, and a tampered dump’s shell command ran as the account rather than root while its DROP DATABASE of another account’s database was refused with ERROR 1044.

Because each table is dropped and recreated, the import replaces the tables that are in the dump and leaves any extra tables alone. If the import stops on an error, tables before that point have already been replaced. If you need an exact copy of the old database, empty it first or import into a new, empty database and switch the site over. Restore files and database from the same backup run, or a WordPress site can end up with plugins whose tables do not match.

Our test dropped the wp_posts table of a WordPress site and imported the dump from the backup; the table came back with all its rows:

Terminal: Dropping wp_posts and importing the database dump from the DirectAdmin backup. DirectAdmin 1.712, 6 Oct 2026.
Dropping wp_posts and importing the database dump from the DirectAdmin backup. DirectAdmin 1.712, 6 Oct 2026. IP addresses masked.

Restore a whole account

For a whole account use Admin Level (or Reseller Level) → Manage Backups → Restore, pick the location and the file, and DirectAdmin recreates the user, domains, mail, databases and settings. If the account still exists, the restore overwrites it, so take a fresh backup of the current state first. We did not run a full-account restore on this server: its licence allows only one account, and we were not going to restore the admin account over itself.

Check the backups before you need them

A restore is only as good as the newest backup that actually opens. Our backup verify script checks that every account has a fresh, non-shrinking archive that decompresses and lists cleanly. On DirectAdmin it reads the account list from /usr/local/directadmin/data/users:

bash backup-verify.sh /home/admin/admin_backups --deep
Terminal: da admin-backup, then backup-verify.sh --deep: archive opens, every account covered. DirectAdmin 1.712, 6 Oct 2026.
da admin-backup, then backup-verify.sh --deep: archive opens, every account covered. DirectAdmin 1.712, 6 Oct 2026. IP addresses masked.

Common problems

  • tar: Cannot exec zstd or unrecognized option --zstd: install the zstd package (it was already present on our AlmaLinux 9.8 server).
  • Refusing: the archive could not be read completely: the backup file is truncated or corrupted (often a copy that was still being written, or a full disk on the backup target). Use an older backup and check the next run with zstd -t.
  • Not found in archive: the path must match the listing exactly, without a leading /. Copy it from the tar -tf output.
  • Access denied for the import: use the database user and password from the site’s wp-config.php (DB_USER, DB_PASSWORD). If the user name differs from the database name, pass it as the fourth argument to restore-db.sh.
  • Site still shows the broken version: clear the page cache (LiteSpeed, nginx or a WordPress cache plugin) and the browser cache.

See also: DirectAdmin CustomBuild Failed: Logs, Lock File, Re-run and Rollback · Migrate DirectAdmin to DirectAdmin: Move All Users to a New Server · Force HTTPS for a Domain in DirectAdmin (Tested on 1.712)

Frequently asked questions

Can I restore a single email account from a DirectAdmin backup?

Yes, the same way as a file. Mailboxes are under imap/DOMAIN/MAILBOX/Maildir/ inside the archive: extract that folder, copy the messages back into the live Maildir with the account owner and the mail group, and Dovecot picks them up.

Do I need to stop the website while I restore a file?

No, for single files. For a database import, a short maintenance window avoids visitors writing to the tables while they are being replaced.

Where does DirectAdmin store admin backups by default?

Wherever the backup job points; /home/admin/admin_backups is the usual local path. Scheduled jobs are listed in Admin Level → Admin Backup/Transfer.

Why is my backup .tar.zst and not .tar.gz?

Current DirectAdmin versions use zstd compression by default because it is faster. tar --zstd reads it; older archives still open with tar -xzf.

Maintenance record

This guide changes servers, data or security settings, so we re-check it against current versions on a fixed schedule. Take a backup or snapshot before you start.

Maintained by
srvScripts editorial team
Supported versions
DirectAdmin 1.712 on AlmaLinux 9.8 with MariaDB
Last full review
Next review

Share this guide

Free website test

Is your website set up right?

Check SSL, security headers, redirects, robots.txt, sitemap, llms.txt and security.txt in one test. It takes about 30 seconds.