Rebuild and repair the storage directory of Nextcloud

The Nextcloud on one server was migrated to another server yesterday. The stored files are no longer needed. In order to reduce the volume of the backup compressed package, they are deleted directly from the shell.

I wanted to migrate the page file and database directly. However, some episodes occurred when rebuilding the storage directory where uploaded files are stored. Here is a record of the process.

Operation process

After the program ontology and database are deployed, find Path of storage directory By default, it is saved in the Nextcloud installation directory, and this server is changed to another path.

You can find the path of the storage directory in the root directory of the website, config config.php, and create a new directory in the corresponding place. For example, here is: /www/nextdata
 Nextcloud storage path
When you visit the Nextcloud page, you will see the following prompt:

 Your data directory is invalid Ensure there is a file called ".ocdata" in the root of the data directory.

This seems to be a symbolic file, which is easy to solve. You can directly create an empty file with the same name in the storage directory, for example:

 touch .ocdata

When you visit the page again, you can log in normally, but the old file list is displayed. This is because all the file information is saved in the database. Nextcloud will not automatically update the list after manually deleting files from the outside. You need to use the command line tool to scan again.

Back to the terminal, run the command line tool of Nextcloud directly to rescan the file

 sudo -u www /usr/local/php/bin/php occ files:scan --all

At this time, a prompt will appear that the user directory of stev cannot be written (the user name in Nextcloud is called stev)

After a try, I found that there was a problem with the directory structure.

At this time, do three things:

First, under the storage directory, create a directory for all users in the "user name/files" structure, and create the directory as many times as there are users, for example:

 mkdir -p stev/files

Remember to go back to the external storage directory (/www/nextdata) and modify the permissions of the folder (change to the user and user group where the Web service is located)

 chown -R www:www *

Switch to the installation directory of Nextcloud again and execute the command to scan files:

 sudo -u www /usr/local/php/bin/php occ files:scan --all #If there is only one user, you can also use the following command Sudo - u www/usr/local/php/bin/php occ files: scan user name

Finally, back to the Nextcloud page, everything is normal

Start the OCC to report an error

The official command to start the occ tool is as follows:

 sudo -u www php occ files:scan -all

Because of different environment variable configurations, running directly as a www user may prompt that the command "php" cannot be found. One solution is to write the full path as above.
The location of PHP on different servers may not be the same. You can use whereis php Command found.

Unless otherwise specified, the content of this website is Salted fish pioneer Original, can be quoted freely, but please indicate the source and link.
https://xyuxf.com/archives/2136
Welcome to follow Salted fish pioneer (WeChat official account: xyuxf), get dry goods push
THE END
share
QR code
< <Previous
Next>>
Article Contents
close
catalog