Sync Nextcloud database with what is on the hard drive / filesystem

Hi all, this is my first post on the Nextcloud community and I’m hoping I can get some help from here.

I am having trouble permanently deleting files from the Deleted files section using the web interface. I get an error saying “Error while removing file from trashbin”. I also see the following message under the Logging tab: “Exception: Failed to remove item from trashbin”. I have attached a screenshot of this error.

Additionally, I SSH’d into the server and deleted all the files in the trash folders, hoping they will disappear from the web interface, but they don’t. I believe it’s because the database still knows about those files. So then I went into the MySQL database and deleted the rows for those files from the tables in the database, but I’m still not able to get rid of the files in the web interface under Deleted Files (bottom-left corner)

So my question is, is there a way to sync up the rows/entries in the database with what is on the filesystem, because I believe that they are out of sync and that’s the reason for my problems.

PS: I have already tried the following commands and they did not fix anything:
sudo -u www-data php occ trashbin:cleanup
sudo -u www-data php occ files:scan
sudo -u www-data php occ files:cleanup

Any assistance would be greatly appreciated.

Thanks,
Morné

EDIT:
Here is what is in the log file relating to the file I’m trying to delete from the trash:

{"reqId":"Eex3sEgtmVMz1imFTeBG","level":4,"time":"2019-10-07T11:59:50+00:00","remoteAddr":"102.182.182.199","user":"morne","app":"webdav","method":"DELETE","url":"\/remote.php\/dav\/trashbin\/morne\/trash\/billexport_7902800%20(1).csv.d1549621244","message":{"Exception":"Exception","Message":"Failed to remove item from trashbin","Code":0,"Trace":[{"file":"\/var\/www\/nextcloud\/apps\/files_trashbin\/lib\/Trash\/TrashManager.php","line":69,"function":"removeItem","class":"OCA\\GroupFolders\\Trash\\TrashBackend","type":"->","args":[{"__class__":"OCA\\GroupFolders\\Trash\\GroupTrashItem"}]},{"file":"\/var\/www\/nextcloud\/apps\/files_trashbin\/lib\/Sabre\/AbstractTrash.php","line":83,"function":"removeItem","class":"OCA\\Files_Trashbin\\Trash\\TrashManager","type":"->","args":[{"__class__":"OCA\\GroupFolders\\Trash\\GroupTrashItem"}]},{"file":"\/var\/www\/nextcloud\/3rdparty\/sabre\/dav\/lib\/DAV\/Tree.php","line":179,"function":"delete","class":"OCA\\Files_Trashbin\\Sabre\\AbstractTrash","type":"->","args":[]},{"file":"\/var\/www\/nextcloud\/3rdparty\/sabre\/dav\/lib\/DAV\/CorePlugin.php","line":287,"function":"delete","class":"Sabre\\DAV\\Tree","type":"->","args":["trashbin\/morne\/trash\/billexport_7902800 (1).csv.d1549621244"]},{"function":"httpDelete","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[{"absoluteUrl":"https:\/\/cloud.hidden.co.za\/remote.php\/dav\/trashbin\/morne\/trash\/billexport_7902800%20(1).csv.d1549621244","__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"\/var\/www\/nextcloud\/3rdparty\/sabre\/event\/lib\/EventEmitterTrait.php","line":105,"function":"call_user_func_array","args":[[{"__class__":"Sabre\\DAV\\CorePlugin"},"httpDelete"],[{"absoluteUrl":"https:\/\/cloud.hidden.co.za\/remote.php\/dav\/trashbin\/morne\/trash\/billexport_7902800%20(1).csv.d1549621244","__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]]},{"file":"\/var\/www\/nextcloud\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php","line":479,"function":"emit","class":"Sabre\\Event\\EventEmitter","type":"->","args":["method:DELETE",[{"absoluteUrl":"https:\/\/cloud.hidden.co.za\/remote.php\/dav\/trashbin\/morne\/trash\/billexport_7902800%20(1).csv.d1549621244","__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]]},{"file":"\/var\/www\/nextcloud\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php","line":254,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[{"absoluteUrl":"https:\/\/cloud.hidden.co.za\/remote.php\/dav\/trashbin\/morne\/trash\/billexport_7902800%20(1).csv.d1549621244","__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"\/var\/www\/nextcloud\/apps\/dav\/lib\/Server.php","line":316,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"\/var\/www\/nextcloud\/apps\/dav\/appinfo\/v2\/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"\/var\/www\/nextcloud\/remote.php","line":163,"args":["\/var\/www\/nextcloud\/apps\/dav\/appinfo\/v2\/remote.php"],"function":"require_once"}],"File":"\/var\/www\/nextcloud\/apps\/groupfolders\/lib\/Trash\/TrashBackend.php","Line":119,"CustomMessage":"--"},"userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/77.0.3865.90 Safari\/537.36","version":"16.0.5.1"}

In case this is still of interest…
The occ files:scan command doesn’t fix database entries for files missing on the file system. It only adds files found on the file system to the database but not the other way around. (In my opinion it definitely should.)

As a work around you have to delete the entry in the filecache table directly.
SELECT * FROM oc_filecache WHERE path LIKE 'path_to_file';
and when you are sure
DELETE FROM oc_filecache WHERE path LIKE 'path_to_file';

If you accidentally delete too many files from the DB, occ files:scan will fix that for you. But be careful!

1 Like