Temporary change the datadirectory for a OCC

How do I temporary change the “datadirectory” for a batch script with an OCC command?

What exactly do you want to do? Which command do you want to execute? Afaik, the Nextcloud data directory is usually taken from the config.php file and cannot be changed.

if I start occ I get this error:

An unhandled exception has been thrown:
TypeError: Return value of OC\AppFramework\Http\Request::getScriptName() must be of the type string, null returned in /test/test2/lib/private/AppFramework/Http/Request.php:838
Stack trace:
#0 /test/test2/lib/base.php(154): OC\AppFramework\Http\Request->getScriptName()
#1 /test/test2/lib/base.php(591): OC::initPaths()
#2 /test/test2/lib/base.php(1068): OC::init()
#3 /test/test2/console.php(46): require_once('/test/test2...')
#4 /test/test2/occ(10): require_once('/test/test2...')
#5 {main}

I Played around with this installation. I think It may the problem, that the “datadirectory” in config.php is wrong.
I would like to use occ to set this var but occ itself do not work.

Ususally there is no need to use occ to set the data directory, because you can edit the parameter directly in the config.php file of Nextcloud.
Nevertheless if you open /test/test2/lib/base.php you will see, starting at line 130, how the configuration file is being searched. Usually Nextcloud expects a directory named “config”, or a symbolic link with that name pointing to the directory, where the config.php file can be found.
If you follow the installation guide should help you with the right configuration.

I try to set datadirectory with occ config:system:set datadirectory
The Problem is I have access to a limited shared webhost. the ssh shell has another directory structure than the running webserver have. If I wish to run occ command from SSH I have to temporary change the datadirectory.

Kind of:
#!/bin/bash
occ config:system:set datadirectory --value="/temp1/temp2/" --update-only
occ …
occ config:system:set datadirectory --value="/orig1/orig2/" --update-only

How is it possible that the data structure is different? Are you using a different user for ssh than it is used for the web server? It might be necessary that you use sudo to run the occ-command because it should always be executed with the user access rights of the web servers user.

My Provider told me they chroot the webserver and SSH so it’s impossible to run an occ Command with the same user like the webserver do.
The problem could get solved easy if I change manually the datadirectory path in config.php.

Thats the point why I need a solution to run a script with another datadirectory. Until now I had a solution where I used a copy and replace of a whole config.php. But If I need to do changes in config.php, I have to do it also on a second one. Another problem is, that while this script is running, the Webserver has no access to datadirectory.

Afaik, running occ under a different user than the web servers user can cause problems with access rights etc. So I don’t know if you’re not causing other problems by bending the system due to provider specific restrictions.

Are you allowed to install your own apps? If yes, you can try to install the OCC Web app which allows you to run occ commands with the access rights of the web server. But in your case it wouldn’t most likely help either.

Yes, I’m allowed to install my own apps. It’s because My hoster is only a PHP webhoster. He doesn’t care what application I install. Also the Problem with the different user never appeared, I think this both user are equal in rights. I know OCC Web App but I’m not able to script with it.

At moment, I have a script which copy different config.php into nextcloud and after that runs the occ script. After ending the occ, it copy the correct config.php back to nextcloud. It’s not the best solution because while I work with occ the website shows an error. And I have to maintain two config.php

Better than nothing :wink: Maybe you should think about changing your web hoster instead of working around the restrictions.

Not sure if that restriction is that bad. I see it as a security feature. I could also say I should change nextcloud because of it’s restriction.

btw.
My Problem seems not be a problem of the datadirectory. I checked every thing. also my old script do not work.

Any Idea what this Error may also could force?

Sorry, no idea.

I have a solution:
at first, If I log into my shared host the Data structure is different from the on PHP can see If I use It with my Browser.
So I have to add a second config file which is able to detect if I come from occ or normally use nextcloud from Web.

because of a missing php.ini if I start it from ssh I have to run the PHP that way:
{PATH-TO-PHP} -c {PATH-TO-php.ini} {PATH-TO-OCC}