nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.17k stars 4.04k forks source link

Clean stale local storages from `oc_storages` and `oc_filecache` #43861

Open tobast opened 7 months ago

tobast commented 7 months ago

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

  1. Populate Nextcloud with some files, so that the local:: storage has entries;
  2. move the data directory location and change the data path in the configuration file accordingly;
  3. rescan files (occ files:scan --all);
  4. 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.

solracsf commented 7 months ago

No it doesn't, but you should also move datafolder dir by the docs (so, editing the DB local:: entry, and not re-scanning the new dir).

https://docs.nextcloud.com/server/latest/admin_manual/issues/general_troubleshooting.html#troubleshooting-data-directory

agru commented 5 months ago

I have the same problem in my installation. And I also have already did a scan on the new data directory with occ files:scan --all. As the entries in oc_filecache with storage=1 are no longer valid, and due to the scan new entries for the new data directory are created, would it be safe to just delete all these stale entries to get rid of them by

DELETE FROM oc_filecache WHERE storage=1;

Or will this be the cause of new, bigger problems than before?

LMRW commented 4 months ago

Same problem. I found a few steps to work around.

https://github.com/nextcloud-snap/nextcloud-snap/issues/2758#issuecomment-2143605231