The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Automated script to remove large accounts from central cpanel backup?

Discussion in 'Data Protection' started by zigzam, Apr 3, 2010.

  1. zigzam

    zigzam Well-Known Member

    Joined:
    May 9, 2005
    Messages:
    206
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  2. WiredTree Joe

    WiredTree Joe Well-Known Member
    PartnerNOC

    Joined:
    Dec 13, 2006
    Messages:
    68
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    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.
     
  3. zigzam

    zigzam Well-Known Member

    Joined:
    May 9, 2005
    Messages:
    206
    Likes Received:
    0
    Trophy Points:
    16
    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.
     
  4. UNIXy

    UNIXy Well-Known Member

    Joined:
    Sep 21, 2009
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Houston, Texas, USA
    cPanel Access Level:
    DataCenter Provider
    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
     
  5. zigzam

    zigzam Well-Known Member

    Joined:
    May 9, 2005
    Messages:
    206
    Likes Received:
    0
    Trophy Points:
    16
    That script didn't work. Any other ones?
     
  6. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    DataCenter Provider
    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.*;
     
  7. zigzam

    zigzam Well-Known Member

    Joined:
    May 9, 2005
    Messages:
    206
    Likes Received:
    0
    Trophy Points:
    16

    Thank you that works!
     
  8. cwalke32477

    cwalke32477 Well-Known Member

    Joined:
    Mar 2, 2010
    Messages:
    94
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Atlanta, Georgia
    cPanel Access Level:
    Root Administrator
    Sorry, I'm pretty new at all of this stuff.
    Can you explian to me how I would use this?
     
Loading...

Share This Page