Nextcloud hoarding trash - how to force automatic removal of deleted items


(Jason Bayton) #1

Originally published at: https://bayton.org/docs/nextcloud/nextcloud-hoarding-trash-how-to-force-automatic-removal-of-deleted-items/

Observing a backup running recently, I noticed a substantial number of files being backed up from the Nextcloud trash directory. On inspecting this, it became apparent not a single file had been permanently deleted from my installation since setting it up over a year ago! The issue If your Nextcloud instance utilises a data directory situated on a disk/partition/volume far greater in size than the sum of the data you’re storing, you may notice files in the trash are not being deleted. The cause By default, Nextcloud is set to hold on to deleted items for 30 days. After this, files are only deleted when storage starts running low. This means for those with terrabytes of unused storage, deleted items may actually never disappear! The solution Config parameters exist to allow Nextcloud server owners the capability of adapting this behaviour, these are as follows: auto – standard behaviour D, auto – change the minimum days a file is kept with standard behaviour auto, D – delete after a number of days, but earlier if space is required D1, D2 – do not delete before, but definitely delete after a certain number of days disabled – disable automatic deletion So to automatically delete files after 30 days, and give Nextcloud the ability to delete sooner if space does eventually run low, you can add this to your config.php: ‘trashbin_retention_obligation’ => ‘auto, 30’, To ensure all files are retained for 30 days, but definitely deleted after 35 days, the following can be added to your config.php: ‘trashbin_retention_obligation’ => '30,…


(Galder56) #2

Hi,
I know this is an old post but I am trying to delete files from NC V. 14.0.6. Using your examples: D – delete after a number of days, but earlier if space is required D1, D2 on our Test box. Placed in config.php. Did not delete the files. I thought I would ask you since I have followed a lot of your guides with great outcomes.
Is there another step? Do I need to create a Cron job? In a way I guess I will be pretty lucky if you even notice this post! Worth a try.
TA… g.


(Jason Bayton) #3

Hey,

So I believe the functionality around this is a little questionable. Leave it with me to check and I’ll get back to you!


(Galder56) #4

Thanks. I appreciate your help.
Oh Also have Background Jobs set to AJAX
An update. After reading some info on:
https://docs.nextcloud.com/server/14/admin_manual/configuration_server/background_jobs_configuration.html
I switched AJAX to Cron. I received an error in log:
Exception: The requested uri(http:/www.google.com/nextcloud) cannot be processed by the script ‘/nextcloud/index.php’)
/var/www/html/nextcloud/lib/private/AppFramework/Http/Request.php - line 768:
OC\AppFramework\Http\Request->getRawPathInfo()
/var/www/html/nextcloud/lib/base.php - line 772:
OC\AppFramework\Http\Request->getPathInfo()
/var/www/html/nextcloud/lib/base.php - line 1068:
OC::init()
/var/www/html/nextcloud/index.php - line 40:
require_once("/var/www/ht … p")

Even though I have this error which I am researching. Older files “were deleted”.
I only have one I put in yesterday and if all goes it should be gone tomorrow.
So I am thinking I need to change a configuration in index.php?
Looking at now. Maybe find fix?

So your automatic removal post worked! Now just clean up on this issue.

g.


(Galder56) #5

Back with update.
Note to others. When installing NC, which maybe I would have done if I read more is change from AJAX to Cron for Background Jobs. Since I am new to Linux and Nextcloud I throw this there out as learning curve. Makes me feel better.
This did not work with my current settings when I did the force automatic removal. And upon changing received some errors.
After a long couple of days I worked it out and this auto removal worked.

Had to change to Cron this cause an error in logging.
Error: Exception: The requested uri(http:/www.google.com/nextcloud) cannot be processed by the script ‘/nextcloud/index.php’)
What???
Added cron job:
crontab -u www-data -e
*/15 * * * * php -f /var/www/nextcloud/cron.php

Be sure to specify your path to cron.php… example. /var/www/html/nextcloud/cron.php

Files in Deleted Files were removed as specified.

This created a new error in logging.
OC\User\NoUserException: 36B664A4-338F-499B-B9D7-2D10A9BE1CEF is not a valid user anymore.

To check:
sudo -u www-data php occ ldap:check-user 36B664A4-338F-499B-B9D7-2D10A9BE1CEF
The user does not exists on LDAP anymore.
Clean up the user’s remnants by: ./occ user:delete “36B664A4-338F-499B-B9D7-2D10A9BE1CEF”
To Remove:
sudo -u www-data php ./occ user:delete “36B664A4-338F-499B-B9D7-2D10A9BE1CEF”
The specified user was deleted

There is a lot of resources out there but being new maybe I should have researched more for initial NextCloud best practices.
Next stop. Throw more files in deleted and make double sure it works. Then on to production server! :slightly_smiling_face:

This may not have anything to do with the change to config.php but it happened and if it happens to someone else this may help.
Big Thanks to all the people who post out there. Appreciate it.

Cheers.