What the message looks like
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.Common causes
- The data volume (second disk, NFS, SMB, bind mount) is not mounted after a reboot, so the path exists but is empty.
datadirectoryinconfig.phppoints to a different path than the real one, for example after a move or a migration.- The hidden file
.ocdatawas not copied, because the copy skipped dot files or only some folders were restored from a backup. - The web server user cannot read the directory, for example after wrong
chownor a changed mount option.
Check
- Which path does Nextcloud use?
grep datadirectory /var/www/nextcloud/config/config.php - Is the marker file there?
ls -la /srv/nextcloud-data/.ocdata - Is the volume really mounted?
findmnt /srv/nextcloud-data - Owner and mode of the directory
stat -c '%U:%G %a %n' /srv/nextcloud-data
Fix
- Mount the volume first and check that your user folders and
nextcloud.logare visible in the data directory. Make the mount start before the web server, for example withRequiresMountsFor=/srv/nextcloud-datain a systemd drop-in. - If the path in
config.phpis wrong, set the real one indatadirectoryand nowhere else. - Only when the folder is the real data directory and the file is missing, recreate it:
sudo -u www-data touch /srv/nextcloud-data/.ocdata. Never do this on an empty mount point. - Fix the owner:
chown -R www-data:www-data /srv/nextcloud-dataand mode0750on the directory. - Reload the page. For future copies use
rsync -a, which keeps dot files.
Typical scenario
You moved the data directory to a new disk, adjusted the paths in config.php, and now the page shows Your data directory is invalid. Ensure there is a file called .ocdata in the root of the data directory. A common trigger: the content was copied with cp -r /old/* /new/. The wildcard skips hidden files, so exactly .ocdata is missing. First check with ls -la whether the file exists in the new directory.
FAQ
Can I just create .ocdata to make the error go away?
Only if you are sure the directory holds your real data. On an unmounted empty folder it would make Nextcloud start with a new, empty instance, and the first uploads would land on the wrong disk.
Why does it happen after every reboot?
Usually the mount comes up later than the web server or fails silently. Check the mount unit or the fstab line and add a dependency so the web server waits for it.
How do I move the data directory correctly?
Enable maintenance mode with occ maintenance:mode --on, copy the folder with rsync -a so hidden files and permissions survive, then adjust datadirectory in config.php and turn maintenance mode off. Nothing needs to change in the database.
Which permissions does the data directory need?
It must belong to the web server user, for example www-data, and not be readable by other users. After copying as root everything belongs to root and Nextcloud reports write errors. chown -R www-data:www-data restores the ownership.
May the data directory live inside the web root?
That is discouraged. Inside the web root, files could become reachable by URL if the access rules ever go missing. Keep it outside, for example under /srv/nextcloud-data, and give the web server access only through Nextcloud itself.