Offline backup/mirror of a Moodle course, using httrack

I havent’ found much details online on how to perform a Moodle course mirror that could be browsed offline using httrack.

This could be useful both for backup purposes, or for distant learners with connectivity issues.

In my case, there’s a login/password dialog that grants access to the moodle platform, which can be processed by httrack by capturing the POST form results using the “catchurl” option.

The strategy I’ve used is to add filters so that everything is excluded and only explicitely mentioned filters are then allowed to be mirrored. This allows to perform the backup connected with a user that may have high privileges, while avoiding to disappear in loops or complex links following for UI rendering variants of Moodle’s interface.

Here’s an example command line :
httrack -v -z -%F "Mirrored [from host %s [file %s [at %s]]]" -N "%h%p/%n%[id].%t" "http://mymoodle.example.com/login/index.php?>postfile:/home/myself/websites/mycourse/hts-post0" "http://mymoodle.example.com/course/view.php?id=42" -O "/home/myself/websites/mycourse" "-*/*" "+/login/index.php*" "+*/course/view.php*" "+*/mod/resource/view.php*" "+*/mod/page/view.php*" "+*/mod/forum/view.php*" "+*/mod/forum/discuss.php?d=*[0-9]" "+*/mod/url/view.php*" "+*/pluginfile.php/*" "+*/mod/feedback/view.php*" "+*/mod/feedback/analysis.php*" "+*/theme/*" "-*/course/view.php?id=43"

Let’s comment on these different parameters :

  • -v -z : shows me a verbose log of what’s done, on stdout. May be removed if command needs to execute in batch mode.
  • -%F “Mirrored [from host %s [file %s [at %s]]]” : This adds an additional header to the pages
  • -N “%h%p/%n%[id].%t” : converts URLs like mymoodle.example.com/mod/page/view.php?id=42 to files saved as /home/myself/websites/mycourse/mymoodle.example.com/mod/page/view42.html
  • “http://mymoodle.example.com/login/index.php?>postfile:/home/myself/websites/mycourse/hts-post0” “http://mymoodle.example.com/course/view.php?id=42” : these are the two pages to be backed-up :
    • “http://mymoodle.example.com/login/index.php?>postfile:/home/myself/websites/mycourse/hts-post0” : this performs the login by sending the POST request with login and password
    • “http://mymoodle.example.com/course/view.php?id=42” : this is the entry page of the course
  • -O “/home/myself/websites/mycourse” : save to this directory. The mirror will be available at file:///home/myself/websites/mycourse/mymoodle.example.com/index.html
  • “-*/*” : don’t follow any links, but the ones explicitely allowed below :
  • “+/login/index.php*” “+*/course/view.php*” “+*/mod/resource/view.php*” “+*/mod/page/view.php*” “+*/mod/forum/view.php*” “+*/mod/forum/discuss.php?d=*[0-9]” “+*/mod/url/view.php*” “+*/pluginfile.php/*” “+*/mod/feedback/view.php*” “+*/mod/feedback/analysis.php*” “+*/theme/*” : this mirrors much of the course contents in our case : pages, PDF attachments, forum posts, etc. (you’ll need to customize this depending on your course contents)
  • “-*/course/view.php?id=43” : but don’t backup other courses the same user participates to

I hope this will be useful.

One thought on “Offline backup/mirror of a Moodle course, using httrack”

Leave a Reply

Your email address will not be published.