Migration Nextcloud to external disk: Error in command "sudo -u nextcloud php occ files:scan --all"

My YunoHost server

Hardware: Raspberry Pi 4 8GB
YunoHost version: 11.0.9.5
I have access to my server : Both through the webadmin page and through SSH
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

Description of my issue

Hello all,
I’ve been following the instructions on Nextcloud | Yunohost Documentation to migrate Nextcloud onto an external disk. I’m following solution II, case B.

The very last command doesn’t work:

root@biba:/var/www/nextcloud# sudo -u nextcloud php7.3 occ files:scan --all
sudo: php7.3: command not found

I checked in /usr/bin and saw that php and php7.4 are installed. But neither of them works:

root@biba:/var/www/nextcloud# sudo -u nextcloud php7.4 occ files:scan --all
An unhandled exception has been thrown:
OC\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
root@biba:/var/www/nextcloud# sudo -u nextcloud php occ files:scan --all
An unhandled exception has been thrown:
OC\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

I’m still somewhat of a beginner on Linux, particularly in such more complex server-related issues.
Can I perhaps just ignore that occ scan command altogether?

Thanks for your help,
Avenor

Can you try to apt install php7.4-apcu ?

@Avenor,
J’ai eu le même problème avec nextcloud après la migration, pourtant php7.4-apcu était installé.
Je l’ai corrigé avec un :

echo apc.enable_cli=1 >> /etc/php/7.4/cli/php.ini

1 Like

Thanks, Aleks and mib.

@Aleks, php7.4 was already installed:

root@biba:~# apt install php7.4-apcu
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
php7.4-apcu is already the newest version (5.1.21+4.0.11-8+0~20220625.32+debian11~1.gbpa7cde5).
php7.4-apcu set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

@mib, merci, after I ran your command echo apc.enable_... the original command (with “php7.4”) worked!

root@biba:/var/www/nextcloud# sudo -u nextcloud php7.4 occ files:scan --all
Starting scan for user 1 out of 1 (pingvin)
Exception during scan: opendir(/home/pingvin/.local/share): failed to open dir: Permission denied
#0 [internal function]: OCA\Files\Command\Scan->exceptionErrorHandler()
#1 /var/www/nextcloud/lib/private/Files/Storage/Local.php(135): opendir()
#2 /var/www/nextcloud/lib/private/Files/Storage/Common.php(879): OC\Files\Storage\Local->opendir()
#3 [internal function]: OC\Files\Storage\Common->getDirectoryContent()
#4 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(410): iterator_to_array()
#5 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(390): OC\Files\Cache\Scanner->handleChildren()
#6 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(393): OC\Files\Cache\Scanner->scanChildren()
#7 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(393): OC\Files\Cache\Scanner->scanChildren()
#8 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(342): OC\Files\Cache\Scanner->scanChildren()
#9 /var/www/nextcloud/lib/private/Files/Utils/Scanner.php(258): OC\Files\Cache\Scanner->scan()
#10 /var/www/nextcloud/apps/files/lib/Command/Scan.php(143): OC\Files\Utils\Scanner->scan()
#11 /var/www/nextcloud/apps/files/lib/Command/Scan.php(199): OCA\Files\Command\Scan->scanFiles()
#12 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute()
#13 /var/www/nextcloud/core/Command/Base.php(168): Symfony\Component\Console\Command\Command->run()
#14 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): OC\Core\Command\Base->run()
#15 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#16 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#17 /var/www/nextcloud/lib/private/Console/Application.php(209): Symfony\Component\Console\Application->run()
#18 /var/www/nextcloud/console.php(100): OC\Console\Application->run()
#19 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#20 {main}
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 24      | 33    | 00:00:02     |
+---------+-------+--------------+

Just one more question: The output of that command was all in red, is that normal? And what does this command actually accomplish (I’m a beginner :slight_smile: ? Thanks!

No, usually this means the computer is angry, especially when accompanied with a big stacktrace (= a somewhat long, multi-line output detailing where the crash occured)

In particular: Exception during scan: opendir(/home/pingvin/.local/share): failed to open dir: Permission denied

So let’s investigate permissions. Can you share the output of namei -l /home/pingvin/.local/share

Yes, here it is:

root@biba:/var/www/nextcloud# namei -l /home/pingvin/.local/share
f: /home/pingvin/.local/share
drwxr-xr-x root    root    /
drwxr-xr-x root    root    home
drwxrwxr-x pingvin pingvin pingvin
drwxr-xr-x pingvin pingvin .local
drwx------ pingvin pingvin share

Hmokay, not sure exactly what’s in that folder. Do you understand what it is about if you run ls -l /home/pingvin/.local/share ? (Maybe those are private files so be careful not to share the result too quickly)

Actually there is almost nothing in that directory, certainly nothing private:

root@biba:~/.local/share/nano# ls -l /home/pingvin/.local/share
total 4
drwx------ 2 pingvin pingvin 4096 Aug 16 14:28 nano

And that directory nano is empty.

All my Nextcloud data is on the external SSD which is mounted as /media/my_ssd. So shouldn’t these files on the SSD be scanned by Nextcloud instead? Somehow I don’t understand how this all works together.

To me it looks like somehow your /home folders are “mounted” (or made available, whatever) in Nextcloud, so it’s trying to scan these. And to be able to scan it, the nextcloud user needs permission to read the file

Anyway, it looks like it’s just some nano config. If you don’t mind so much about it, I would just rm -rf /home/pingvin/.local/share and re-try the scan

Oh, nice. I deleted that directory and the scan went through clean:

root@biba:/var/www/nextcloud# sudo -u nextcloud php7.4 occ files:scan --all
Starting scan for user 1 out of 1 (pingvin)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 12211   | 35892 | 00:05:37     |
+---------+-------+--------------+

But something looks weird in Nextcloud: The files indeed appear under /home/..., meaning I have made a mistake along the way.

I’ll redo this tomorrow with a fresh mind.

Thanks so much for your help, Aleks!

I redid the entire process of (re)installing the Nextcloud app on YunoHost and then migrating the Nextcloud directory from microSD to an external SSD again, following the documentation on Nextcloud | Yunohost Documentation.

This time everything worked flawlessly. I’m reporting here what I learned in the process, maybe it helps someone with similar problems in the future.

If you are on the new YunoHost version 11, the final commands need to be modified by replacing php7.3 with php7.4, which is the version installed on YunoHost v11 (Someone please update this in the documentation!) So you run:

cd /var/www/nextcloud
sudo -u nextcloud php7.4 occ files:scan --all

The output looks something like this:

Starting scan for user 1 out of 1 (pingvin)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 26      | 32    | 00:00:00     |
+---------+-------+--------------+

It can take a lot longer if you have a lot of data on your Nextcloud already. But this command is necessary to acquaint your Nextcloud with the new directories and files it is now responsible for. If you don’t run this command, you will not see files on Nextcloud in the browser interface that you have added yourself to the new Nextcloud directory on your external SSD in a terminal.

Contrary to the errors I reported earlier in this thread, this command scanned my new Nextcloud data on the external SSD without errors in my second attempt.

It was not necessary to first run the command echo apc.enable_cli=1 >> /etc/php/7.4/cli/php.ini which mib suggested above.

The reason why I had difficulties running this command with php7.4 in my first attempt described avoe, was related to the settings when I installed the Nextcloud app: In the YunoHost webadmin interface, from where you install apps, when installing the Nextcloud app, do not select the option “Access the user’s home folder from Nextcloud”. In my first attempt, I selected this settnig, and it messed up my directory structure, causing some files to have wrong permissions for the Nextcloud file scan to work.

Thanks again, Aleks and mib for helping me out.

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