Auto delete if a number of files exist

Hi there,

I would like to have a app that gives me the chance to auto-delete files when I upload a new one.
I am planning to auto-upload Backups to my NC. To avoid flooding my NC space I would like to only keep 3 Backups. Is there a way (app) to auto-delete the oldest file after a new backup was successfully uploaded?! I couldnt find something.

If there is no app I could imagine to use a collaborative tag and auto tagging with file retention but it wouldnt be my first choice. The problem here is, if there werent a successful upload of a new backup the older files would still be deleted after the elected time.
Is there furthermore a way that only one user or one user-group can see and use a tag? I only found the settings to hide (for all users), to show (public --> for all users) or restrict tags. But if i am right, the restrict is only for admins?! isn´t it? I think i would need it for a user-group.

Thanks for every hint and help.

I believe this is more your backup script responsibility to check if:
a. File was successfully uploaded
b. delete older versions of backups.

As quick win I think you have at least 2 options:

  1. For daily backups, call your backup file in a same way without date and time, e.g. userXXXbackup.tar.gz. In this case you need to overwrite file and nextcloud will care about versions with standard retention policies.
    Or you can setup it like 'versions_retention_obligation' =>; '3,auto' (https://docs.nextcloud.com/server/13/admin_manual/configuration_server/config_sample_php_parameters.html#file-versions) this will keep 3 day file versions before to start retention.
    OR
  2. Just pickup unique file name like userXXXXbackup-DATE.tar.gz and add cron job to find and delete older files like:
    find /PATH/TO/NEXTCOUD/DATA/USER/files/FOLEDERwithBACKUPS/*tar.gz -mtime +3 -exec rm {} \;
    and run occ command to rescan folder afterwards:
    sudo -u www-data php occ files:scan --path="USER/files/FOLEDERwithBACKUPS"
    In one line it should be something like this for you NC user:
    find /PATH/TO/NEXTCOUD/DATA/USER/files/FOLEDERwithBACKUPS/*tar.gz -mtime +3 -exec rm {} \; && php /PATH/TO/NEXTCOUD/occ files:scan --path="USER/files/FOLEDERwithBACKUPS"

Hey gas85,

thanks a lot for your answer.

I agree, it could be regulated by a backup script but,… i dont have a script atm. I use the android auto-upload to uplad a backup-folder. But it would be a solution and i could use a script, no problem. I hoped there is a app so that other user can easily use it, too if they want. But it doesnt matter.

Thanks a lot for the your solution no 1. Its a nice hint!

If there is anyone else with a nice idea or a solution it would realy nice to share it. Is there anyone who can answer my question with the tagging?!

tanks and greetings
Dennis