Error: Your data directory is invalid Ensure there is a file called ".ocdata" in the root of the data directory

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 23.0.5
Operating system and version (eg, Ubuntu 20.04): Debian 11
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.53 (Debian)
PHP version (eg, 7.4): 7.4

The issue you are facing:

I get the following errors on my settings page

There are some errors regarding your setup.

  • It was not possible to execute the cron job via CLI. The following technical errors have appeared:
  1. Your data directory is invalid Ensure there is a file called “.ocdata” in the root of the data directory.
  2. Cannot create “data” directory This can usually be fixed by giving the webserver write access to the root directory. See https://docs.nextcloud.com/server/23/go.php?to=admin-dir_permissions

Is this the first time you’ve seen this error? (Y/N): N

Steps to replicate it:

  1. Install Nextdcloud with data directory on /media/nc-500gb/
  2. Turn off server; disconnect data drive, add, migrate, and reorganize data on /media/nc-2tb/
  3. Chown, chmod, update config.php, update oc_storages in databases, occ files:scan
  4. Visit settings page; see error.

The output of your Nextcloud log in Admin > Logging:

See: Mozilla Community Pastebin/GBN2sWJf (IRC logs)

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'xxxx',
  'passwordsalt' => 'xxxx',
  'secret' => 'xxxx',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'nc.xxxx.com',
    2 => '192.168.xxx.xxx',
  ),
  'datadirectory' => '/media/nc-2tb/ncdata',
  'dbtype' => 'mysql',
  'version' => '23.0.5.1',
  'overwrite.cli.url' => 'http://nc.xxxx.com',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxxx',
  'installed' => true,
  'updater.secret' => 'xxxx',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
);

The output of your Apache/nginx/system log in /var/log/____:

[Mon May 30 12:30:52.911782 2022] [php7:notice] [pid 737] [client 192.168.xxx.xxx:48688] {"reqId":"zxT0jZYcUjD5Ne2Tbc7X","level":3,"time":"2022-05-30T16:30:52+00:00","remoteAddr":"192.168.xxx.xxx","user":"--","app":"PHP","method":"GET","url":"/index.php/204","message":"file_get_contents(/media/nc-500gb/ncdata/appdata_ocpk7we61bcu/js/core/merged-template-prepend.js.deps): failed to open stream: No such file or directory at /var/www/nc.xxxx.com/lib/private/Files/Storage/Local.php#277","userAgent":"Mozilla/5.0 (Android) Nextcloud-android/3.20.1","version":"23.0.4.1","exception":{"Exception":"Error","Message":"file_get_contents(/media/nc-500gb/ncdata/appdata_ocpk7we61bcu/js/core/merged-template-prepend.js.deps): failed to open stream: No such file or directory at /var/www/nc.xxxx.com/lib/private/Files/Storage/Local.php#277","Code":0,"Trace":[{"function":"onError","class":"OC\\\\Log\\\\ErrorHandler","type":"::"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/Storage/Local.php","line":277,"function":"file_get_contents"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/Storage/Wrapper/Wrapper.php","line":247,"function":"file_get_contents","class":"OC\\\\Files\\\\Storage\\\\Local","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/View.php","line":1171,"function":"file_get_contents","class":"OC\\\\Files\\\\Storage\\\\Wrapper\\\\Wrapper","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/View.php","line":601,"function":"basicOperation","class":"OC\\\\Files\\\\View","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/Node/File.php","line":56,"function":"file_get_contents","class":"OC\\\\Files\\\\View","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/SimpleFS/SimpleFile.php","line":90,"function":"getContent","class":"OC\\\\Files\\\\Node\\\\File","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSCombiner.php","line":127,"function":"getContent","class":"OC\\\\Files\\\\SimpleFS\\\\SimpleFile","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSCombiner.php","line":102,"function":"isCached","class":"OC\\\\Template\\\\JSCombiner","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSResourceLocator.php","line":115,"function":"process","class":"OC\\\\Template\\\\JSCombiner","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSResourceLocator.php","line":71,"function":"cacheAndAppendCombineJsonIfExist","class":"OC\\\\Template\\\\JSResourceLocator","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/ResourceLocator.php","line":78,"function":"doFind","class":"OC\\\\Template\\\\JSResourceLocator","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/TemplateLayout.php","line":388,"function":"find","class":"OC\\\\Template\\\\ResourceLocator","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/TemplateLayout.php","line":216,"function":"findJavascriptFiles","class":"OC\\\\TemplateLayout","type":"::"},{"file":"/var/www/nc.xxxx.com/lib/private/legacy/OC_Template.php","line":182,"function":"__construct","class":"OC\\\\TemplateLayout","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/Base.php","line":132,"function":"fetchPage","class":"OC_Template","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/legacy/OC_Template.php","line":272,"function":"printPage","class":"OC\\\\Template\\\\Base","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/base.php","line":662,"function":"printGuestPage","class":"OC_Template","type":"::"},{"file":"/var/www/nc.xxxx.com/lib/base.php","line":1089,"function":"init","class":"OC","type":"::"},{"file":"/var/www/nc.xxxx.com/index.php","line":34,"args":["/var/www/nc.xxxx.com/lib/base.php"],"function":"require_once"}],"File":"/var/www/nc.xxxx.com/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"}}
[Mon May 30 12:30:53.679980 2022] [php7:notice] [pid 737] [client 192.168.xxx.xxx:48688] {"reqId":"zxT0jZYcUjD5Ne2Tbc7X","level":3,"time":"2022-05-30T16:30:53+00:00","remoteAddr":"192.168.xxx.xxx","user":"--","app":"PHP","method":"GET","url":"/index.php/204","message":"file_put_contents(/media/nc-500gb/ncdata/appdata_ocpk7we61bcu/js/core/merged-template-prepend.js): failed to open stream: No such file or directory at /var/www/nc.xxxx.com/lib/private/Files/Storage/Local.php#282","userAgent":"Mozilla/5.0 (Android) Nextcloud-android/3.20.1","version":"23.0.4.1","exception":{"Exception":"Error","Message":"file_put_contents(/media/nc-500gb/ncdata/appdata_ocpk7we61bcu/js/core/merged-template-prepend.js): failed to open stream: No such file or directory at /var/www/nc.xxxx.com/lib/private/Files/Storage/Local.php#282","Code":0,"Trace":[{"function":"onError","class":"OC\\\\Log\\\\ErrorHandler","type":"::"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/Storage/Local.php","line":282,"function":"file_put_contents"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/Storage/Wrapper/Wrapper.php","line":258,"function":"file_put_contents","class":"OC\\\\Files\\\\Storage\\\\Local","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/View.php","line":1169,"function":"file_put_contents","class":"OC\\\\Files\\\\Storage\\\\Wrapper\\\\Wrapper","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/View.php","line":706,"function":"basicOperation","class":"OC\\\\Files\\\\View","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/Node/Folder.php","line":198,"function":"file_put_contents","class":"OC\\\\Files\\\\View","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Files/SimpleFS/NewSimpleFile.php","line":133,"function":"newFile","class":"OC\\\\Files\\\\Node\\\\Folder","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSCombiner.php","line":202,"function":"putContent","class":"OC\\\\Files\\\\SimpleFS\\\\NewSimpleFile","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSCombiner.php","line":105,"function":"cache","class":"OC\\\\Template\\\\JSCombiner","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSResourceLocator.php","line":115,"function":"process","class":"OC\\\\Template\\\\JSCombiner","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/JSResourceLocator.php","line":71,"function":"cacheAndAppendCombineJsonIfExist","class":"OC\\\\Template\\\\JSResourceLocator","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/ResourceLocator.php","line":78,"function":"doFind","class":"OC\\\\Template\\\\JSResourceLocator","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/TemplateLayout.php","line":388,"function":"find","class":"OC\\\\Template\\\\ResourceLocator","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/TemplateLayout.php","line":216,"function":"findJavascriptFiles","class":"OC\\\\TemplateLayout","type":"::"},{"file":"/var/www/nc.xxxx.com/lib/private/legacy/OC_Template.php","line":182,"function":"__construct","class":"OC\\\\TemplateLayout","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/Template/Base.php","line":132,"function":"fetchPage","class":"OC_Template","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/private/legacy/OC_Template.php","line":272,"function":"printPage","class":"OC\\\\Template\\\\Base","type":"->"},{"file":"/var/www/nc.xxxx.com/lib/base.php","line":662,"function":"printGuestPage","class":"OC_Template","type":"::"},{"file":"/var/www/nc.xxxx.com/lib/base.php","line":1089,"function":"init","class":"OC","type":"::"},{"file":"/var/www/nc.xxxx.com/index.php","line":34,"args":["/var/www/nc.xxxx.com/lib/base.php"],"function":"require_once"}],"File":"/var/www/nc.xxxx.com/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"}}
[Mon May 30 12:30:53.682574 2022] [php7:notice] [pid 737] [client 192.168.xxx.xxx:48688] {"reqId":"zxT0jZYcUjD5Ne2Tbc7X","level":3,"time":"2022-05-30T16:30:53+00:00","remoteAddr":"192.168.xxx.xxx","user":"--","app":"no app in context","method":"GET","url":"/index.php/204","message":"JSCombiner: unable to cache: merged-template-prepend.js","userAgent":"Mozilla/5.0 (Android) Nextcloud-android/3.20.1","version":"23.0.4.1"}
[Mon May 30 12:30:53.913940 2022] [php7:notice] [pid 737] [client 192.168.xxx.xxx:48688] {"reqId":"zxT0jZYcUjD5Ne2Tbc7X","level":3,"time":"2022-05-30T16:30:53+00:00","remoteAddr":"192.168.xxx.xxx","user":"--","app":"PHP","method":"GET","url":"/index.php/204","message":"fopen(/media/nc-500gb/ncdata/nextcloud.log): failed to open stream: No such file or directory at /var/www/nc.xxxx.com/lib/private/Log/File.php#84","userAgent":"Mozilla/5.0 (Android) Nextcloud-android/3.20.1","version":"23.0.4.1"}

Output of relevant commands:

$ sudo grep datadirectory /var/www/nc.hxfam.com/config/config.php
  'datadirectory' => '/media/nc-2tb/ncdata',
$ sudo ls -ld $( sudo grep datadirectory /var/www/nc.hxfam.com/config/config.php | awk '{ print $3 }' | grep -oP "[^']*[^']" | head -1 )
drwxr-x--- 5 www-data www-data 4096 May  4 19:05 /media/nc-2tb/ncdata
$ ls -l /media/ 
total 8
drwxr-xr-x 4 www-data www-data 4096 May  4 19:05 nc-2tb
drwxr-xr-x 2 root     root     4096 Apr 22 08:49 nc-500gb
$ sudo systemctl status nc-automount-links
Unit nc-automount-links.service could not be found.

Do I need to create some kind of symlink from /media/nc-500gb/ to /media/nc-2tb/?
What would you all recommend?

Thanks
–P

Alright, someone help me out here. So I am on Ubuntu 22.10, latest verison. My nextcloud is running fine and all that great stuff however, I wanted to move my NextCloud data directory from my spinning ZFS pool to my NVMe ZFS pool. Keep in mind I am aware of the ownership and permissions needed, so everything was owned by the www-data user and group along with rwx for both, so permissions were set recursivly to 770, yet I keep getting the following error when I change config.php to new data directory and turn maintenance mod off:

nextcloud your data directory is invalid. ensure there is a file called ".ocdata" in the root of the data directory. cannot create "data" directory. this can usually be fixed by giving the web server write access to the root directory

So the steps I followed are as follows:

  1. Set Maintnance mode to --on

  2. Moved data directory, now keep in mind for troubeshooting I’ve used all of these commands thinking maybe it’s a command thing and something isn’t coming over right.

  • cp -a /path/to/nc/data-store/. /newPath/to/nc/data-store
  • rsync -av /path/to/nc/ /newPath/to/nc/
  • mv /path/to/nc/data-store /newPath/to/nc/
  1. Set the permissions to 770 and chown’d recursivly to www-data:www-data using the -Rv options on both.

  2. Updated 'datadirectory' => ''/newPath/to/nc/data-store',

  3. Turned Maintenance mode off.

  4. Restarted apache

and again… I get…

nextcloud your data directory is invalid. ensure there is a file called ".ocdata" in the root of the data directory. cannot create "data" directory. this can usually be fixed by giving the web server write access to the root directory

I then ran $ touch .ocdata inside the data-store directory, chown’d it to www-data, set perms to 770… still get the above error… What am I doing wrong?

Also, forgot to mention, the good news is that I can always revert back to previous data-store and it works, comes up just fine… but NC just is not liking my new data-store and I don’t get it.

hello sorry to hear from your troubles.

to make sure that the permissions are set correctly instead of touch .ocdata and set the correct permissions you can try

sudo -u www-data touch .ocdata

ofcource in your new data directory.
this will verify that www-data has write access.

also check you php log for eventualy openbase_dir error.

extra ’ infront of your /newPath/to… is a typo here or in your config.php?

1 Like

@Vincent_Stans Thanks for your reply, so I did create that file and I did chown it to www-data:www-data along with perms to 770 however, I did not try to create it as the www-data user so i will try that. Addiitonally, yeah I do see that typo, but that was just me typing it in this comment, the real config.php is formatted properly. I will do that and then after that check the php logs, I assume /var/log/phpSomthing?

@Vincent_Stans Yeah that didn’t work. I dunno why. I think I am about to blow this sucker away and spin up a new one. the good thing about nextcloud is that when it’s personal use, all the client files stay on the clients, and the clients being my family members… so nothing is a loss.

@Vincent_Stans I figured it out. It was the fact that the nextcloud/data directory was in one of my shared folders via sama and it was the samba settings that were jacking it up. So I moved all my directories shared by samba into one whole directory, then left nextcloud/data outside of that directory/separate directory, so samba rules/perms don’t apply to it and it worked.

2 Likes

Craig,

I have the same issue from the same situation but I don’y understand how you fixed it.
Can you explain with a little more detail?

Thanks

Mike