Automated script to remove large accounts from central cpanel backup?

zigzam

Well-Known Member
May 9, 2005
206
0
166
Does anyone know of an automated script that will check all cpanel accounts disk usage and remove them from the server wide cpanel backup if the disk usage is higher than X amount.


Thanks
 

WiredTree Joe

Well-Known Member
Dec 13, 2006
68
1
158
Chicago, IL
You can use find to purge backups over a certain size:

Code:
find /backups -type f -size +10485760k -exec rm -f {} \;
The above command will search through /backups for files that are over 10GB in size and remove them. Adjust the /backups to the correct path of your backups and the +10485760k to fit your needs. This can be scheduled to run via Cron.
 

zigzam

Well-Known Member
May 9, 2005
206
0
166
Not quite what I was looking for. I am looking for a script to remove large accounts from the cpanel backup list so they are not backed up nightly.

Its under WHM --> Configure backup --> Select Specific Users

That list.
 

UNIXy

Well-Known Member
Verifed Vendor
Sep 21, 2009
75
0
56
Houston, Texas, USA
cPanel Access Level
DataCenter Provider
Not quite what I was looking for. I am looking for a script to remove large accounts from the cpanel backup list so they are not backed up nightly.

Its under WHM --> Configure backup --> Select Specific Users

That list.
Hi,

Here's a script. Configure this in cron to run weekly for example (@weekly /root/script.sh)

Code:
#!/bin/bash

max_size="4096" # This is 4096KB or 4MB

ls -1 /var/cpanel/users/| \
while read u;
 do
  size=$(repquota -a | grep ${u}|awk '{print $3}'|sort -k 1 -nr|head -1);
  if [ "${size}" -ge "${max_size}" ];
  then
    echo "${u}" >> /tmp/cpbackup-userskip.conf;
  fi;
done;

sort -u /tmp/cpbackup-userskip.conf /etc/cpbackup-userskip.conf > /tmp/cpbackup-userskip.conf.uniq;
cp -f /tmp/cpbackup-userskip.conf.uniq /etc/cpbackup-userskip.conf;
rm -f /tmp/cpbackup-userskip.conf.*;
Enjoy!

Joe / UNIXY
 

InterServed

Well-Known Member
Jul 10, 2007
268
14
68
cPanel Access Level
DataCenter Provider
That script didn't work. Any other ones?
Here's a revised code based on UNIXy :

Code:
#!/bin/bash

max_size="2097152" # This is 2097152KB or 2GB

for u in `ls /var/cpanel/users/`;
 do
  size=$(repquota -a | grep ${u}|awk '{print $3}'|sort -k 1 -nr|head -1);
  if [ "${size}" -ge "${max_size}" ];
  then
    echo "${u}" >> /tmp/cpbackup-userskip.conf;
  fi;
done;

sort -u /tmp/cpbackup-userskip.conf /etc/cpbackup-userskip.conf > /tmp/cpbackup-userskip.conf.uniq;
cp -f /tmp/cpbackup-userskip.conf.uniq /etc/cpbackup-userskip.conf;
rm -f /tmp/cpbackup-userskip.conf.*;
 

zigzam

Well-Known Member
May 9, 2005
206
0
166
Here's a revised code based on UNIXy :

Code:
#!/bin/bash

max_size="2097152" # This is 2097152KB or 2GB

for u in `ls /var/cpanel/users/`;
 do
  size=$(repquota -a | grep ${u}|awk '{print $3}'|sort -k 1 -nr|head -1);
  if [ "${size}" -ge "${max_size}" ];
  then
    echo "${u}" >> /tmp/cpbackup-userskip.conf;
  fi;
done;

sort -u /tmp/cpbackup-userskip.conf /etc/cpbackup-userskip.conf > /tmp/cpbackup-userskip.conf.uniq;
cp -f /tmp/cpbackup-userskip.conf.uniq /etc/cpbackup-userskip.conf;
rm -f /tmp/cpbackup-userskip.conf.*;

Thank you that works!