Hello guys,
after really long time of non writing here; finally I’m happy to announce a small handy pre backup script hook for DA (Directadmin) server control panel system.
The idea behind is to check free disk space (in percents) of a particular partition, before (previously to) DA will fire up it’s backup script. This will work for user backups along with admin level backups.
For many years I found that I always face the problem that the local backups are eating up all the disk space on the server hence a nice (per user/account) pre backup free disk space will save you later problems with 100% disk full.
DA has a wonderful feature for calling pre/post scripts for various functions in the system, which one of them is the built-in backup system.
According to the DA knowledge base documentation (and with John’s advice), we need simply create a bash/shell script called ‘user_backup_pre.sh’ and put it exactly here:
/usr/local/directadmin/scripts/custom/user_backup_pre.sh
DA knows that if such files exists in this path with this name, it should first run it and receive a NULL (false) response, otherwise it will not continue with the backup process.
I modified their ‘highload’ checker example script and created this one:
#!/bin/sh
PARTITION=/dev/sda1
MAXUSED=90checkfree()
{
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 back
up.”;
exit 1;
fi
exit 0;
Just set your maximum allowed used disk space variable MAXUSED (the value is in percents, just exactly the value you get with the df command in the USE% column).
Then the subject PARTITION (if you have separate /home partition then set it to, since, as you know, DA stores his admin_backups at /home/admin/admin_backups/ path). In my example it’s /dev/sda1 because this server uses single partition for everything.
Finally chmod this script to 755
chmod 755 /usr/local/directadmin/scripts/custom/user_backup_pre.sh
Find your biggest user and make sure that the maximum disk usage will be kept below his size.
Direct download user_backup_pre.sh