Clean stale local storages from `oc_storages` and `oc_filecache`
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
Description
First of all, sorry if this is a duplicate issue. I did find occurrences of this question on forums (with no convincing answer), but no issue here.
Some time ago, I changed the datadirectory setting of a Nextcloud server (25.x at the time) after manually moving the data to its new path. I did so without taking precautions, and ended up with a new local entry in the oc_storages table:
nextcloud=> SELECT * FROM oc_storages WHERE id LIKE 'local%' ;
numeric_id | id | available | last_checked
------------+--------------------------------------+-----------+--------------
1 | local::/var/www/html/nextcloud/data/ | 1 |
272 | local::/data/nextcloud/data/ | 1 |
Rescanning the files (occ files:scan --all) made most things work again, and I did not overly bother with the issue after this, but I still have some leftover issues from this: for instance, sub-shares from group folders that must be re-shared, and the previous shares being empty directories (since they still point to the old storage path in the database).
I have since upgraded my instance to 27.1.6, and I would prefer being rid of these stale entries in my database to avoid any future issues. After manually running a files:cleanup (and files:repair-tree, in case it would help), the stale row in the database still has available to 1. I still have many (thousands) entries in oc_filecache with storage id 1, with (as expected) plenty of those duplicated in storage 272 (ie. same path and path_hash), which are not cleaned up as stale.
Steps to reproduce
- Populate Nextcloud with some files, so that the
local::storage has entries; - move the data directory location and change the data path in the configuration file accordingly;
- rescan files (
occ files:scan --all); - cleanup file cache (
occ files:cleanup)
Expected behavior
The stale entry from oc_storage should disappear, as the files are no longer available at this location (the directory was moved). The stale entries from oc_filecache should be cleaned up accordingly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the behavior of the mentioned occ files:scan, files:cleanup, and files:repair-tree commands around the oc_storages and oc_filecache tables. Reproduce the moved-datadirectory scenario and verify that stale storage rows and their file-cache entries are removed without affecting the active storage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- cli, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100