Migrating files to Nextcloud, occ scan failes, could be permissions [solved]

:uk: :us: :ireland:

My YunoHost server

Hardware: Old laptop or computer
YunoHost version: 11.2.5
I have access to my server : Through SSH | through the webadmin | direct access via keyboard / screen
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

Description of my issue

I’m trying to move files from an external hard-drive into my nextcloud.

I managed to ssh into my server and mount my hard-drive than copied a couple of file into /home/yunohost.multimedia/user/share/ and scan them with

sudo -u nextcloud php8.1 --define apc.enable_cli=1 /var/www/nextcloud/occ files:scan --all

to test the process. Everything was working fine.

Than I copied a larger folder into /home/user/share without realizing it wasn’t the same place (to many “Share” folders got me confused). Scanning wouldn’t make my files appear in Nextcloud and a discussion with a friend got me thinking it could be because of permission so I used

sudo chmod 664 -R

on the directory.
After some more research I understood what I did but now I’ve got this error when trying to scan my files

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:140
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1531): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1029): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/nextcloud/lib/private/DB/Connection.php(262): Doctrine\DBAL\Connection->executeQuery()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery()
#4 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/nextcloud/lib/private/AppConfig.php(418): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/nextcloud/lib/private/AppConfig.php(184): OC\AppConfig->loadConfigValues()
#7 /var/www/nextcloud/lib/private/AppConfig.php(374): OC\AppConfig->getApps()
#8 /var/www/nextcloud/lib/private/legacy/OC_App.php(803): OC\AppConfig->getValues()
#9 /var/www/nextcloud/lib/private/Server.php(736): OC_App::getAppVersions()
#10 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}()
#11 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#12 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#13 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#14 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#15 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(193): OC\AppFramework\Utility\SimpleContainer->get()
#16 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#17 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#18 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#19 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#20 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#21 /var/www/nextcloud/lib/private/Server.php(1130): OC\AppFramework\Utility\SimpleContainer->get()
#22 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}()
#23 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#24 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#25 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#26 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#27 /var/www/nextcloud/lib/private/Server.php(2088): OC\AppFramework\Utility\SimpleContainer->get()
#28 /var/www/nextcloud/lib/private/Files/View.php(107): OC\Server->getLockingProvider()
#29 /var/www/nextcloud/lib/private/Server.php(470): OC\Files\View->__construct()
#30 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}()
#31 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#32 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#33 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#34 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#35 /var/www/nextcloud/lib/private/Server.php(1490): OC\AppFramework\Utility\SimpleContainer->get()
#36 /var/www/nextcloud/lib/base.php(635): OC\Server->boot()
#37 /var/www/nextcloud/lib/base.php(1196): OC::init()
#38 /var/www/nextcloud/console.php(48): require_once('...')
#39 /var/www/nextcloud/occ(11): require_once('...')
#40 {main}

I have deleted the copied folder but scanning still doesn’t work.
This discussion makes me think this is a permission issue but I don’t know which : Can't restore Nextcloud

Worst case scenario, I could re-install but I’m new to this and would like to learn to fix it if possible.

Many thanks in advance for your time.


:fr: :belgium:

Mon serveur YunoHost

Matériel: Vieil ordinateur
Version de YunoHost: 11.2.5
J’ai accès à mon serveur : En SSH | Par la webadmin | En direct avec un clavier/écran
Êtes-vous dans un contexte particulier ou avez-vous effectué des modificiations particulières sur votre instance ? : non

Description du problème

Je suis en train de déplacer des fichiers depuis un disque dur externe vers mon Nextcloud.

J’ai réussi à me connecter en SSH à mon serveur et à monter mon disque dur, puis j’ai copié quelques fichiers dans /home/yunohost.multimedia/user/share/ et les ai scannés avec

text

sudo -u nextcloud php8.1 --define apc.enable_cli=1 /var/www/nextcloud/occ files:scan --all

pour tester le processus. Tout fonctionnait bien.

Ensuite, j’ai copié un dossier plus volumineux dans /home/user/share sans réaliser que ce n’était pas le même endroit (trop de dossiers “Share” m’ont induit en confusion). Le scan n’a pas fait apparaître mes fichiers dans Nextcloud, et une discussion avec un ami m’a fait penser que cela pourrait être dû à des problèmes de permissions. J’ai donc utilisé

text

sudo chmod 664 -R

sur le dossier. Après quelques recherches supplémentaires, j’ai compris ce que j’avais fait, mais maintenant j’ai cette erreur lorsque j’essaie de scanner mes fichiers

text

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:140
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1531): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1029): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/nextcloud/lib/private/DB/Connection.php(262): Doctrine\DBAL\Connection->executeQuery()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery()
#4 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/nextcloud/lib/private/AppConfig.php(418): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/nextcloud/lib/private/AppConfig.php(184): OC\AppConfig->loadConfigValues()
#7 /var/www/nextcloud/lib/private/AppConfig.php(374): OC\AppConfig->getApps()
#8 /var/www/nextcloud/lib/private/legacy/OC_App.php(803): OC\AppConfig->getValues()
#9 /var/www/nextcloud/lib/private/Server.php(736): OC_App::getAppVersions()
#10 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}()
#11 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#12 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#13 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#14 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#15 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(193): OC\AppFramework\Utility\SimpleContainer->get()
#16 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#17 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#18 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#19 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#20 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#21 /var/www/nextcloud/lib/private/Server.php(1130): OC\AppFramework\Utility\SimpleContainer->get()
#22 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}()
#23 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#24 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#25 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#26 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#27 /var/www/nextcloud/lib/private/Server.php(2088): OC\AppFramework\Utility\SimpleContainer->get()
#28 /var/www/nextcloud/lib/private/Files/View.php(107): OC\Server->getLockingProvider()
#29 /var/www/nextcloud/lib/private/Server.php(470): OC\Files\View->__construct()
#30 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}()
#31 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#32 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet()
#33 /var/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query()
#34 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query()
#35 /var/www/nextcloud/lib/private/Server.php(1490): OC\AppFramework\Utility\SimpleContainer->get()
#36 /var/www/nextcloud/lib/base.php(635): OC\Server->boot()
#37 /var/www/nextcloud/lib/base.php(1196): OC::init()
#38 /var/www/nextcloud/console.php(48): require_once('...')
#39 /var/www/nextcloud/occ(11): require_once('...')
#40 {main}

J’ai supprimé le dossier copié, mais le scan ne fonctionne toujours pas.
Cette discussion me fait penser qu’il s’agit d’un problème de permissions, mais je ne sais pas lesquel : Can't restore Nextcloud

Dans le pire des cas, je pourrais réinstaller, mais étant novice, j’aimerais apprendre à résoudre le problème si possible.

Merci d’avance pour votre temps.

Hi eamonn,

Welcome to the forums!

The permissions on Yunohost are ‘conventional’ permissions as well as ACL. Let me look up another post about ACLs, but first: my Yunohost does not have any /home/user/share directory. Also no /home/wbk/share (or for any other user).

As which user did you perform the action?

Any Linux (any *nix, I guess) does have a /usr/share/ directory.

Very good! How familiar are you in general with Linux? If you say “I have no clue”, the troubleshooting will go another way than when you say “I mostly know my way around, I’m just stuck at this point” :wink:

That is the right attitude :slight_smile:

Hi wbk,

Thanks, it’s great to have a community to reach out to.

I performed the scans as root (as in sudo su, it wouldn’t work otherwise) and the rest as a normal user (with admin access for the install), using sudo when required.

Your remark about the home folder got confused a little. Looking at it more closely, it seems that the user folder in my /home/user is the same one as /home/yunohost.multimedia/user (I guess one is a link to the other).

I know my way around Linux but I am not a power user. I can read doc pages and use command line but I don’t understand (yet) all the ins and outs of running a server (or any of the complex IT stuff for that matter).

Many thanks in advance for your time, this is much appreciated :slight_smile:

Hi eamonn,

It turns out I was also connecting to Nextcloud that time, have a look at Access nextcloud via SSHFS - #9 by wbk for the configuration of permissions I used.

Paraphrasing,

So, on which directories did you run chmod 664, and was it necessary to use sudo in those cases? My hunch is that some file needs to be executed to connect to the database, but 664 does not allow execution, hence Failed to connect to the database:

Is your Nextcloud installation itself still functional? Can you scan other folders? How long has the system been installed and used?

Depending on the situation, I could run an ls -hals on my copy of the directory that has trouble on your side so you can compare them. On the other hand, if nothing has been installed or uploaded, pending this issue, before starting to use the system, the amount of troubleshooting (and learning :wink: ) might not be in balance with re-installing.

By the way: the fact that you needed to run occ files:scan implies that you did not connect to Nextcloud via WebDAV. Did you have a reason for using a direct filesystem copy, did the WebDAV connection not work?

Hi wbk,

Thanks for your time.

I think your case is a bit different than mine. I physically connected a usb hard drive to my server. The reason I didn’t transfer the data through webdav is because I have 4Tb of data to transfer so I was hoping to let it run in the background.

My server is a couple months old, I had help for the install. So far I took it slow in order to test things and move progressively. I tested a couple of apps but mostly Nextcloud, Calibre, Jellyfin, InvoiceNinja (and I was hoping to also have a Matrix server and maybe rocketchat). Migrating my data was the next step in my process.

The command I ran was

sudo chmod 664 -R -v /home/[user]/Share/Music/[The folder I copied from external HD]

After that, I guess I was a bit lost (and a bit panicked) and ran several commands (after reading on various forums)

chown -R www-data:www-data nextcloud

than

chown -R www-data:www-data Multimedia

than

chown -R nextcloud:nexcloud .

I might have run those as root or sudo.
Full disclaimer, I knew I shouldn’t copy-past command lines mindlessly, now I know why… And I feel pretty silly.

I can still import files into my nextcloud from the webinterface but I cannot run an occ scan on other folders. Other than that, it seems that everything is working as it should (SNAFU).

Again, many many thanks for taking the time to share your experience, it truly is heart warming :smiley:

Hi eamonn,

You got quite a detailed log, handy :slight_smile:

You list relative directories in the commands, they are all subdirectories of /home, are they not? I mean, you didn’t alter any permissions on the actual Nextcloud installation in /var/www, so these can’t be messed up in some way?

I found the share directory on my Yunohost, it is one subdir deeper at /home/[user]/Multimedia/Share, indeed a symlink to /home/yunohost.multimedia/share . This is how my listing looks like.

# ls /home/yunohost.multimedia/share/ -halsR
/home/yunohost.multimedia/share/:
total 24K
4.0K drwxrwxr-x+  6 root root 4.0K Dec 25  2019 .
4.0K drwxrwxr-x+ 22 root root 4.0K Oct 14 00:02 ..
4.0K drwxrwxr-x+  2 root root 4.0K Dec 25  2019 eBook
4.0K drwxrwxr-x+  2 root root 4.0K Dec 25  2019 Music
4.0K drwxrwxr-x+  2 root root 4.0K Dec 25  2019 Picture
4.0K drwxrwxr-x+  2 root root 4.0K Dec 25  2019 Video

Notice the ±signs behind the permissions, indicating ACL’s. When querying those for Music, it shows:

# getfacl /home/yunohost.multimedia/share/Music/
getfacl: Removing leading '/' from absolute path names
# file: home/yunohost.multimedia/share/Music/
# owner: root
# group: root
user::rwx
group::rwx
group:multimedia:rwx
mask::rwx
other::r-x
default:user::rwx
default:group::rwx
default:group:multimedia:rwx
default:mask::rwx
default:other::r-x

Are those permissions still in place on your side?

I still can’t imagine how changing ownership here prevents (access to a file needed for) connecting to the database. Perhaps the actual error is something else, and then interpreted by occ as ‘Well, I tried, but no access to the database’.

Over on the Nexctloud-forum, someone got the same symptoms in a slightly different situation, they resolved the issue by calling occ from another location, OCC has Database problem: "Failed to connect to the database" - #11 by Mannshoch - ℹ️ Support - Nextcloud community

Because my occ does not misbehave, I can not pin down whether it got a helpful hint in this case, but you might give it a try.

Hi wbk,

All the directories I mentioned should be (have been) sub-directories of /home/

Regarding permissions, they seem a bit different than yours :

ls /home/yunohost.multimedia/share/ -hals
total 4.0K
   0 drwxrwxr-x+  6 nextcloud nextcloud   80 Jun 18 21:05 .
   0 drwxrwxr-x+  6 root      root        83 Oct 19 11:37 ..
4.0K drwxrwxr-x+ 11 nextcloud nextcloud 4.0K Oct  2 14:30 eBook
   0 drwxrwxr-x+  3 nextcloud nextcloud   67 Oct 19 10:30 Music
   0 drwxrwxr-x+  2 nextcloud nextcloud    6 Jun 18 21:05 Picture
   0 drwxrwxr-x+  4 nextcloud nextcloud   53 Aug 11 19:08 Video

and

getfacl /home/yunohost.multimedia/share/Music/
getfacl: Removing leading '/' from absolute path names
# file: home/yunohost.multimedia/share/Music/
# owner: nextcloud
# group: nextcloud
user::rwx
group::rwx
group:multimedia:rwx
mask::rwx
other::r-x
default:user::rwx
default:group::rwx
default:group:multimedia:rwx
default:mask::rwx
default:other::r-x

I don’t understand all the discussion you linked to but I installed the occ app and lo and behold, I was able to scan my files again ! I’m still concerned about having a non-working thingy on my server but I guess I can at least keep on moving forward for now.

Thank you so very very much for your help !
Should I mark this issue as “fixed” somehow (changing the header for the thread or something) ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.