Another missing .ocdata in the root of the data directory issue

Yes another .ocdata issue. I’m so sorry I tried my best.

Moved my data directory. Followed this guide: HowTo: Change / Move data directory after installation

I’m pretty sure this is a permission issue with my new data drive but I can’t seem to get the settings right or doing the syntax wrong.

1. sudo -u www-data php /path/to/nextcloud/occ maintenance:mode --on
2. mkdir -p /new/path/to/data
3. cp -a /path/to/data/. /new/path/to/data
4. chown -R www-data:www-data /new/path/to/data
5. nano /path/to/nextcloud/config/config.php
       'datadirectory' => '/new/path/to/data',
6. mysqldump -u<rootuser> -p > /path/to/dbdump/dump.sql
7. Adjust "oc_storages"database table to reflect the new data folder location:
      echo "Your Nextcloud dbname is: $(awk -F\' "/'dbname'/{print \$4;exit}" /path/to/nextcloud/config/config.php)"
      dbuser=$(awk -F\' "/'dbuser'/{print \$4;exit}" /path/to/nextcloud/config/config.php)
      dbpassword=$(awk -F\' "/'dbpassword'/{print \$4;exit}" /path/to/nextcloud/config/config.php)
      mysql -u"$dbuser" -p"$dbpassword"
      // Inside the MySQL console:
      use <dbname>;
      update oc_storages set id='local::/new/path/to/data/' where id='local::/path/to/data/'; //take care about backslash at the end of path!!
      // Again outside the MySQL console
      unset -v dbuser dbpassword
8. sudo -u www-data php /path/to/nextcloud/occ maintenance:mode --off

Nextcloud version (eg, 20.0.5):
Operating system and version (eg, Ubuntu 20.04): Ubuntu 22.04.3 LTS
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.52 (Ubuntu)
PHP version (eg, 7.4): PHP 8.1.2-1ubuntu2.14 (cli)

The issue you are facing:
Your data directory is invalid. Ensure there is a file called “.ocdata” in the root of the data directory.

Is this the first time you’ve seen this error? Y

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

$CONFIG = array (
  'instanceid' => 'ockz1fm1avme',
  'passwordsalt' => 'hidden',
  'secret' => 'hidden',
  'trusted_domains' =>
  array (
    0 => '',
    1 => '',
  'trusted_proxies' =>
  array (
    0 => '',
  'forwarded_for_headers' =>
  array (
    0 => 'X-Forwarded-For',
  'htaccess.RewriteBase' => '/',
  'datadirectory' => '/mnt/nasdata',
  'dbtype' => 'mysql',
  'version' => '',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'ncadmin',
  'dbpassword' => 'mypassword',
  'installed' => true,
  'maintenance' => true,

I’m not sure what /mnt/data/ is. I double checked the commands I ran and it was definitely /mnt/nasdata/. I can remove #4 if needed.

Data drive before running
sudo chown -R www-data:www-data /mnt/nasdata/
sudo chmod -R 755 /mnt/nasdata/


After running those commands


{"reqId":"lwW4ulkOg0bW86BSIRXU","level":3,"time":"2023-09-02T02:30:41+00:00","remoteAddr":"MYIP","user":"--","app":"PHP","method":"GET","url":"/index.php/204","message":"file_get_contents(/mnt/nasdata/appdata_ockz1fm1avme/js/core/merged-template-prepend.js.deps): Failed to open stream: No such file or directory at /var/www/html/lib/private/Files/Storage/Local.php#305","userAgent":"Mozilla/5.0 (Windows) mirall/3.9.2stable-Win64 (build 20230808) (Nextcloud, windows-10.0.22621 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":{"app":"PHP"}}
{"reqId":"BAjvHOMXEzif5W9th74W","level":3,"time":"2023-09-02T02:31:43+00:00","remoteAddr":"MYIP","user":"--","app":"PHP","method":"GET","url":"/index.php/204","message":"file_get_contents(/mnt/nasdata/appdata_ockz1fm1avme/js/core/merged-template-prepend.js.deps): Failed to open stream: No such file or directory at /var/www/html/lib/private/Files/Storage/Local.php#305","userAgent":"Mozilla/5.0 (Windows) mirall/3.9.2stable-Win64 (build 20230808) (Nextcloud, windows-10.0.22621 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":{"app":"PHP"}}
{"reqId":"rZeO3yImU4Eu8NCtqlor","level":3,"time":"2023-09-02T02:32:45+00:00","remoteAddr":"MYIP","user":"--","app":"PHP","method":"GET","url":"/index.php/204","message":"file_get_contents(/mnt/nasdata/appdata_ockz1fm1avme/js/core/merged-template-prepend.js.deps): Failed to open stream: No such file or directory at /var/www/html/lib/private/Files/Storage/Local.php#305","userAgent":"Mozilla/5.0 (Windows) mirall/3.9.2stable-Win64 (build 20230808) (Nextcloud, windows-10.0.22621 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":{"app":"PHP"}}

Still no luck but I dug through a dozen articles and tried to change the fstab mount to this.

( /mnt/nasdata cifs vers=3.0,credentials=/.nascred,rw,file_mode=0777,dir_mode=0777)

I may have figured it out.

My mount seems to have stopped reconnecting after reboot. I guess that’s easy to miss (for me) if you are just browsing the folder structure via ssh gui. Everything was still showing up but not actually mapped to the network drive.
I ran a “sudo mount -a” and got error 2 (No such file or directory) opening credential file /.nascred
The password file I was using stopped working.

I put the username and password into the actual string and rebooted.
Fixed that problem but got another one something like “can’t write to data directory

Which lead me here:

I ran some chown 777 commands and got this error:
Please change the permissions to 0770 so that the directory cannot be listed by other users

Eventually I found this:

I changed my fstab to this replicating some examples other people have posted. Nextcloud loaded up fine with no GUI errors.

// /mnt/nasdata cifs username=nasuser,password=nasuserpassword,uid=33,dir_mode=0770,file_mode=0666

It’s probably better to use an NFS share rather then SMB from the NAS but that’s what I had setup already.

From my laptop I can open the Nextcloud “app” and create a new folder and I see it populate over to my NAS location. However if I UNC to the NAS data location and create a folder it doesn’t populate into Nextcloud - but I think that is expected behavior.

I need to try it with some test users and see if the folders / permissions are actually working. But so far, much better.

Since CIFS does not support UNIX permissions, you cannot use such a share directly as Nextcloud data directory.

What works is adding the Samba/CIFS share as external storage via the related Nextcloud app. But for performance reasons, if possible, make the Nextcloud server system the network storage instead of having that on a dedicated system. Respectively make the Nextcloud server system the NAS or put Nextcloud onto the NAS.

With NFS is can generally work as long as on the NFS server a user with the same user ID and proper permissions exist. But I cannot imagine that it works great. AFAIK also an NFS share can and better should be added as external storage.

Its been working perfect the way I described with the cifs share. Permissions and all.

I had nextcloud on my nas previously. Didn’t care for having it there. There is a lot more flexibility having NC on its own vm in a hypervisor separated from a storage appliance (for me).

I tried the external storage option for smb. Also not a fan.

Of course this works, as then the filesystem is locally mounted as Linux filesystem, so UNIX permissions work etc. But when you mount a remote CIFS share, all those chmod/chown commands have no effect (which is why my HowTo cannot work) as UNIX permissions are simply not supported by this cifs filesystem type and not passed through to the server, along with other limitations.

You can hack around it somehow, e.g. use the user=www-data mount option to have the whole mountpoint owned by the webserver/PHP user. But really, the data directory is intended to be a “local” drive. If Nextcloud needs to connect to a remote server on every little R/W to this directory, this worsens performance significantly, and I am not sure how well it handles the other implications, like latency, uncommon filesystem parameters (block sizes etc) and all this. I’m actually pretty sure that a lot of features simply require a native Linux filesystem with all its features.

Not sure which flexibility you mean and what practical benefit exactly you see. I only see more complexity and practical + massive performance downsides. You must anyway not write directly to the Nextcloud data dir, but only through Nextcloud/WebDAV.

It is not great indeed, e.g. AFAIK it is not reliably scanned for changes, at least it was like that. This is anyway not intended as main data dir, but as extension in cases where other network shares exist for a good reason. But having them only as main Nextcloud data dir is a bad concept IMO, and basically unsupported for sure.

Compared to the infrastructure I deal with at work this is pretty basic. Actually - performance is great. The same if not better then before.

I like sticking to what things are made for because that’s what they are best at. I use TrueNAS (previously FreeNAS). It was built first and foremost to be good at storing data. Later they added the functionality to run plugins / vms. Sure they work but it’s not good at plugins / vms. Actually TrueNAS seems to have one of the worst vm systems.
I ran VMs and plugins on my NAS for a long time and it worked - not great but it worked.

But there are limitations.
Especially with pre-built systems like a QNAP or Synology that come with a set amount of memory or low end CPU. The more VMs / plugins you put on it the less it has for its primary job (storage) and you will feel that performance hit.

Benefits (for me):

  • NAS has all available memory / cpu for file system and cache
  • VMs / plugins aren’t limited to how much memory / cpu I can give them
  • The VMs can failover to a 2nd hypervisor for maintenance or if one goes down
  • Easier to backup VMs
  • Not having all my eggs in one basket (if the nas goes down everything goes down)
  • I’d rather have SSDs in my hypervisor for the VMs and put as many large capacity drives in my NAS as possible

Performance is excellent over the network - uploads and downloads.

Anyway we could go back and forth forever on pros / cons, why / why not. This is how I wanted to do it. I hope my solution can help someone else down the road.