Set datadirectory is create datadirectory?

I am trying to change the location of nextcloud data directory after restore

docker exec --user www-data nextcloud php occ config:system:set datadirectory --value=/var/www/html/data

This fails with message that the data directory cannot be created. I assume this is because the data directory already exists

root@collab:~# docker exec --user www-data nextcloud php occ config:system:set datadirectory --value=/var/www/html/data
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/16/go.php?to=admin-dir_permissions

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/html/lib/private/Console/Application.php:166
Stack trace:
#0 /var/www/html/console.php(96): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/html/occ(11): require_once('/var/www/html/c...')
#2 {main}root@collab:~# 

Note, that when I enter the container as www-user I can create files / directories and the .ocdata file does exist and it readable for www-user.

My assumption was that this command would allow me to change the data directory. I think this is wrong. This command is used to create the data directory I think. A better name would be create I think

occ config:system:create datadirectory

Having said that, what would be the correct way to change the datadirectory location in config.php?

why you want to do this?

I am restoring a owncloud backup in a nextcloud instance. The owncloud instance is not in a docker container and the data directory is in a different location.

My understanding is that I also have to restore the config.php because it contains stuff like instanceid, passwordsalt and secret properties that are tied to the restored instance.

After restore of config.php I try to update those properties that need to be changed such as datadirectory, database connection etc.

Yes. But you don’t want to restore into the container.
All data that you want to keep are in docker volumes.

You store the nextcloud data files somewhere on your host e.g. /srv/nextcloud/data and map this into the container with -v /srv/netxcloud/data:/var/www/html/data

With this you don’t need to change this in config.php.

You also use a docker volume. Then you find the location on your host somewhere below /var/lib/docker . docker inspect nextcloud will tell you. In this case you don’t have to care about file ownership and rights.

The same applys to config.php. That is to say you put the config directory into a volume. So you can restore this files (and edit) on your host.

P.S.: All in one would be: -v nextcloud:/var/www/html

Agreed but the OwnCloud instance is not in a container. The OwnCloud database is also not in a container. So I restore the data into the volume container and then I have to change the restored config.php