How to create a full backup of all accounts via the command line.


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DirectAdmin » Backup & Restore Process

How to create a full backup of all accounts via the command line.Last Modified: Jan 30, 2017, 11:42 pm
If your server is on it's way to being fully dead, or your license has expired, you can still create backups via the command line.   To do so, run the following command:

echo "action=backup&append%5Fto%5Fpath=nothing&database%5Fdata%5Faware=yes&email%5Fdata%5Faware=yes&local%5Fpath=%2Fhome%2Fadmin%2Fadmin%5Fbackups&owner=admin&type=admin&value=multiple&when=now&where=local&who=all" >> /usr/local/directadmin/data/task.queue

And make sure that the dataskq is running by checking /var/log/cron.  If it isn't you can run the dataskq manually to create the backups:

/usr/local/directadmin/dataskq d200

This will create all backups in /home/admin/admin_backups, assuming there is enough of a system left to do so.

The command to create a backup for just a single User is:

echo "action=backup&append%5Fto%5Fpath=nothing&database%5Fdata%5Faware=yes&email%5Fdata%5Faware=yes&local%5Fpath=%2Fhome%2Fadmin%2Fadmin%5Fbackups&owner=admin&select%30=testuser&type=admin&value=multiple&when=now&where=local" >> /usr/local/directadmin/data/task.queue

where testuser is the account you're backing up, by admin.



Along the same lines, to restore a single User, the command is:

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

where user%2Eadmin%2Etestuser%2Etar%2Egz is the name of the file being restored.  Replace periods with %2E (hex value).  Note that you can also use the testuser%2Etar%2Egz format as well, either will work.  This restore specifes to use the IP stored in the backup file for the restore.    If you want to specify the IP to restore him to (assuming his account doesn't exist yet), then you'd set ip_choice=select&ip=1.2.3.4 instead of ip_choice=file.

A sample cron script, run as root, run daily, on the backup/restore box, might be:

#!/bin/sh

#Who is doing the restore?
OWNER=admin
LOCAL_PATH=/home/${OWNER}/admin_backups

#choice can be 'file' to get it from the backup
#or 'select' which will use the ip set.
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 "";

if [ "${COUNT}" -eq 0 ]; then
       exit 1;
fi

exit 0;

Adjust the variables as needed.   This will spit out the sample task.queue entry, which you'd dump to the task.queue in your cron, eg:

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


© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST