Trashbin_retention_obligation and CommandBus not working as expected


I am running out of space on my server. I noticed some accounts have a massive amount of trashed files. Some from about 18 years ago (inherited from owncloud). So a month or so ago I read about setting trashbin_retention_obligation in the config file and after reading about it, I set that to “‘trashbin_retention_obligation’ => ‘30, 180’”. According to the documentation in the sample config file that should remove everything over 180 days old the next time something is deleted.

Since then, I have been monitoring the situation to see when it cleans up the old files, but it has not removed any of them. That has been about a month ago so all accounts would have deleted numerous files through the desktop app. I also just deleted one through the web interface to make sure that was not the required action.

Any ideas why this might not be working?

Thanks for your help.

Did you have a look in the nextcloud.log if something is mentioned there? You may also try occ config:system:get trashbin_retention_obligation to check if the setting is in effect.

I’ve set a similar “trashbin_retention_obligation” setting a few days ago and the older files where gone just a few hours later.

This issue was closed, but I’m not sure if it is working now.

Thanks for the pointers. I looked in the next cloud log and found nothing interesting. But I could have missed something. I ran the occ command and it comes back as “30, 180”, so that looks good. I am using nextcloud 17.0.1 on Ubuntu server. I just updated (I suppose from 17.0.0) yesterday.

I did some more poking around and added some logging to the Trashbin.php. I found that expire method is never called.

public static function expire($user) {
	$trashBinSize = self::getTrashbinSize($user);
	$availableSpace = self::calculateFreeSpace($trashBinSize, $user);

	$dirContent = Helper::getTrashFiles('/', $user, 'mtime');

	// delete all files older then $retention_obligation
	list($delSize, $count) = self::deleteExpiredFiles($dirContent, $user);

	$availableSpace += $delSize;

	// delete files from trash until we meet the trash bin size limit again
	self::deleteFiles(array_slice($dirContent, $count), $user, $availableSpace);

You can see the file referenced in the link gas85 provided. I am guessing a call to that method is suppose to get scheduled in the scheduleExpire method.

 * @param string $user
private static function scheduleExpire($user) {
	// let the admin disable auto expire
	$application = new Application();
	$expiration = $application->getContainer()->query('Expiration');
	if ($expiration->isEnabled()) {
		\OC::$server->getCommandBus()->push(new Expire($user));

My logging would indicate that Expire was getting pushed. That is all the further I got. Anyone have ideas why the scheduled commands would not be being run?

Thanks for your help.

I am so happy. I got it figured out. So to get NextCloud to clean the trash, in NextCloud, I went to ‘Settings’ > ‘Basic settings’ > ‘Background jobs’. There I changed it from ‘AJAX’ to ‘Cron’. Then I followed the instructions at the link bellow to set up a Cron job to run the background task.


  1. Apparently it does not do the trash cleaning on AJAX. I am not sure if this is a bug or intentional. If intentional it should be documented some place. Another thought, maybe it was working but there was just such a long list of background task that it never got around to them, because the web interface was used so seldom.

  2. Why does it not say on the ‘Background jobs’ settings page that choosing the Cron option requires manual configuration and provide a link to instructions? It is a good thing I read the manual.