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.

easy way to delete backups of non-existant accounts?

Discussion in 'Workarounds and Optimization' started by Funkadelic, Feb 6, 2010.

  1. Funkadelic

    Funkadelic Well-Known Member

    Joined:
    Feb 10, 2006
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    backup space is always an issue, especially with incremental backups. I'm wondering in an effort to save space if it is possible for some script or something that could automatically remove old backups of accounts that don't exist anymore? When you have hundreds of accounts it is a real hassle to do this manually.
     
  2. furquan

    furquan Well-Known Member

    Joined:
    Jul 27, 2002
    Messages:
    425
    Likes Received:
    0
    Trophy Points:
    16
  3. Zion Ahead

    Zion Ahead Well-Known Member

    Joined:
    Nov 10, 2006
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    I tried that script but getting this error.

    [/scripts]# ./cleanbackups
    Reading Backup Config...Complete
    Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
     
  4. MikeDVB

    MikeDVB Well-Known Member
    PartnerNOC

    Joined:
    Jun 4, 2008
    Messages:
    212
    Likes Received:
    3
    Trophy Points:
    18
    Location:
    Indiana, USA
    Something that I'm running that may help is a cron job that deletes backup files that are older than 72 hours... So if you were doing daily backups any account that isn't backed up for 3 consecutive days would be pushed out of the system.

    If you were doing weekly backups you could adjust it to 8 days or 15 days if you wanted.

    You obviously would want to adjust the paths to the specifics of your server:
    Code:
    0 0 * * * find /backup -maxdepth 3 -name 'backup-*.tar.gz' -mtime +3 -exec rm {} \; ; find /backup -maxdepth 3 -name 'cpmove-*.tar.gz' -mtime +3 -exec rm {} \;
     
  5. Zion Ahead

    Zion Ahead Well-Known Member

    Joined:
    Nov 10, 2006
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    That didn't do anything for me.
     
  6. yapluka

    yapluka Well-Known Member

    Joined:
    Dec 24, 2003
    Messages:
    301
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    France
    cPanel Access Level:
    Root Administrator
    This is what we use :
    Code:
    bakdir=$(grep BACKUPDIR /etc/cpbackup.conf | awk '{print $2}');cd "$bakdir"/cpbackup/daily/;for user in *;do if [ ! -e "/var/cpanel/users/"$user"" ] && [ "$user" != "files" ] && [ "$user" != "dirs" ]; then rm -rf "$bakdir"/cpbackup/*/"$user";fi;done
    
    Replace daily with weekly or monthly if you don't have daily backups.
     
  7. Zion Ahead

    Zion Ahead Well-Known Member

    Joined:
    Nov 10, 2006
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    What is the non-cron command to run manually?
     
  8. yapluka

    yapluka Well-Known Member

    Joined:
    Dec 24, 2003
    Messages:
    301
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    France
    cPanel Access Level:
    Root Administrator
    My command is not a cron command, and will delete all backups of non existent accounts.
    If you want to run it automatically, your best option is to add it to /scripts/postcpbackup (create it if it doesn't already exist), so it will be executed after cpbackup is complete.
     
  9. bornonline

    bornonline Well-Known Member

    Joined:
    Nov 19, 2004
    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Earth
  10. shaun

    shaun Well-Known Member

    Joined:
    Nov 9, 2001
    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    San Clemente, Ca
    The above plug-in replaces that script. The plug-in gives you many more features and the ability to automate the process!
     
Loading...

Share This Page