How to automate deletion of files in folder if there are more than 2 files

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 25.0.3
Operating system and version (eg, Ubuntu 20.04): Red Hat 4.8.5-44
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.48
PHP version (eg, 7.4): PHP 7.4.33

I’m using using nextcloud on android to save my backups from signal app on my nextcloud server. The way signal backups works is by keeping two backups in the backup folder at the same time. But the way the auto uploads works is by adding all new files and folder detected when they are created. That’s a good thing, because i don’t want my backups to be synchronized with my server, otherwise if i delete backups from my phone they are deleted from my server. however, i don’t need to keep all the backups on my server, i just need the last two.

I could use automated tagging and Retention apps to delete the files older than x time, but that’s not what i want : the two most recent files should never be deleted, no matter how old they are.

Do you know how I can do that ?

I’m not aware of a way to do it in NC, but if it’s a significant issue, you could do it with a cron script on the server.

i guess it’s time for me to learn cron scripts then :slight_smile: