Back in the days of Moodle 1.9, we wrote a script to perform automated bulk backup and restores.
The purpose of the script was to copy “master” courses to other nominated courses. For example, the “Master Year 7 English” course could be automatically backed up and restored into “Year 7A English”, “Year 7B English”, “Year 7C English”, and so on, in effect setting each back to a default state. Each semester we’d use this script to reset hundreds of courses across three campuses, and it saved us many hours of effort.
Here’s how it worked:
- We created a table containing three fields: source course id, target course id, and a switch field (eg skip the record or process it). The table was populated with the ids of courses to be updated, and the id of the appropriate master course.
- The script iterated through the table backing up of the source course and restoring it into the target course. The process was achieved by calls to backup_execute() from backuplib.php and import_backup_file_silently() from backup\lib.php.
The script wasn’t the most perfect piece of PHP code, but it did its job brilliantly. However, the Backup and Restore processes in Moodle 2 are quite different from 1.9, and have rendered our script useless.
Has anyone written a script that does this kind of thing in Moodle 2.3.1? Or, can anyone give me some clues as to how I might replicate this functionality in 2.3.1?
I’m aware of the new backup_controller() and restore_controller() in Moodle 2; the backup_controller seems to do what I need in terms of backing up a course, but I can’t get my head around how to get that backup restored into a course I specify.
Hoping someone out there can help! Thanks!