Limit the number of backups a User can create


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


Top Level » DirectAdmin » Custom Scripting

Limit the number of backups a User can createLast Modified: Dec 22, 2017, 10:58 pm
If you want to limit the number of backups a User can created, to say , then you can create the following custom script to enforce it:

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

and add the code:

#!/bin/sh
MAX_BACKUPS=5
#check filename for /home/user/
U=`echo $file | cut -d/ -f3`
if [ "$U" != "$username" ]; then
   #file is not in our /home, so is Reseller or Admin backup.
   exit 0;
fi
#file is being created below this User.
C=`ls /home/$username/backups | wc -l`
if [ "$C" -ge "$MAX_BACKUPS" ]; then
   echo "Too many backups. Delete some from /home/$username/backups before creating another.";
   exit 1;
fi
exit 0;

and chmod the script to 755.

You can manually test the script like this:

file=/home/fred/backups/backup.tar.gz username=fred ./user_backup_pre.sh; echo $?;

Which will either output 0, which means the script allowed creation, or the "Too many backups" error, followed by a "1", where 1 means the script tells DA to abort the backup.

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