Dealing with locked files in Nextcloud? It can really mess up your work. File locking is meant to stop problems when people are editing the same stuff at once. But sometimes these locks won’t budge, and that’s a headache. Let’s see why this happens and how you can fix it using redis configurations and more.

Understanding Locked Files in Nextcloud

Nextcloud uses a file locking system to avoid data mess-ups when multiple people edit files together. When you edit, it locks, so others can’t mess it up. Ideally, these locks drop off automatically once you save. But sometimes files stay locked longer than a checkout line at rush hour, which is annoying.

Key reasons for persistent locked files include:

  • Locks that fail or linger, often due to interrupted syncs or client crashes
  • Backend cache hiccups, especially related to Redis
  • Server overload, pulling out these locks real slow
  • Database quirks, like sluggish queries or blockages
  • Messed-up permissions on the server

Why File Locking Matters

The locking system protects files from conflicting changes when it works right. When it doesn’t, users might see “file is locked” errors. For instance, a team’s productivity tanked after Nextcloud updates led to more locked files—a frustrating roadblock no one wants.

Fixing Locked Files Using Redis Config

Redis acts as a fast, in-memory store for caches and locks in Nextcloud. Without Redis, the database does this job, but it’s slower and prone to hiccups.

Common Redis Hiccups Causing Locked Files

  1. Not having Redis installed: Without it, Nextcloud leans on the database for file locking.
  2. Messed-up Redis connection details: Wrong path or port info stops Nextcloud from hooking up to Redis.
  3. Overzealous Redis eviction policy: Dropping keys too soon or never renewing them can mess locks up.
  4. Limited Redis memory: Insufficient RAM may result in disappearing locks.
  5. No Redis locking in config: It can be used for caching but not necessarily for locking if misconfigured.

Configuring Redis Properly for Nextcloud

Use this sample config snippet for Nextcloud’s config.php:

'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' => [
  'host' => '/var/run/redis/redis-server.sock',
  'port' => 0,
  'timeout' => 0.0,
  'dbindex' => 0,
  'password' => '',
],
  • This setup uses a UNIX socket for security and speed.
  • 'memcache.locking' tells Nextcloud to use Redis for locking.
  • Avoid plain TCP in production for safety.

Quick Steps to Set Up Redis on Ubuntu

  1. Install Redis server:

    sudo apt update  
    sudo apt install redis-server  
  2. Check Redis is running:

    sudo systemctl status redis  
  3. Configure Redis for Nextcloud in /etc/redis/redis.conf:

    • Set maxmemory to something sensible, like maxmemory 256mb.
    • Use maxmemory-policy as allkeys-lru.
    • Enable socket connection:
      unixsocket /var/run/redis/redis-server.sock   
      unixsocketperm 770  
    • Restart Redis:
      sudo systemctl restart redis
  4. Add your web server user to Redis group:

    sudo usermod -aG redis www-data
    sudo systemctl restart redis
  5. Update Nextcloud’s config.php as before.

This setup lightens the database load, speeds things up, and keeps locks refreshed.

Real-World Example: Fixing Locked Files with Redis

A mid-sized company struggled with locked files after moving servers. They weren’t using Redis at first, sticking to MySQL. This led to many lock-related complaints. Following our steps, they set up Redis and tweaked their config, leading to significantly fewer complaints, faster syncs, and stable files.

Further Tricks and Tips

Even with Redis set up, sometimes you’ll need a bit more manual intervention.

Clearing Locked Files Manually

To clear out pesky locks, use these occ commands (as the web user):

sudo -u www-data php occ files:scan --all
sudo -u www-data php occ files:cleanup
sudo -u www-data php occ files:lock --unlock-all
  • files:scan updates the file index
  • files:cleanup tidies up leftover data
  • files:lock --unlock-all clears all locks (handle with care)

Verify File and Folder Permissions

Wrong permissions can cause locking issues. Set them right:

chown -R www-data:www-data /path/to/nextcloud/data  
find /path/to/nextcloud/data -type d -exec chmod 750 {} \;  
find /path/to/nextcloud/data -type f -exec chmod 640 {} \;

Avoid Collisions During Sync

Users juggling multiple devices risk conflict and locks. Tips for smoother operation:

  • Edit files one at a time, rather than using numerous clients simultaneously
  • Close programs after saving work
  • Leverage collaborative tools available within Nextcloud (e.g., Collabora Online, OnlyOffice)

Regularly Update Nextcloud and Apps

Stay on top with updates for core and apps to catch bug fixes and enhance functionality. Keep an eye on the official change logs.

Importance of File Locks for Data Safety

Proper locks prevent data loss by ensuring file edits don’t clash. Good redis configurations keep locks stable, reducing risks of sync errors and faulty files, which is crucial for teams handling sensitive content.

Wrap-Up

Locked files often crop up when the locking backend isn’t up to snuff, usually because of Redis misconfiguration or server hiccups. Properly setting up Redis boosts speed and lock dependability while reducing obstacles to saving and syncing files. Post-setup, monitor resource use and logs, manually address blocks as needed, and guide users on best practices.

Following these steps brings Nextcloud to a stable, fast, and enjoyable state for file sharing.

For more in-depth technical help, check out Dhabaka’s Nextcloud resources.


Need to fix Nextcloud’s locked files and speed things up? Install Redis, tweak your Nextcloud settings, and say goodbye to locked files headaches. For more expert support, visit Dhabaka.

Get in Touch