.ocdata file missing after changing data directory

Nextcloud version : 18.0.3.0
Operating system and version : Debian 10 (NextcloudPi)
Apache version: 2.4.38
PHP version : PHP 7.3.14

The issue you are facing:
I changed my data directory according to this tutorial: HowTo: Change / Move data directory after installation . I adjusted the following pathes of data_directory, tempdirectory and logfile to pathes on my new drive at /media/Nextcloud-Data, as written in my config.php:

Summary
$CONFIG = array (
  'passwordsalt' => *removed*,
  'secret' =>*removed*,
  'trusted_domains' => 
  array (
    0 => 'localhost',
    5 => 'nextcloudpi.local',
    7 => 'nextcloudpi',
    8 => 'nextcloudpi.lan',
    11 =>*removed*,
    1 => '192.168.2.103',
    3 => *removed*,
    4 => *removed*,
  ),
  'datadirectory' => '/media/Nextcloud-Data/NC-Data',
  'dbtype' => 'mysql',
  'version' => '18.0.3.0',
  'overwrite.cli.url' => *removed*,
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'ncadmin',
  'dbpassword' => *removed*,
  'installed' => true,
  'instanceid' => 'oc8iggjkub4w',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
    'password' => *removed*,
  ),
  'tempdirectory' => '/media/Nextcloud-Data/nc-tmp',
  'mail_smtpmode' => 'sendmail',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_from_address' => 'admin',
  'mail_domain' => 'ownyourbits.com',
  'preview_max_x' => '2048',
  'preview_max_y' => '2048',
  'jpeg_quality' => '60',
  'overwriteprotocol' => 'https',
  'maintenance' => true,
  'logfile' => '/media/Nextcloud-Data/nc-log/nextcloud.log',
  'loglevel' => 2,
);```

I also created the needed directories on /media/Nextcloud-Data and gave ownership to user www-data:

drwxr-xr-x 1 www-data www-data 584 May  1 10:32 NC-Data
drwxr-xr-x 1 www-data www-data   0 May  5 16:06 nc-log
drwxr-xr-x 1 www-data www-data   0 May  5 16:05 nc-tmp

Now i recognized two problems:
First, I wanted to remove the new pathes in my database using the commands from the tutorial:

      dbuser=$(awk -F\' "/'dbuser'/{print \$4;exit}" /path/to/nextcloud/config/config.php)
      dbpassword=$(awk -F\' "/'dbpassword'/{print \$4;exit}" /var/www/nextcloud/config/config.php)
      mysql -u$dbuser -p$dbpassword
      // Inside the MySQL console:
      use <nextclouddb>;
      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!!
      quit;
      // Again outside the MySQL console
      unset dbuser dbpassword

After the update command, I received the message:

    ERROR 1062 (23000): Duplicate entry 'local::/media/Nextcloud-Data/NC-Data/' for key 'storages_id_index'

I ignored this for first. Because I copied my files manually to the new directory /media/Nextcloud-Data/NC-Data, i had to run nc-scan. But here comes the following message:

Nextcloud is in maintenance mode - no apps have been loaded

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 webserver write access to the root directory. See https://docs.nextcloud.com/server/18/go.php?to=admin-dir_permissions

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:167
Stack trace:
#0 /var/www/nextcloud/console.php(98): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')

I am also not able to open the Web-API.

How can I solve this problem? Is the MariaDB error relevant in this case? And do I even have to run the database update, when I have to rescan all my files anyway? Thanks in Advance!

Here is my process that I use for moving the data der… maybe it can help you out ?

Search for section - Relocate DATA directory

https://sesipod.info/doku.php?id=sesipod:linux:debian-9:nextcloud17-0-2#tab__extras_fixes

Login to nextcloud and have a look under SETTINGS → Overview

If you have an error about .ocdata lets fix that…

crontab -u www-data -e

And append this line at the bottom of the file:

/5 * * * * php -f /var/www/nextcloud/cron.php
save and quit

force run cron php.

php -f /var/www/nextcloud/cron.php

The error should now be gone :slight_smile:

Process complete you can now use nextcloud again :slight_smile:

Be aware that in Linux, file names starting with a period are hidden files. Make sure you didn’t accidentally leave it behind when you moved.

Also make sure your data directory is owned by the web server user. Use the same permissions and ownership as the old one.

Otherwise do a
touch /media/Nextcloud-Data/NC-Data/.ocdata

Indeed, a

touch /media/Nextcloud-Data/NC-Data/.ocdata

worked. The message is gone and the web API shows up again. However, a nc-scan returns this:

Running nc-scan
Nextcloud is in maintenance mode - no apps have been loaded


In Application.php line 583:
                                                                    
  [Symfony\Component\Console\Exception\NamespaceNotFoundException]  
  There are no commands defined in the "files" namespace.           
                                                                    

Exception trace:
  at /var/www/nextcloud/3rdparty/symfony/console/Application.php:583
 Symfony\Component\Console\Application->findNamespace() at /var/www/nextcloud/3rdparty/symfony/console/Application.php:632
 Symfony\Component\Console\Application->find() at /var/www/nextcloud/3rdparty/symfony/console/Application.php:236
 Symfony\Component\Console\Application->doRun() at /var/www/nextcloud/3rdparty/symfony/console/Application.php:148
 Symfony\Component\Console\Application->run() at /var/www/nextcloud/lib/private/Console/Application.php:214
 OC\Console\Application->run() at /var/www/nextcloud/console.php:99
 require_once() at /var/www/nextcloud/occ:11

And if I disable maintenance mode, it finds no files:

Running nc-scan
Unknown user 1 _

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 0       | 0     | 00:00:00     |
+---------+-------+--------------+
Unknown user 1 _

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 0       | 0     | 00:00:00     |
+---------+-------+--------------+
Unknown user 1 _

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 0       | 0     | 00:00:00     |
+---------+-------+--------------+
Done. Press any key...

Why no user?

I don’t know. Might it be related to the problem I described above, that the sql update command doesn’t seem to work properly?

There is nothing to setup in the database, the only thing you have to change is the path in config.php