## General plugins (Local): Sandbox

local_sandbox
Maintained by University of Ulm, Alexander Bias
Moodle plugin which programatically restores courses to predefined course states. It can be used to provide playground moodle courses which will be cleaned periodically.
168 sites
16 fans

After installing local_sandbox, the plugin doesn't do anything until it is configured. To configure the plugin, please visit Plugins -> Local plugins -> Sandbox.

There, you are able to define when local_sandbox should restore the courses.

You also define the directory where the course backup files to use for course restoring are. local_sandbox takes every file in this directory with a .mbz filename extension, takes the file's name, searches for a existing course with a shortname equal to the file's name and finally, uses the course backup file to restore / reset this course.

Additionally, there is an option to set the course start date to today instead of setting it to the date saved in the course backup file. Use this option if you need to provide playground courses in Moodle which pretend to be up-to-date.

As local_sandbox acts automatically, it can inform you by mail when failures or problems occur.

### Contributors

Alexander Bias: Developer

### Awards

• Fri, 6 Feb 2015, 7:30 PM
Hello Alexander,
Awesome plugin.
Could you please confirm the following? Thank you.

1) I must always manually upload the .mbz backup file(s) to /moodledata/sandbox/ yes? If so, is there a way to have moodle's course backup automatically be stored there?

2) I get new students on a regular basis, but from what I understand (limited) when I export a course it freezes the list of students who are enrolled in it. If so, does it mean that I will need to re-export my course (and upload to /moodledata/sandbox) everytime I get new students, because if I don't the ones who enrolled AFTER the first backup won't have access to it?

3) Is it OK to run a cron every hour with this plugin or is that going to increase the load on the server significantly (I just have one small demo course to restore.)

• Sat, 7 Feb 2015, 3:53 AM
Hi Sebastien,

> I must always manually upload the .mbz backup file(s) to /moodledata/sandbox/ yes?

Yes. We have been thinking about implementing a possibility to upload the course backup directly within the Moodle admin interface with the standard filepicker, but up to now we didn't have the time and need to do it.

> If so, is there a way to have moodle's course backup automatically be stored there?

I don't think so. You have to download the course backup and then upload it via FTP / SCP / whatever to your webserver. To do this, you will have to have direct access to moodledata. This is not possible with some Moodle hosts, that's why we thought about the filepicker solution.

> I get new students on a regular basis, but from what I understand (limited) when I export a course it freezes the list of students who are enrolled in it. If so, does it mean that I will need to re-export my course (and upload to /moodledata/sandbox) everytime I get new students, because if I don't the ones who enrolled AFTER the first backup won't have access to it?

Well, you can backup a course without including enrolments into your backup file. When sandbox restores the course, all students who are enrolled up to then are removed from the course and course content is restored from the backup. That's what we do here and what the plugin is made for.

I haven't tested yet what sandbox does when you use a backup file with enrolments. But I don't see a real use case for restoring enrolments with sandbox on a regular basis. Why do you want to reset a course regularly _and_ keep students enrolled?

> Is it OK to run a cron every hour with this plugin or is that going to increase the load on the server significantly (I just have one small demo course to restore.)

Sure, restoring a course backup takes some seconds to process and puts some load on the DB. But as long as you don't run the cron every minute so that restore processes overlap, this shouldn't be any problem for a healthy server.

Alex
• Mon, 25 May 2015, 8:17 PM
Hi Alex, do you have plans to update this tool for Moodle 2.9 soon?
• Tue, 26 May 2015, 1:21 AM
Hi Bernhard,

up to now, we didn't have the time to check our plugins on 2.9 thoroughly. I assume our testing period will start in June.

Did you test Sandbox on 2.9 and did encounter any problems? If yes, I might be able to have a look at it earlier and provide some quick fix.

Thanks,
Alex
• Tue, 29 Sep 2015, 10:30 PM
Hi Sebastien,

> If so, is there a way to have moodle's course backup automatically be stored there?

Give Moosh a try. It's a command line tool and one of its functions, course-backup, allows you to specify the location where you want the backup file to be saved as well as the file name.

Best regards,

Michael
• Wed, 18 Nov 2015, 8:18 PM
Thanks for this plugin! Is there a way to force the course ID to be the same as my 'original' sandbox course (happy to change code) - two reasons:
1. my sandbox is hardcoded into menus, so when the course id changes, the link breaks
2. the sandbox will reset every day, so my course ID number is going to increment very rapidly.

Obviously, the second is not a huge issue, but the first is quite important.

The course ID seems to in classes/task/restore_courses.php - I tried...

$newcourseid =$oldcourseid;

and

\$newcourseid = '19';

at the start of the // Create new course section, but neither option works.

• Wed, 18 Nov 2015, 8:33 PM
Jon,

I can't do anything about 2., that's just how the plugin works at the moment.

But for 1., you can change your hardcoded link form https://yourmoodle.com/course/view.php?id=1234 to https://yourmoodle.com/course/view.php?name=courseshortname. As the course's shortname will be kept for the resetted course, this link will continue to work. And you don't have to hack the plugin ;)

Alex
• Wed, 18 Nov 2015, 9:00 PM
Oh yeh, why didn't I think of that! Doh!
Thanks
• Mon, 28 Mar 2016, 6:40 PM
Hello,
Testing the plugin with:
moodle 3.03.
v3.0-r2 (2016021000)
/var/www/clients/client1/web1/private/moodledata/sandbox - (permission: -R 777)
1 NOTICE: Sandbox has restored 0 courses
1 WARNING: There is no existing course with shortname "demo_lms", skipping
file...
backupfile name - backup-moodle2-course-6-demo_lms-20160328-1326.mbz
sandbox backup file "demo_lms.mbz"
what i'm doing wrong?
Thank you
• Tue, 29 Mar 2016, 3:31 AM
James,

based on your posted message, local_sandbox is looking for a course which has a shortname called "demo_lms" which it can reset to the state saved in demo_lms.mbz. If such a course does not exist, you can either change the shortname of the course you want to reset to "demo_lms" or you can rename demo_lms.mbz to the shortname of the course you want to reset.

Alex
• Wed, 25 May 2016, 3:53 AM
Is this the plugin that is in effect on demo.moodle.net to reset the course every hour?

Thanks!
• Wed, 25 May 2016, 4:00 AM
Hi Matt,

no, it isn't.
• Tue, 28 Jun 2016, 11:40 PM
Hello. I've just installed this plugin on my Moodle 3.1 and have noticed that new courses are being created instead of existing courses being reset. Instead of resetting the existing courses, the plugin seems to be deleting the existing course and creating a new one. I know this because the restored course has a new course ID. Not sure if I have set this up correctly. Any advice will be much appreciated.
• Wed, 29 Jun 2016, 2:44 AM
Hi Abdul,

you're right, that's just how the plugin works at the moment. This topic has been discussed before in this comment seciton here, please have a look at the other comments - especially from Jon Bolton - if you like.

Thanks,
Alex
• Thu, 30 Jun 2016, 12:50 AM
Thanks for the suggestion Alex!