Auto-delete files in specific folders in Nextcloud

I am storing backups from mobile devices on my Nextcloud instance (32.0 at the time of this writing). Some apps support retention themselves and they only keep the last x backups. Some apps do not and they clutter and fill up my storage. To solve this I wanted to get Nextcloud to automatically delete files in my backup folder. This required some knowledge that I did not see in a single place, so I am putting all the info I needed into this post to make it easier for others.

Install Nextcloud apps

I solved my issue with two apps: “Files automated tagging” and “Retention”. You can find both under the “Flow” category in Nextcloud's app store. Install and enable them both, if you don't already have done this.

Automatic tagging

Initially I was unable to add a tag whenever I upload a backup. The solution turned out to be an extra step: Manually adding a tag to the backup folder. I chose “backup-folder” for the tag name. This allows us to create a rule to automatically tag all files added to this folder.

⚠️ I found that the “Manage tags” menu in the file view is the only place where I could add new tags. You will need to add the tag you automatically want to assign here first before being able to configure the flow in the next step.

Screenshot showing the "Manage tags" menu item

This is was we do next by creating a new tagging flow in the “Flow” section of your personal settings.

The “When” rule apparently cannot be changed and is always “File is changed”. In some documentation I saw other values, but I guess they changed this at some point. The rule we create is “File system tag” “is tagged with” “backup-folder” (or whichever tag you picked when manually adding a tag to your backup folder). And the outcome is adding a new tag like “auto-delete”. You can have different tags that, for example, contain the retention period in their name (something like “delete-in-one-week”) which would allow you to enforce different retention periods. This will require you to use different backup folder tags for each folder to use in your auto-tagging rule.

An auto-tagging flow

Configure retention rule

Retention is configured in the admin settings, again under the section “Flow”. Here you simply configure the rule for your automatically added tag (“auto-delete” or “delete-in-one-week” or whatever you used). Configure it however you want and save it.

⚠️ Be careful to not use the tag you manually added to the backup folder, otherwise all your backups will suddenly be gone.

And that's it!