Nextcloud install broke, can't recover data that was on USB SSD

Nextcloud version: 23
Operating system and version: debian buster
Apache or nginx version _: 2.4.52
PHP version (eg, 7.4): 7.4

I updated my nextcloud pi admin password and ssh password at the same time and the system didn’t update to my password specified, because I couldn’t access anything at that point. I tried to update nextcloud and got an error during so, which resulted in my nc instance being completely broken. I couldn’t diagnose the problem from logs or anything and couldn’t access the protected folders I just wiped the SD card and re-installed.

Now I am un-sure how to import the data from the external SSD into the new nc instance. Could someone please help me out?

During install the nextcloud pi wizard detected the SSD and I skipped formatting and moved the data dir to the SSD. But even when browsing to it in the terminal I cannot access the data folder to get the old files off of it.

I am kinda panicking, I had lots of important files on there D:

no need to panic there is lots of help here.

So you did NOT format the SSD ? if no the files should still be there.

Did you have encryption enabled? if no there is no worries.
What do you mean by

browsing to it in the terminal

Do you mean shell access. if so how are your permissions set.

A rescan of the files can help: sudo -u www-data php console.php files:scan --all

Running the command you gave results in: Could not open input file: console.php

I am using nextcloud pi if that makes a difference.

And yes, I meant shell access. I saw that I could run sudo -i and I am able to access the SSD data. It now has two partitions on it, USBdrive and myCloudDrive, which my old data resides on myCloudDrive and I can see that the ~70gb of data is still on the partition. BUT when I browse to it in the shell, it only shows the default files from a nextcloud install inside the ncdata folder. I’m very confused. I’ve even tried installing a brtfs driver on windows to manually pull the data off but it won’t read either.

edit: Thank you SO much for the reply!

sudo -i gives you interactive shell access to root you should’nt use it unless your 100% sure what your doing. besides you still need to use sudo as the command should be run as -u ( user ) www-data because that’s you apache user and the command should be run from the nextcloud installation folder where the file console.php is.

As I understand you have both Nextcloud ( installation ) and your DATA files ( personal files that you uploaded) on the SSD and they both reside inside the Folder /myCloudDrive and there is another partition mounted on /USBdrive which is empty.

the command posted earlier should be run inside the Nextcloud installation folder. mostly it resides in /var/www/nextcloud but as I read yours might be in /myCloudDrive.

you can look inside /etc/apache2/sites-enabled/ there should be a file that has your cloud configuration for apache. do cat your-cloud-file.conf and see where DocumentRoot points to

My nextcloud install is located in /var/www/nextcloud, but I cannot cd into it without first running sudo -i. How do I switch myself to the www-data user so I can run that command inside the nextcloud folder?

you cannot change to user www-data as it is a systemuser ( learn here security - Does www-data user need a real shell? - Server Fault )
you can check which groups you are in with the command ‘groups’ if the group www-data is not there
you should add yourself to the group www-data

sudo usermod -aG www-data YOURUSERNAME

logout and back in to take effect and check with groups again if it’s there
if you still can’t get in /var/www/nextcloud there is permission setting wrong and you should do

sudo chmod 750 /var/www/nextcloud ( learn about chmod https://www.makeuseof.com/tag/chmod-command-linux-file-permissions/ )

edit:
never simply run commands from posts they may destroy your system learn what your doing.

Okay, I managed to get into the directory and run the command but it only output the default nc user files:

Starting scan for user 1 out of 1 (ncp)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 6       | 28    | 00:00:00     |
+---------+-------+--------------+

I am so confused. I can see the space is still taken on the drive from a partition manager, but I cannot see the files no matter what I try. I am about to try a linux live USB and see if linux can read the files.

in /var/www/nextcloud/config/config.php where does it point to your data directory

cat config.php | grep data

'datadirectory' => '/media/myCloudDrive/ncdata/data',
  'tempdirectory' => '/media/myCloudDrive/ncdata/data/tmp',
  'logfile' => '/media/myCloudDrive/ncdata/data/nextcloud.log',

do you know any file name you are trying to access like important.docx or so you can then search the drive for it’s existence.

do cd /media/myCloudDrive/
there you can search like find -name important.docx or from any directory do find /media/myCloudDrive -name important.docx

edit:
sorry type should be -name

Okay! Yes! It is seeing my files!

 find /media/myCloudDrive -type f -name *.pdf
find: ‘/media/myCloudDrive/ncdata-03-08-22.1646799562/.opcache/a8644594cdadb84c26b9bafb116c6110’: Permission denied
find: ‘/media/myCloudDrive/ncdata-03-08-22.1646799562/.opcache/3a6e0aa1637c49097789b85ae251536d’: Permission denied
find: ‘/media/myCloudDrive/ncdata-03-08-22.1646799562/.opcache/263996ba74a5d4d618f167a7007ec408’: Permission denied
find: ‘/media/myCloudDrive/ncdata-03-08-22.1646799562/.opcache/c315577b0aa05ee4d8d7706db2a12436’: Permission denied
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/Big Mikes/big-mikes.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/JMS/jms-grill-alternative.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/JMS/jms-menu.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/Power/sweetstakes-sign.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/Red Oak Grocery & Grill/Slide Images/red-oak-menu-reduced.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/Red Oak Grocery & Grill/Slide Images/red-oak-menu.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/Red Oak Grocery & Grill/red-oak-menu-compressed.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/ncp/files/Clients/Red Oak Grocery & Grill/red-oak-menu.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/Muhammed/files/Documents/Nextcloud flyer.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/Muhammed/files/Reasons to use Nextcloud.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/Muhammed/files/Nextcloud Manual.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/__groupfolders/1/Dari Guaranty.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/__groupfolders/1/Tax Exemption Form.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/__groupfolders/1/December 2021 Pricelist (Dari) - pricelsit-12-3-21.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/__groupfolders/1/ACH Debit Agreement.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/__groupfolders/1/03.01.22.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/__groupfolders/1/Sales Pages/03.01.22.pdf
/media/myCloudDrive/ncdata-03-08-22.1646799562/Mohammad/files_trashbin/files/Documents.d1637276685/Nextcloud flyer.pdf
find: ‘/media/myCloudDrive/ncdata-03-08-22.1646800350/data/.opcache/8717fb3e34d238cda5dc6c342cf24d1d’: Permission denied
find: ‘/media/myCloudDrive/ncdata-03-08-22.1646800350/data/.opcache/20e0d9a8fd2ffc97798aeb7815e75303’: Permission denied
/media/myCloudDrive/ncdata-03-08-22.1646800350/data/ncp/files/Reasons to use Nextcloud.pdf
/media/myCloudDrive/ncdata-03-08-22.1646800350/data/ncp/files/Nextcloud Manual.pdf
/media/myCloudDrive/ncdata-03-08-22.1646800350/data/ncp/files/Documents/Nextcloud flyer.pdf
find: ‘/media/myCloudDrive/ncdata/data/.opcache/8717fb3e34d238cda5dc6c342cf24d1d’: Permission denied
find: ‘/media/myCloudDrive/ncdata/data/.opcache/20e0d9a8fd2ffc97798aeb7815e75303’: Permission denied
/media/myCloudDrive/ncdata/data/ncp/files/Reasons to use Nextcloud.pdf
/media/myCloudDrive/ncdata/data/ncp/files/Nextcloud Manual.pdf
/media/myCloudDrive/ncdata/data/ncp/files/Documents/Nextcloud flyer.pdf

Question now is why isn’t it seeing them when scanning? Maybe because they’re created with the old nextcloud install’s account?

seems like you have a user called ncp and mohammad but your datadirectory is pointing to ```
/media/myCloudDrive/ncdata
while your old NC files are actualy in /media/myCloudDrive/ncdata-03-08-22.1646799562

hmm how should we solve this there are multiple ways you could change your /var/www/nextcloud/config/config.php and point your datadirectory to /media/myCloudDrive/ncdata-03-08-22.1646799562 or you can mv all files to your new installation datadirectory which ever you choose.

if you need help to move them let me know

rename the current ncdata to ncdata_old and then rename ncdata-03-08-22.1646800350 to ncdata

like sudo mv ncdata ncdata_old
and sudo mv 'ncdata-03-08-22.1646800350' ncdata

when you moved them or changed your config.php datadirectory do a scan of all files again in /var/www/nextcloud with sudo -u www-data php console.php files:scan --all

edit:
mv solution included forgot brackets for - and .

I think I’m just going to use the datadir method as that sounds the easiest. I’ll report back how it goes.

And thank you so SO much for helping me resolve this man! I truly appreciate it.

I’m also an idiot though, the whole time I thought the data dirs were just files :face_with_spiral_eyes:

your very welcome I like to problem solve and come with a happy solution

1 Like

Okay, I renamed the folders as suggested and tried running the scan, but got the following output:

 sudo -u www-data php console.php files:scan --all
{"reqId":"37g4av3GWXUl8gZDcKUc","level":2,"time":"2022-03-09T18:32:23+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"","url":"--","message":"Temporary directory /media/myCloudDrive/ncdata/data/tmp is not present or writable","userAgent":"--","version":"23.0.2.1"}
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:164
Stack trace:
#0 /var/www/nextcloud/console.php(98): OC\Console\Application->loadCommands()

appears it’s not a valid directory?

i’m not sure about this tmp directory I don’t have it but does this directory exsist

/media/myCloudDrive/ncdata/data/tmp

if not create it.

then in /media/myCloudDrive/ncdata/ do

sudo -u www-data touch .ocdata

try scan again

Tried that, same error oddly:

sewdohe@nextcloudpi:/media/myCloudDrive/ncdata/ncp $ cd /media/myCloudDrive/ncdata/data/tmp
-bash: cd: /media/myCloudDrive/ncdata/data/tmp: No such file or directory
sewdohe@nextcloudpi:/media/myCloudDrive/ncdata/ncp $ mkdir /media/myCloudDrive/ncdata/data/tmp
sewdohe@nextcloudpi:/media/myCloudDrive/ncdata/ncp $ cd ..
sewdohe@nextcloudpi:/media/myCloudDrive/ncdata $ sudo -u www-data touch .ocdata
sewdohe@nextcloudpi:/media/myCloudDrive/ncdata $ cd /var/www/nextcloud/
sewdohe@nextcloudpi:/var/www/nextcloud $ sudo -u www-data php console.php files:scan --all
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:164
Stack trace:
#0 /var/www/nextcloud/console.php(98): OC\Console\Application->loadCommands()

edit:
I made the .ocdata file in /media/myCloudDrive/ncdata/data and re-ran the scan and got this:

Starting scan for user 1 out of 1 (ncp)
Home storage for user ncp not writable
Make sure you're running the scan command only as the user the web server runs as
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 0       | 0     | 00:00:00     |
+---------+-------+--------------+

edit again:
tried to run nc-fix-permissions and it gave me this error:

fixing permissions in /media/myCloudDrive/ncdata/data... chown: cannot access '/media/myCloudDrive/ncdata/data/*/files': No such file or directory
chmod: cannot access '/media/myCloudDrive/ncdata/data/*/files': No such file or directory
done

yeah you have permission problem just do it manualy

in /media/myCloudDrive/ncdata do

sudo find -type f -print0 | sudo xargs -0 chmod 0640
sudo find -type d -print0 | sudo xargs -0 chmod 0750
sudo chown -R www-data:www-data /media/myCloudDrive/ncdata

hmm yes your data directory is
/media/myCloudDrive/ncdata/data
you should remove the /data part in your config.php
so it reflects /media/myCloudDrive/ncdata

1 Like

Wooohooo!!! It worked that time!!!

 sudo -u www-data php console.php files:scan --all
Starting scan for user 1 out of 1 (ncp)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 431     | 6356  | 00:00:24     |
+---------+-------+--------------+

Thank you SO much buddy! You’re a MVP for that!

You by any chance have a cashapp so I could send you a little thanks?! You helped me so much through that!