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.

Auto Delete Backup Directory Before New One Generated

Discussion in 'Data Protection' started by Dave Peterston, Oct 17, 2015.

  1. Dave Peterston

    Dave Peterston Registered

    Joined:
    Oct 17, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Sydney
    cPanel Access Level:
    Root Administrator
    Hi cPanelers,

    I hope I am not bothering anyone by asking this.

    I need to delete a backup directory older than 2 days before a new one is generated. I run a small business transporting PDF files and need to get the backup directory deleted off the server after 2 days.

    Running with the default cpanel system means I need space to hold an additional backup directory which is only going to be deleted anyway after the new one is saved. That's a huge waste of space. I need the oldest backup directory deleted just before the new one is generated.

    I have this in the crontab on my server:

    30 2 * * * find /backup -type d -ctime +2 -exec rm -rf {} \;

    This deletes the daily backup directory older than 2 days at 2:30am. It seems to work OK.

    However, recently the backup process got stuck resulting in the backups not working for about four days I think. The result was the cronjob kept on deleting backup directories older than 2 days so I was left with no backups, and to top is off it ended up deleting the main "/backup" directory too!! Doh!!!

    I am after something like this:

    ... At 2:30am delete the daily backup directory older than 2 days old but only if there is a daily backup directory in there older than 1 day old.

    I have done a heap of research but I have not yet found anything.

    If anybody knows the right code that would be awesome or is there is a better way.

    Other threads on this subject seem to tell people to look at the cpanel 'hooks' which is way beyond me but a cronjob code which can be pasted in to the crontab is super easy.

    Any help would be totally awesome.

    Thanks heaps
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Have you considered using incremental backups? You can choose this setting to store only one uncompressed backup file. The system saves updated account information to the existing backup file, and removes the old information that these updates replace. This setting limits your restoration settings, but runs faster and uses less disk space than other backup types.

    Thank you.
     
  3. chalupa

    chalupa Registered

    Joined:
    Jul 15, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    DataCenter Provider
    Would be better to just remove the .tar.gz files and let cPanel remove the directory itself. Most of the space is taken up by them anyways

    30 2 * * * find /backup -type f -ctime +2 -name '*.tar.gz' -exec rm -rf {} \;

    But the cPanel backups will run after this by default. 1am for legacy and 2am for new backups. So you want that to run earlier than the backups fire? Maybe

    30 1 * * * find /backup -type f -ctime +2 -name '*.tar.gz' -exec rm -rf {} \;

    or if you use legacy backups

    30 0 * * * find /backup -type f -ctime +2 -name '*.tar.gz' -exec rm -rf {} \;
     
Loading...

Share This Page