Backup plugin - Keep the last x days of backups

  • Hi,

    I use backup plugin with scheduled backup jobs (running every 2 days).

    There is an option Keep (with description "Keep the last x days of backups"). I have is set to 5, but doesn't seems like old backups are deleted. At the moment I have 7 backups and the oldest is from the 17th of Feb. The only non-standard thing is a different path and additional sub-directory for backups added in /etc/default/openmediavault and it looks like that:

    Code
    OMV_BACKUP_DIR_NAME="/backups/omvbackup/`date +%y-%m-%d-%H`/"
    OMV_BACKUP_FILE_PREFIX="omv__"

    which saves a backup to /backups/omvbackup/ and sub-directory with a current date and hour.

    Could anyone explain how to set it up to keep only last few backups please?

    Thanks

    Greg

  • The way you have subfolders based on the current date and time set up may be the exact reason why old backups aren't deleted. I think.


    Normally, all the files in a given backup set are dumped into the same folder (they all have dates and times in their filenames as well, so you still know what goes with what). I'm assuming that's how the backup plugin knows when to start deleting the oldest sets of files - because they all live together in one folder.


    Try using /backups/omvbackup/ without the date/time part and see if that solves your issue.

  • I have explained this many times. Because of the way the Linux find command works and the dates on the files, you usually get two more backups (not days) than the setting seems like it should give you.

    omv 5.6.6 usul | 64 bit | 5.11 proxmox kernel | omvextrasorg 5.6.1
    omv-extras.org plugins source code and issue tracker - github


    Please read this before posting a question.
    Please don't PM for support... Too many PMs!

  • ryecoaaron - thank will see in a few days then. BTW - Interesting about the 'find' command. Need to read more about it. I actually used it in my cron scripts a while ago to delete old daily, weekly and monthly backups and never had any issues.

  • BTW - Interesting about the 'find' command. Need to read more about it. I actually used it in my cron scripts a while ago to delete old daily, weekly and monthly backups and never had any issues.

    There is nothing wrong with the find command. It is doing very literal things that are different than people think about. When you tell find to keep the last 5 days worth of files, a file 5.99 days old is still within 5 days. And because the current backup is 0 days, find could keep two more backups than people think of.

    omv 5.6.6 usul | 64 bit | 5.11 proxmox kernel | omvextrasorg 5.6.1
    omv-extras.org plugins source code and issue tracker - github


    Please read this before posting a question.
    Please don't PM for support... Too many PMs!

  • Thanks for the insight ryecoaaron.


    It had indeed occurred to me that when you back up every 2 days and ask to have the last 5 days of backups kept, you should end up with either 2 backups or 3, depending on how exactly the cutoff point is calculated.

  • I've got it set to 5, but last night just got one more backup without deleting the old one, so I've got 8 of them at the moment. Will wait another 48 hours so see if creating another one will delete the very old one too.

    I'm guessing the problem may be the path and sub-directories where the backups are saved as cubemin suggested in a previous post. Will change it in a few days and see.

  • I've got it set to 5, but last night just got one more backup without deleting the old one, so I've got 8 of them at the moment. Will wait another 48 hours so see if creating another one will delete the very old one too.

    It doesn't count them. Everything is done by date. Can you do the following in your backup directory? I would like to see the results.


    ls -al *.grub

    find -maxdepth 1 -type f -mtime +5 -name "*.grub" -ls

    omv 5.6.6 usul | 64 bit | 5.11 proxmox kernel | omvextrasorg 5.6.1
    omv-extras.org plugins source code and issue tracker - github


    Please read this before posting a question.
    Please don't PM for support... Too many PMs!

  • The result of ls command is nothing. The same with the find command.

    However it returns a list of files if I change -maxdepth to 2 (I have it in sub-directories as explained in my first post (also sub-dirs are listed below for you reference.


  • The result of ls command is nothing. The same with the find command.

    However it returns a list of files if I change -maxdepth to 2 (I have it in sub-directories as explained in my first post (also sub-dirs are listed below for you reference.

    Your override is why the backups aren't being purged. I guess the next thing you will ask for is an override for max depth.

    omv 5.6.6 usul | 64 bit | 5.11 proxmox kernel | omvextrasorg 5.6.1
    omv-extras.org plugins source code and issue tracker - github


    Please read this before posting a question.
    Please don't PM for support... Too many PMs!

  • Happy to modify some file, but I guess they will be restored to 'factory' on the backup plugin update.

    May be safer and more reliable if I keep all backups in the same directory. Then it should work straight away.

    In meantime is there any place (github?) I can report a bug / request a feature to make it work in a future?

  • In meantime is there any place (github?) I can report a bug / request a feature to make it work in a future?

    https://github.com/OpenMediaVa…ers/openmediavault-backup but you don't need to file one. I will change it.

    omv 5.6.6 usul | 64 bit | 5.11 proxmox kernel | omvextrasorg 5.6.1
    omv-extras.org plugins source code and issue tracker - github


    Please read this before posting a question.
    Please don't PM for support... Too many PMs!

  • In meantime (before the new version of the plugin will be distributed) based on your changes in Github I added a line:

    Code
    OMV_BACKUP_MAX_DEPTH="3"

    to /etc/default/openmediavault and changed old find line in omv-backup to:

    Code
    find "${backupDir}" -maxdepth ${OMV_BACKUP_MAX_DEPTH} -type f -mtime +${keep} -name "${OMV_BACKUP_FILE_PREFIX}*" -delete

    as you updated it in Github repository.


    The backup ran last night. Created a new one, but haven't deleted the old ones.


    Will investigate more in the evening when I'm back home, but it seems like the script finds old files in:

    Code
    backupDir="${sfpath}/${OMV_BACKUP_DIR_NAME}"

    but OMV_BACKUP_DIR_NAME in my case is dependant on a current date (and everytime the script runs the dir path if different, thus old files / dirs are not deleted):

    Code
    OMV_BACKUP_DIR_NAME="/backups/omvbackup/`date +%y-%m-%d-%H`/"

    so I guess I need to move date part to file prefix and make it look something like:

    Code
    OMV_BACKUP_DIR_NAME="/backups/omvbackup/"
    OMV_BACKUP_FILE_PREFIX="`date +%y-%m-%d-%H`/omv__"

    That will make the script to find old file in .../omvbackup/ dir. However I'm not sure if slash ("/") can be placed as a part of file prefix and if it's going to be recognised as directory name.


    Will change the settings and run it manually tonight when get back home and see the result.


    Many thanks ryecoaaron for your help with that.



    EDIT:


    Tried to put a date in the prefix part, but it says No such file or directory:



    Code
    Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; /usr/sbin/omv-backup 2>&1': Method: ddfull
    Device file: /dev/root
    Root drive: /dev/mmcblk0
    /usr/sbin/omv-backup: line 84: /srv/dev-disk-by-uuid-83a49c51-f71d-4fd0-a4f0-028b95102cd7/backups/omvbackup/21-03-05-19/omv__-05-Mar-2021_19-49-34.fdisk: No such file or directory

    The script should make the directory (based on a current date) first :(



    EDIT 2:


    Would it be possible to have a different date format in filenames? I personally prefer date +"%y-%m-%d_%H-%M-%S" instead of hardcoded date +"%d-%b-%Y_%H-%M-%S" (better for sorting files by name from the oldest to newest).

    Again - I'm going to change it manually for now and don't use sub-dirs, but it will be overwritten on the plugin update.

    OMV5 on RPi4B

    Edited 3 times, last by greg77: adding extra info ().

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!