Backup Scheduler and Cron on Windows Server 2012

Hi, I recently installed the 1.6.0 beta.6 and it was great to see the new backup scheduler. But I am running Grav on Windows Server 2012 so I do not have CRON

I have tried searching the net but have not found anything that makes it clear to me that I will be able to install something and then run the command that GRAV tells me needs to be run namely.

(crontab -l; echo "* * * * * cd c:\grav\grav-admin;C:\PHP\php-7.2.9\php.EXE bin/grav scheduler 1>> /dev/null 2>&1") | crontab -

and I am not sure if I can set up a windows task to do the equivalent but if I can I do not know what the task setup should be as I do not know how to interpret the cron string above.

Any help would be very appreciated.
Thanks
Derek

You won’t, yet, because the equivalent for Windows has not been implemented. I’m also not entirely sure the executable persists into newer versions of Window Server 2016 and beyond. However, you can definitely run tasks as a substitute, just have it run the CLI-command you wish from your Grav-installation.

The command above by itself makes little sense, because it tries to run the following:

  1. cd C:/inetpub/wwwroot/positivelivingskills.com.au/wwwroot/ecplans, ie. go to the installation-directory
  2. C:\Program Files\PHP\php-7.2.9\php.EXE, ie., prepend the PHP-executable
  3. bin/grav scheduler, ie. run the scheduler

The task, however, is missing. All tasks the scheduler can run should be available as normal CLI-tasks through bin/. Just have the task go to the directory above, add the path to PHP, and execute the CLI-command.

Hi OleVik,

Thanks so much for your response. Can I please confirm.

I should create a task in the normal windows scheduler and have that run, every “x” minutes? I have tried the following (using Admin privilege - just to try things out)

I set the program/script to: “C:\PHP\php-7.2.9\php-win.exe”
and arguments to: -f .\bin\grav scheduler
Start in: c:\grav\grav-admin

Note:
in my site ./bin folder I see the “grav” file
I used php-win.exe above and not php.exe as when I tried

c> php -f .\bin\grav scheduler
(I got an error on the above saying pdo.dll not found (and it is not in the php installation ./ext folder)

c> php-win -f .\bin\grav scheduler

(the above did seem to run but I guess it would not actually do anything if there were no scheduled tasks to run)

but I have no idea if this is correct or not, and I cannot find any docs on how to set up the grav scheduler in task manager for windows.

Also, I tried to set up a “Custom Scheduler Job in Grav”, is this even an option when running on windows? I cannot find any help on this at all.

Thanks
Derek

Yes, scheduling the task at a timed interval will be equivalent to cronjobs. However, running the Grav Scheduler through the Windows Task Manager is superfluous and incorrect, as the former does not support the latter (currently). Rather, you should use the Windows Task Manager to run the task you want Grav to perform directly.

Grav Scheduler is a new feature in Grav v1.6, so docs and support is limited. Let’s take an example: You want to update Grav itself (“Core”) routinely. In Windows Task Manager, you add a task that once a day will run the command cd C:/Grav;php bin/gpm self-upgrade --all-yes > self-upgrade.log 2>&1.

This does three things:

  1. Goes to the directory where Grav is installed.
  2. Asks Grav to self-upgrade (update Core).
  3. Save any output or errors to “self-upgrade.log”.

In essence, until we have a robust way of managing tasks in Windows Task Manager through Grav’s Scheduler, we have to do it the old way.

Hi OleVik,

Thank you again, so much. I created a batch (.bat) file with the following

cd “C:\grav\grav-admin”
php-win .\bin\grav backup > scheduler-backup.log 2>&1

and scheduled that and it works perfectly. So many many thanks.

The only odd thing is in the grav.log file I get this line

[2018-11-18 23:06:34] grav.ERROR: Backup Created: C:/grav/grav-admin/backup/default_site_backup–20181118230619.zip [] []

It reports an error, even though the backup worked (I see the ZIP in the backup folder and can open it just fine)

Any thoughts as to why this might be?

Also the time stamp on the log file is not correct for my server

Lastly is there anyway for me to change the name of the ZIP file produced by the backup process, or should I just do that in the bat file. Is there a place I can look (even in the code) to find out what parameters any given command can take?

Oh and I realised I was stupid enough to include full paths in my previous examples and while I am sure the Grav community is a wonderful bunch (this is probably not a good thing to do from a security perspective), I wonder if there is anyway for you to modify the paths in my previous post to just mention c:\grav\grav-admin?

Many many thanks
Derek

1 Like

May be an incorrect addition in Grav source, where it’s meant to say grav.INFO, or Windows just reports back odd results from the Zip-extension to PHP. The timestamp should derive from your server-settings, ie. PHP’s .ini-settings or where PHP gets them from.

Renaming in the Batch-file would be best, since the Backup-command doesn’t take a “name”-parameter. Even if it did, I find it preferable to rename after the fact, so the OS-level rename happens after PHP has done all its transactions.

I’ll obscure your paths :wink:

Hi OleVik,

Thanks so much for all your help. I set the timezone in the INI file, I guess I had just expected it to pick up the server’s timezone.

And thanks for obsuring the paths.

Just one more thing, is there a place I can find, or will there be when out of beta, all the commands that can potentially be scheduled in a similar way as the backup.

Many thanks
Derek

A list of applicable commands should be available when the docs for Grav’s Scheduler are written, until then all the normal CLI ones are applicable.

Cool once again, thanks very much OleVik.
Derek