Sometimes, due to connectivity issues (or even NextCloud bugs), files may end up in a locked state on the server. This means they can no longer be modified in any way, not even deleted.

Start by making a backup of the files in question (check that they are in usable state beforehand), then continue by placing the server in maintenance mode:
sudo -u USERNAME php occ maintenance:mode --on
Clean up the oc_file_locks table in the database of any records with:
DELETE FROM oc_file_locks WHERE 1
Then turn off maintenance:
sudo -u USERNAME php occ maintenance:mode --off
If you notice anything out place, perform a bit of maintenance with with:
sudo -u USERNAME php occ files:scan --all
sudo -u USERNAME php occ files:cleanup

Finish things off by waiting for the client(s) to sync and then checking if the previously locked files are in order (and restore them from the backup if needed).

PS: Replace USERNAME with the correct username which owns the NextCloud data folder.

More info about file locks (and advanced configuration): https://docs.nextcloud.com/server/15/admin_manual/configuration_files/files_locking_transactional.html

Leave a Reply