Monday, March 26, 2012

Moodle Cron script - the big potato

Well, my objective is to automate the db backing up process, not the courses, I and trying to let moodle handle that, but the DB, which phpMyAdmin could handle, somehow.

There are a few different options for automating db backups using mySQL, since it is a very popular open source tool. Many of the options depend on the OS, most of which tend to be Unix based, since that too is open source software. But, we are using Windows, so I do not have as many options, but still a few.

The path I am on now is trying to get the moodle\admin\cron.php script to handle the work for me. I will probably end up figuring out what my SQL/php statements are for automating this.

The moodle docs suggest for Windows, automating the cron script by adding a service. I downloaded a script from the docs page and ran the installer. Now I have a Moodle Cron service listed in my Services. The properties of the service indicate a Moodlecron.exe was installed in the Program Files\MoodleCron folder, which was created by the installer. The installer asked how frequent it wanted to execute the script, I said every 60 minutes. This means the cron script will execute each hr. The purpose of the script is detailed here.

This is interesting and hopefully enlightening....

I had scheduled automated course backups on friday to run over the weekend. I came in today to check and did not see any evidence of those automated scripts running. I think the reason they did not run was because the cron script did not run. I think the cron script is responsible for executing the automated backups. In other works they are only automated if you have your cron script automated. This does make sense since the cron script needs to be automated to run at least every hr on your moodle server because it does the work of executing other moodle scripts that do things like:
process assignments, quizzes, chat, forum, scorm, rss updates, reports etc. In other words, all this data is not pushed in real time, but sits in the que waiting to be processed by the cron script. Which is why it should run at least every hr. I am sure its a bit more complex than that, but that's a very good aha for me. Executing the course backups are the same thing.

I noticed this because I browsed to the cron script to watch it execute on my server and I saw the course backups running....and, I just checked my email and see a message from the site that the backup completed successfully. The email came to the Admin User, but I put my email as the admin user. The automated course backups sends an email to the admin confirming a successful completion, including the # of courses.

Moral of the story?

Cron is king in moodle. In windows, create a service that calls the cron script as often as you like. The first time the script is called AFTER the automatic course backup time, the course backups will run. For me, that means, 23 times the cron script is called, every hr (executing scripts mentioned above, the 24 the call also includes the course backups run.

No comments:

Post a Comment