Short tip: Remove Nextcloud File Locks

To prevent accidental overwriting of files during synchronization - especially between multiple users and clients - Nextcloud relies on File Locking. This function is implemented at application level and therefore has no special requirements for the file system used.

However, with large amounts of data and network problems, a dead lock can sometimes occur: Files cannot be deleted even though they are no longer in use. Corresponding error messages in the web interface and the corresponding clients show that the file is locked.

The locks can also be verified via the occ CLI - for example for all users:

1$ ./occ files:scan --all
2Starting scan for user 1 out of 1337 (sgiertz)
3Starting scan for user 2 out of 1337 (ppinkepank)
4...
5Exception while scanning: "files/[...]" is locked
Note

For larger environments, it is recommended to run the scan only for affected users: ./occ files:scan [name]

One approach to solving the problem is to temporarily put Nextcloud into maintenance mode and remove the locks in the database:

1$ ./occ maintenance:mode --on
1$ mysql -u <nextcloud_user> -p <nextcloud_db>
2MariaDB [nextcloud_db]> DELETE * FROM oc_file_locks;
1$ ./occ maintenance:mode --off

The scan should then show no more errors:

1$ ./occ files:scan --all
2Starting scan for user 1 out of 1337 (sgiertz)
3Starting scan for user 2 out of 1337 (ppinkepank)
4...
5+---------+-------+--------+--------------+
6| Folders | Files | Errors | Elapsed time |
7+---------+-------+--------+--------------+
8| 81      | 606   | 0      | 00:00:02     |
9+---------+-------+--------+--------------+

Translations: