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:


and add the code:

#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;
#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;
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 ./; 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