Introduction
Hello folks! Today I’m going to discuss what is the proper way to perform admin/reseller/user backup in DirectAdmin so that you can speed up the backup process and most importantly your backup data has less chance to result in an error when you perform the backup restoration. This article assumes that you know how to perform these backups using DirectAdmin backup tool. Note, this tutorial is written specifically for nginx and apache web servers.
Tip #1: How to put your website into maintenance mode before performing backup
This is not officially documented in DirectAdmin but generally speaking, when you set your website into maintenance mode, it will actually prevent other users from using your site and lock against all activities including database transactions. Therefore, your backup data will have less prone to error during the restoration process. So, I’m not gonna waste your time, below is an example of a script that you can execute in order to put your website into maintenance mode in DirectAdmin. You should only do this before performing the backup.).
Step 1: Create a new maintenance.html file in your public_html and add maintenance code setting using the following bash script
#!/bin/bash
# Author: Arafat Ali
# Website: codegix.com
# Change the following USERNAME and DOMAIN.COM to yours
user="USERNAME"
domain="DOMAIN.COM"
maintenance_html="/home/${user}/domains/${domain}/public_html/maintenance.html"
echo -n "Writing maintenance page html into ${maintenance_html}"
{
echo "<!DOCTYPE html>"
echo "<html>"
echo " <!--"
echo " This is a maintenance page"
echo " -->"
echo " <head>"
echo " <meta http-equiv=\"Refresh\" content=\"5; url='http://${domain}'\" />"
echo " <title>${domain}-Website Maintenance</title>"
echo " <style>"
echo " body { text-align: center; padding: 150px; }"
echo " h1 { font-size: 50px; }"
echo " body { font: 20px Helvetica, sans-serif; color: #333; }"
echo " article { display: block; text-align: left; width: 650px; margin: 0 auto; }"
echo " a { color: #dc8100; text-decoration: none; }"
echo " a:hover { color: #333; text-decoration: none; }"
echo " </style>"
echo " </head>"
echo "<body>"
echo "<article>"
echo " <h1>We&rsquo;ll be back soon!</h1>"
echo " <div>"
echo " <p>Sorry for the inconvenience but we&rsquo;re performing site maintenance at the moment. If you need to you can always <a href=\"mailto:webmaster@${domain}\">contact us</a>, otherwise <strong><a href=\"${domain}\">${domain}</a></strong> will be online shortly!</p>"
echo " <p>&mdash; The Team</p>"
echo " </div>"
echo "</article>"
echo "</body>"
echo "</html>"
} >"${maintenance_html}"
chmod 644 "${maintenance_html}"
chown "${user}":"${user}" "${maintenance_html}"
# Create the following maintenance code:
# for apache or nginx_apache
custom_web_httpd="/usr/local/directadmin/data/users/${user}/domains/${domain}.cust_httpd"
# for nginx
#custom_web_httpd="/usr/local/directadmin/data/users/${user}/domains/${domain}.cust_nginx"
echo -n "Writing maintenance mode config into ${custom_web_httpd} ..."
{
echo "#!# Start maintenance mode"
echo "<IfModule mod_rewrite.c>"
echo "RewriteEngine on"
echo "RewriteCond %{REQUEST_URI} !/maintenance.html\$ [NC]"
echo "RewriteRule .* /maintenance.html [R=302,L]"
echo "</IfModule>"
echo "#!# End maintenance mode"
} >"${custom_web_httpd}"
# for nginx
#location ~* /maintenance.html\$ {
#}
#location / {
# rewrite ^(.*)$ /maintenance.html redirect;
#}
echo "Done"
fi
Step 2: Save the script with the following name maintenance.sh and run as follow:
chmod +x maintenance.sh
./maintenance.sh
/usr/local/directadmin/custombuild/./build rewrite_confs
When you are done, your website DOMAIN.COM will be in maintenance mode and you can safely perform backup. To set the website to online mode, you can remove the following file:
cp /usr/local/directadmin/data/users/${user}/domains/${domain}.cust_nginx /usr/local/directadmin/data/users/${user}/domains/${domain}.cust_nginx.backup
rm -f /usr/local/directadmin/data/users/${user}/domains/${domain}.cust_nginx
or
cp /usr/local/directadmin/data/users/${user}/domains/${domain}.cust_httpd /usr/local/directadmin/data/users/${user}/domains/${domain}.cust_httpd.backup
rm -f /usr/local/directadmin/data/users/${user}/domains/${domain}.cust_httpd
There are a lot more that I want to share for this article but I’m gonna stop here for a while. Remember that this post is developing, you will see another info soon.