Author Topic: Deleting old backups automatically  (Read 7889 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Deleting old backups automatically
« on: May 17, 2020, 04:37:21 PM »
Hi,

I enabled "newbackup" around a month ago and choose backups to generate everyday. The backups are generating everyday as expected but as I'm seeing the old backups don't get deleted automatically. I just want to keep only one copy of every weekday's backup. Is there something I'm missing on the backup settings? I know I can crate cron to delete backup files older than X days but I would like to know if there's anything I can do from GUI. Any suggestion will be highly appreciated. Thanks.

Code: [Select]
[root@server1 newbackup]# tree
.
`-- full
    |-- daily
    |   |-- Friday
    |   |   |-- 2020-04-17
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-01
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-08
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   `-- 2020-05-15
    |   |       `-- accounts
    |   |           `-- wappyco.tar.gz
    |   |-- Monday
    |   |   |-- 2020-04-20
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-04
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   `-- 2020-05-11
    |   |       `-- accounts
    |   |           `-- wappyco.tar.gz
    |   |-- Saturday
    |   |   |-- 2020-04-18
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-02
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-09
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   `-- 2020-05-16
    |   |       `-- accounts
    |   |           `-- wappyco.tar.gz
    |   |-- Sunday
    |   |   |-- 2020-04-19
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-03
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   `-- 2020-05-10
    |   |       `-- accounts
    |   |           `-- wappyco.tar.gz
    |   |-- Thursday
    |   |   |-- 2020-04-16
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-04-23
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-04-30
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-07
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   `-- 2020-05-14
    |   |       `-- accounts
    |   |           `-- wappyco.tar.gz
    |   |-- Tuesday
    |   |   |-- 2020-04-21
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   |-- 2020-05-05
    |   |   |   `-- accounts
    |   |   |       `-- wappyco.tar.gz
    |   |   `-- 2020-05-12
    |   |       `-- accounts
    |   |           `-- wappyco.tar.gz
    |   `-- Wednesday
    |       |-- 2020-04-22
    |       |   `-- accounts
    |       |       `-- wappyco.tar.gz
    |       |-- 2020-04-29
    |       |   `-- accounts
    |       |       `-- wappyco.tar.gz
    |       |-- 2020-05-06
    |       |   `-- accounts
    |       |       `-- wappyco.tar.gz
    |       `-- 2020-05-13
    |           `-- accounts
    |               `-- wappyco.tar.gz
    `-- manual
        `-- accounts
            `-- wappyco.tar.gz

63 directories, 27 files
[root@server1 newbackup]#

Re: Deleting old backups automatically
« Reply #1 on: May 17, 2020, 05:16:56 PM »
See http://forum.centos-webpanel.com/index.php?topic=8476.0 script for an idea on how the correct meaning of "retention" is used.
Retention=7 would appear to appropriate for you need.
« Last Edit: May 17, 2020, 05:18:51 PM by cynique »

Offline
*
Re: Deleting old backups automatically
« Reply #2 on: May 17, 2020, 05:38:02 PM »
Hi,

Thanks for the script. So CWP newbackup GUI doesn't have option to automatically retentate old backups? As per the screenshot, I do see there's option to choose from Daily Backup Retention, Weekly Backup Retention and Monthly Backup Retention. I have just enabled Weekly Backup Retentaton on Sunday. Will it generate a weekly backup on every Sunday or delete old backups on Sunday?

https://imgur.com/a/7v3rGOZ

Screenshot added as reference. Thanks.

Re: Deleting old backups automatically
« Reply #3 on: May 17, 2020, 10:45:10 PM »
Hi,

Thanks for the script. So CWP newbackup GUI doesn't have option to automatically retentate old backups? As per the screenshot, I do see there's option to choose from Daily Backup Retention, Weekly Backup Retention and Monthly Backup Retention. I have just enabled Weekly Backup Retentaton on Sunday. Will it generate a weekly backup on every Sunday or delete old backups on Sunday?

https://imgur.com/a/7v3rGOZ

Screenshot added as reference. Thanks.
No, the developers don't understand what the word retention means - it is not correct; the GUI just means enabled.
Alternatively, they may have intended the tick boxes to mean "keep indefinitely" but that doesn't appear to be working either and is lacking in functionality.

This is why I directed you to the custom script, that finds old files and deletes them, based on the retention value. You could extract that portion to a separately run cron task, if you didn't wish to use the complete script. You could have different retention values applied to daily, weekly & monthly backups, by individually specifying the relevant backup subdirectory.

Ideally, with a correctly implemented backup scheduler, you should be able to specify, for example:
Keep 2 weeks of daily backups, 6 months of weekly backups and 5 years of monthly backups.
Lengthy backup retention is mandatory for some business types.
« Last Edit: May 17, 2020, 10:55:18 PM by cynique »

Re: Deleting old backups automatically
« Reply #4 on: May 21, 2020, 04:05:30 PM »
Following on from the above, I needed to clear space today..
/root/cleanup-cwp-backup.sh
Code: [Select]
#!/usr/bin/bash
/usr/bin/find /backup/full/daily/* -maxdepth 1  -mtime +7 -type d -exec rm -rf {} +
/usr/bin/find /backup/full/weekly/* -maxdepth 1  -mtime +5 -type d -exec rm -rf {} +
/usr/bin/find /backup/full/monthly/* -maxdepth 1  -mtime +3 -type d -exec rm -rf {} +


Offline
*
Re: Deleting old backups automatically
« Reply #5 on: January 24, 2024, 11:38:55 PM »
Thanks, the script helped me and then I created a cron, perfect now to remove the large logs