Rescan files on shared server

My database seems inconsitent, files present on sftp are not synchronized and missing in the web-interface. I probably should start a rescan (occ command) in the cli.
But …

  • I use Onwcloud 10.0.0.9 on a shared server (infomaniak.com)
  • I do not have access to ssh or command line.
  • I can use sftp and mysqladmin.
  • There is also a cron service enabling me to run cron.php in regular intervals.

Is there a way to trigger a file scan to get the database consistent with the existing files?

Thank you
Fabio

Hey,

maybe you can run the occ command to rescan the files via cron the same way you’re running it for the cron.php?

1 Like

Hi Tom
Thank you for your interest. My hoster offers a kind of webcron, allowing to launch php-sides with a command like “www.mysite.xy/owncloud/cron.php”. He probably blocks attempt to use cli-commands. I have tried, but I could not figure out a syntax working with “occ” instead of “cron.php”. To my knowledge, “occ” itself launches the command “console.php”. But again, I could not figure out a syntax to trigger the desiered function “files:scan --all”
Thank you Fabio

Very interesting idea! Thanks so far.

Hey,

maybe its possible to somehow call external commands like occ from a php file which is in turn called by the webcron?

But from your description it looks like you’re using ownCloud in a more advanced way, maybe switching to an hosting plan which gives you more control via SSH might be another alternative?

Nice Idea. Worth a try. And here, what I have tried:

<?php $output = `./occ files:scan --all`; echo "
$output
"; ?>

In a file called rescan.php
And now, what I got - not surprisingly:
“shell_exec() has been disabled for security reasons …”

But: since “occ” calls console.php, it should be possible to trigger the scan from a php-file. But, which command, how to use it?

Fabio

There exists a file:
owncloud/apps/files/lib/BackgroundJob/ScanFiles.php
What is probably more or less what I need, but it primarilly exports a class ScanFiles.
So it seems possible to generate a background job (re-)scanning files, but… how to trigger it?
Thanks - Fabio

There also seems to exist a function “filescan()”;
But I dont know where to find it, and how to import and call it.
Fabio

Finally, after having installed a reliable cron-service, the database repaired itself.
Nevertheless, it is regretable that the administrator can not launch a complet database rescan from the administration console.
Fabio

2 Likes

Here I fully agree with you. Could you please give more details on how your solution looks like? You can PM me if you don’t want share with public.

Hi Alfred
The cronjob just starts the cron.php every 15 min. scan.php is a backgroudjob that ist launched by corn.php by default. It does not scan the entire filesystem at once (may be due to script execution time limits), but after hours and days everithing should be scanned if the users aren’t to busy…
The (web)cronjob is launched by my hoster, who offers the possibility to set up this kind of function.
This may also be done by an external webcron service (see documentation).
Fabio

1 Like

Thanks for this description! Sounds very interesting. I’ll have a deeper look inside later.

Hi I found this thread because I’m experiencing the same problem.
And since I am also on shared hosting at Infomaniak I would really like to know how exactly how you @fabio solved it. Was it with cron.php? Did you eventually find the right syntax?
Thanks in advance!

If you’re using anything newer than 10.3.1 it should be /path/to/php -f /path/to/occ system:cron.
cron.php does not exist anymore.

1 Like

Thanks @eneubauer for your quick reply!

Yes I’m on 10.5. Sorry but I don’t understand your answer. Where can I write that input, and then how can I specify what commands cron should run? …sorry if I sound trivial but I’m not that knowledgeable!

I’ll try to explain with more details what it looks like from my point of view:
Infomaniak -my web hosting provider- offers to run scheduled jobs by calling files on the server. I can’t simply shedule the command itself, it has to be in a file. Which I assumed would be fine with a ‘cron.php’ file that can be called regularly by the server.

That part works fine, but just like @fabio was experiencing, I’m not able to find a correct syntax to run occ files:scan command.

In the meantime I ran it manually by CLI. It did scan and update the dropbox folders, but since it took 30 minutes I guess it would be best to be able to specify the dropbox folder to be scanned instead of my whole owncloud directory.

If you have to contact your providers support team to install the cron job anyway, you could try the following:

  • find out where PHP is by running in a shell command -v php, if you can’t do that, the support team should know.
  • You should know where you installed your ownCloud, so you should know the path to your occ file in the ownCloud web root
  • get in touch with support telling them to run the cron job /path/to/php -f /path/to/occ system:cron with correctly filled out paths as the user the website is being executed as.

Have a look here:
https://doc.owncloud.com/server/admin_manual/configuration/server/occ_command.html#the-filesscan-command

What are you actually trying to achieve? And what is not working?

EDIT: As you see a lot has changed since two years ago. Even though you are using the same host, perhaps it would be better to open a new topic…

1 Like

Thanks for your efforts in helping me! :sweat_smile:

What are you actually trying to achieve? And what is not working?

I would like a cron job to periodically rescan my linked dropbox directory because the sync does not work automatically. Since this was the topic raised in this thread I simply followed up.

I managed to run the following shell command php occ system:cron -p and it seems to work fine, even though I suspect it only does part of the job each time it is called (that’s what @fabio pointed out). But I actually don’t quite get what it does. Output is different each time I run it. Or maybe it is running in the background and simply shows where it is at.

If I summarize:

  1. I can manually rescan (only the dropbox directory) with shell command $ php occ files:scan --path="/jeremie/files/DropboxJS" (very slow, 1 file/sec but I see this is an issue on files_external_dropbox’s github page)
  2. I can manually run $ php occ system:cron
  3. My provider has a simple interface to setup cron jobs that can only run files (crontab not allowed)

So now I’m left with these questions:

  • How to write a php file that would simply run either occ system:cron or directly occ files:scan ...
  • How/where can one edit what system:cron does?
  • And last but not least: Is there a better way to keep dropbox-linked directories synced in OC?

Again, thanks for your help!

So the cronjob is there to execute the jobs that are defined in the jobs table, usually it is called oc_jobs.
There are some occ commands around this called background:queue, please read the documentation: https://doc.owncloud.com/server/admin_manual/configuration/server/occ_command.html#managing-background-jobs

I have no clue how you would create a custom background for a files:scan on an external storage, perhaps @jvillafanez knows more?

1 Like

You can’t. They’re provided by the apps. As said, there are some occ commands to manipulate the background queue, but that’s only what you get.

Note that, these days, the recommendation is to use occ commands and use cron / crontab (or any cron-like service) to run specific occ commands accordingly to your own schedule.

Maybe you should check with your provider because noone will know better how to do what you want other than him.
Without knowing anything about your provider, if they require you to use a php script for this, I’d be worried about that script to be in a public place and accessible to anyone, but I guess that’s their problem.
Normally, the cron-like services can run any executable, so you could create a simple shell script to run that command.

2 Likes

Yes I guess that would be the most simple way to go. What would be the correct syntax?
#!/bin/bash and then php occ system:cron?