Nc-datadir command does not behave like expected - new location misplaced

I tried to move my datadir (and later planned dbdir) to a new and mounted btrfs partition that was connected over USB on my Odroid-HC2. So I used datadir change command in my webUI in my at that time working cloud. The change was from:
/media/USBdrive/ncdata to
/media/NewDrive/ncdata

During movement process I could read something like “creating new subvolume”. This command moves all my data, not to the expected folder, but to a subfolder:
/media/NewDrive/ncdata/data
I found this very strange. Process aborts and nextcloud still thinks that my datadir is at the old position on USBDrive. But I now don’t know wether the database links are already moved to whatever new folder or not. Nextcloud is now down, of course.
How can I repair this instance? (I must repair it, because nc-restore or my last full backup also aborts with “permission denied” after some time.)

Found several entries here in the forum, but none of them had problems with such a creation of a sub directory.

it failed how? what is the output?

I new that this question will come :slight_smile: . Unfortunately, I clicked it away to check which folder I entered.
How can I find the log file?
Alternatively, I can use the MV command to push the data to the old position, and then redo NC-datadir (in a hope that the Cloud will then work again ).

/var/log/ncp.log

Thank you @OliverV. Found it.

The relevant lines are:

[ nc-datadir ] (Sat Dec 11 00:53:35 CET 2021)
Nextcloud is in maintenance mode - no apps have been loaded

Maintenance mode already enabled
moving data directory from /media/USBdrive/ncdata to /media/NewDrive/ncdata...
BTRFS filesystem detected
Create subvolume '/media/NewDrive/ncdata'

[ nc-previews-auto ]
mv: cannot remove '/media/USBdrive/ncdata': Operation not permitted

[ nc-update-nc-apps-auto ]
checking for updates...
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}

[ nc-previews-auto ]
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}[ nc-update-nc-apps-auto ]
checking for updates...
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:168
Stack trace:
#0 /var/www/nextcloud/console.php(99): 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...')
#2 {main}

I can see nothing in this log that gives a hint for the folder “/media/NewDrive/ncdata/data” where my data files were moved to. Does anyone have a hint for me?
Of course, the system cannot find dthe file “.ocdata” in “/media/NewDrive/ncdata”, because it is in the subfolder “/media/NewDrive/ncdata/data”, see:

root@nextcloudpi:/media/NewDrive/ncdata/data# ls -a -l
total 1635748
drwxr-x— 1 www-data www-data 370 Jul 5 19:41 .
drwxr-xr-x 1 root root 8 Dec 11 00:53 …
-rw-r–r-- 1 www-data www-data 542 Nov 20 21:40 .htaccess
-rw-r–r-- 1 www-data www-data 0 Nov 20 21:40 .ocdata
drwxrwxr-x 1 www-data www-data 320 Jul 12 2019 .opcache
drwxr-xr-x 1 www-data www-data 0 Jul 5 19:41 Testaccount
drwxr-xr-x 1 www-data www-data 146 Dec 10 2020 appdata_ocblaxfwv5b6
drwxr-xr-x 1 www-data www-data 26 Aug 18 16:56 files_external
-rw-r–r-- 1 www-data www-data 0 Nov 20 21:40 index.html
drwxr-xr-x 1 www-data www-data 90 Nov 25 2020 manglbergers
drwxr-xr-x 1 www-data www-data 90 Jan 12 2019 michael
drwxr-xr-x 1 www-data www-data 20 Jan 11 2019 ncp
drwxr-xr-x 1 www-data www-data 1866 Oct 1 23:13 ncp-update-backups
drwxr-xr-x 1 www-data www-data 22 Dec 1 2018 news
-rw-r----- 1 www-data www-data 1792358 Dec 11 00:44 nextcloud.log
-rw-r----- 1 www-data www-data 1673183573 Mar 15 2021 nextcloud.log.1
drwxrwxr-x 1 www-data www-data 0 Jul 25 2019 tmp
drwxr-xr-x 1 www-data www-data 74 Jan 16 2021 updater-ocblaxfwv5b6
-rw-r–r-- 1 www-data www-data 18914 Jan 16 2021 updater.log

looks like the process was interrupted? did you ctrl-c or similar? if your files are moved to the new location, then you can edit /var/www/nextcloud/config.php and point datadir to the right direction, I think that you aborted the process before it finalized though

Thank you @nachoparker.
After editing the /var/www/nextcloud/config/config.php so that datadirectory parameter pointed to the correct path it worked again.
So for my feeling I did not press ctrl-c or similar. But hey, it works :grinning: . They result says you are right.

I did all this to replace my small ssd with new bigger one.
After I had my working system back, I did some testing and found out that I had problems, when my datadirectory points to this automount forwarding path like /media/USBdrive/...... I changed it to the alternative working path like /media/myCloudDrive/ (or whatever it is on your machine). This prevents my system from running into problems with path names, because every time I plugged in the new ssd and restart system, then my existing drive was put to /USBdrive1/ and the new drive was /USBdrive/ from then on. The datadir and dbdatadir was not found in this case, of course.
Just want to mention. Don’t know maybe this can help other people who want to do the same like me.