Set a Reliable Expiration Policy for Nextcloud Deleted Files

To empty Nextcloud’s Deleted files automatically, set a maximum retention age and make sure Nextcloud background jobs run on a schedule. For example, set trashbin_retention_obligation to auto, 30 to delete trash items older than 30 days automatically, then run Nextcloud’s recommended system cron every five minutes. The default auto policy alone does not promise deletion right at day 30.

Automatic deletion is permanent. Choose a retention period that gives users time to recover mistakes, and keep backups for anything that must remain recoverable after it leaves the trashbin.

What does Nextcloud clean up by default?

Nextcloud 35’s administrator documentation describes auto as keeping deleted items for at least 30 days, then allowing them to be removed if storage space is needed. If space is not needed, items may remain beyond 30 days. That behavior makes the trashbin a recovery area, not a strict 30-day deletion timer.

Policy valueWhat it meansUse it when
autoKeep items at least 30 days; remove them later if space is needed.You want the default recovery window and space-based cleanup.
auto, 30Delete items older than 30 days automatically; items may also be removed earlier if space is needed.You want a 30-day maximum age.
30, 90Keep items for at least 30 days and delete them after 90 days.You want a recovery window plus an upper retention bound.
disabledDo not automatically clean the trashbin.You have a separate retention process and intend to retain deleted items.

Retention is not absolute if a user’s quota is exceeded because of trash items: Nextcloud may override the configured policy and clean items until the quota requirement is met. Check the current trashbin retention documentation before applying a policy to accounts with quota constraints.

Set a maximum age for deleted files

Run occ from the Nextcloud installation directory and as the HTTP user so file permissions stay consistent. On Debian or Ubuntu, that user is commonly www-data, and the installation path is often /var/www/nextcloud. Substitute your actual user and path on other systems or in containers.

cd /var/www/nextcloud
sudo -E -u www-data php occ config:system:set trashbin_retention_obligation --value='auto, 30'
A terminal command sets trashbin_retention_obligation to auto, 30, with output confirming the system configuration value.
Set a maximum age of 30 days with the retention-aware policy value auto, 30.

This setting is stored in Nextcloud’s system configuration. To check the active value, run:

sudo -E -u www-data php occ config:system:get trashbin_retention_obligation

The output should show auto, 30. If you prefer a different policy, use the table above and enter its value instead. The 30, 90 option aims to keep items for at least 30 days and remove them after 90 days; quota enforcement can still force earlier cleanup.

Make sure background jobs run reliably

Nextcloud runs trash expiration as a background job. The administrator manual says the trashbin background job runs every 30 minutes, but it still depends on your installation’s background-job runner being invoked. Nextcloud recommends operating-system cron for regular tasks; its default AJAX mode is less reliable because jobs run only when users visit the site.

Set Nextcloud to cron mode:

sudo -E -u www-data php occ background:cron
A terminal runs the occ background:cron command and displays the response that background jobs are set to cron mode.
Switch Nextcloud to cron mode so scheduled background jobs do not depend on users opening the site.

Then edit the web-server user’s crontab. On a typical Debian or Ubuntu host:

sudo crontab -u www-data -e

Add this line, changing the PHP executable or Nextcloud path if your installation uses different locations:

*/5 * * * * php -f /var/www/nextcloud/cron.php
A user-specific crontab editor contains the line to run /var/www/nextcloud/cron.php every five minutes.
Schedule cron.php under the HTTP user. Replace the example Nextcloud path with your installation path.

This schedule triggers Nextcloud’s background runner every five minutes; individual jobs keep their own schedules. For a container deployment, use the documented cron service or scheduled worker for that deployment and run cron.php as the Nextcloud web user. Do not add a second job blindly if your image or platform already runs it.

How can you test expiration safely?

First verify both the policy and the scheduled job. Check the policy with occ config:system:get trashbin_retention_obligation, then list the scheduled task:

sudo crontab -u www-data -l
A terminal shows the active auto, 30 retention value and a five-minute cron entry for cron.php.
Check the saved retention value and confirm the web-server user has the recurring cron.php entry.

In Nextcloud’s administration settings, confirm that background jobs are set to Cron and that the last job execution time advances. After the configured maximum age passes, check Deleted files for an old test item that is safe to lose. The expiry job runs on its schedule, so cleanup is not necessarily immediate at the exact retention boundary.

For a one-time test with a custom retention policy, run the retention-aware command:

sudo -E -u www-data php occ trashbin:expire --quiet

On current Nextcloud, trashbin:expire applies the configured retention period. With the default auto policy, the command exits without expiring items; default auto-expiration is handled by the background job. Do not substitute trashbin:cleanup --all-users: that command permanently removes all trash for every user, regardless of age, and is not a routine retention setting.

Quick verification checklist

  • The active policy returned by occ config:system:get trashbin_retention_obligation matches your intended retention window.
  • Nextcloud background jobs are set to Cron, and the web-server user’s crontab includes the correct cron.php path.
  • The last job execution time advances in the administration settings.
  • An old test item past the maximum age disappears after the background job runs, while newer items remain unless storage or quota pressure requires cleanup.

If the last execution time does not advance, troubleshoot the system cron, PHP CLI path, web-server user, and Nextcloud path before changing the retention value. A correct policy cannot clean anything if the background runner never executes.

Official documentation

Leave a Comment

Set a Reliable Expiration Policy for Nextcloud Deleted Files

Set a Reliable Expiration Policy for Nextcloud Deleted Files

Configure Nextcloud to remove deleted files after a defined retention period, schedule background jobs reliably, and avoid commands that purge every user’s trash.

Clear Nextcloud’s Missing Database Indexes Warning

Clear Nextcloud’s Missing Database Indexes Warning

Run Nextcloud’s OCC repair safely, preview the database changes, and check why the warning might remain.

Raise Nextcloud’s Web Upload Limit Past 2 GB

Raise Nextcloud’s Web Upload Limit Past 2 GB

Allow larger Nextcloud browser uploads by aligning PHP, Nginx or Apache, temporary storage, and timeout settings—and verify which limit is blocking the file.

Clear Nextcloud’s PHP Memory Warning at the Web Server

Set the PHP memory limit Nextcloud actually uses, restart the right service, and confirm the 512 MB setting in Admin Overview.

Connect an S3-Compatible Bucket to Nextcloud External Storage

Mount a compatible object-storage bucket in Nextcloud using its S3 backend, with the right endpoint, credentials, access scope, and verification steps.

Move Nextcloud Data to an External Drive Without Breaking Storage

Move Nextcloud Data to an External Drive Without Breaking Storage

Safely move a Linux Nextcloud data directory to an external drive using a persistent UUID mount, maintenance mode, a verified copy, and the original-path symlink.

Nextcloud Database Error After an Update: What to Check First

Restore Nextcloud access after an update by diagnosing SQL errors, checking database connectivity, and safely completing interrupted migrations.

Reset a Lost Nextcloud Admin Password with OCC

Use Nextcloud’s OCC command to reset an administrator password from the server shell, with guidance for usernames, permissions, and external login providers.

Add the HSTS Header at the HTTPS Endpoint Serving Nextcloud

Clear Nextcloud’s HSTS warning by setting the header at Apache, NGINX, or your TLS proxy, then verify the public HTTPS response safely.

Troubleshoot Nextcloud App Installs That Report No Internet

Troubleshoot Nextcloud App Installs That Report No Internet

Trace App Store installation failures to DNS, HTTPS, proxy, TLS, or configuration issues from the Nextcloud server itself.