## 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.
3k
102
8

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

• Thu, Feb 13, 2014, 7:19 PM
Dear Carol,

the message you are citing appears if
a) the current day is not one of the days you have configured sandbox to run.
b) the current time is before the time you have configured sandbox to run or if sandbox has already run today.

So, assuming that you have configured sandbox with correct day and time when it should run, I can think of these problems:
- You are looking at a manually started cron run output, but there was already a automatic cron run today before your manual start. Please check if the cron run you are looking at is the only cron run on your server.
- There is something wrong with timezones. Actually, the sandbox settings as well as the sandbox run functions should use the timezone of the admin user. But I can't tell if my code is timezone-bulletproof. Please check if the sandbox works if you are scheduling the cron run some hourse before or after your current local time. If yes, I will try to fix the problem.

After that, I have no more simple ideas at the moment...

Alex
• Wed, Feb 26, 2014, 4:40 PM
HI Alexander
Again sorry for the delay in my reply and thank you for your assistance. I think the answer may be much simpler - I got an email from my server:
WARNING: There is no existing course with shortname
"backup-moodle2-course-90-features_demo-20140210-1315", skipping file...

I had put the course backup into the sandbox directory without renaming but I think I should have just named it 'shortname.mbz'?
I will do this now and hopefully not bother you again!
thanks
Carol
• Wed, Feb 26, 2014, 4:54 PM
Carol,
I think you are on the right track. That's a reason for the problem which I didn't think of.

Alex
• Wed, Jul 16, 2014, 2:58 AM
Guys,
I'm needing some help. I am using this to restore a lot of our backups from a different moodle instance. So my issue is I would like to move the files to a different folder once the course has been successfully restored. I have tried the command shell_exec("cp $file /srv/moodledata/moodledata_production2/repository/restored"); and it says that it can't find the file or directory • Thu, Jul 17, 2014, 4:10 PM Zach, what you are doing is not what the plugin was built for - although it can be abused to do what you want to do ;) So I'm trying to give you some basic feedback.$file contains only the filename of the course backup. If you make a shell call with only this filename and the current working directory of the shell is not the directory where the backups are, the file won't be found. You have to provide the whole path of the file to the shell command.

$config->coursebackupsdirectory.'/'.$file
\$file
and your shell command should work.

Alex
• Thu, Sep 25, 2014, 7:34 PM
Hi Alex, this plugin looks awesome, save me restroing our Sandpit course every monday. However I cant seem to get it working, I've read the readme, I have made the dir in moodledata, placed a .mbz backup named the same as the shortname of my sandpit course 'MOODPIT' . but I get an email saying.. WARNING: Unzipping of backup file "MOODPIT" failed, skipping file... any ideas?
• Thu, Sep 25, 2014, 8:55 PM
Hi Chris,

sorry that the plugin does not work for you yet.

This error message occurs when the plugin takes the course backup package, tries to extract it and fails in this step.

But I have never seen this error message before.
Two possible reasons come to my mind:
- The course backup package is extracted to /temp/backup/. It is unlikely, but not impossible, that the process running the moodle cron job is not allowed to write into this directory. Might this be the case?
- There's something wrong with the course backup package. Did you create it on the same Moodle version as you are trying to restore it now? Are you using the "new backup format" on /admin/settings.php?section=experimentalsettings (I have to say that I have never tested local_sandbox with this setting)?

Alex
• Mon, Oct 13, 2014, 9:45 PM
Hi Alex

If I understood it right the sandbox does the job once a day at a certain hour. Do you plan to add an option for every hour ? We are thinking about using a sandbox to showcase something and are concerned about stuff that people are going to upload onto the platform. Resetting the courses every hour would help a lot.

Best regards
Ioana
• Tue, Oct 14, 2014, 2:35 AM
Dear Ioana,

The Moodle 2.7 version of the plugin leverages Moodle scheduled tasks for resetting the sandbox courses. So, you are free to define how often and when exactly courses should be resetted - see https://docs.moodle.org/27/en/Scheduled_tasks for details.

I have changed the description of the plugin here in the plugin repository (it was still describing the pre-2.7 situation of the plugin).

Alex
• Fri, Jan 30, 2015, 4:30 PM
Good Morning,

I am testing this plugin I find interesting about the backup of courses and content. I have successfully installed the version of the plugin for my platform Moodle in version 2.7.x. The following steps have been performed:

- Created the path of sandbox where I will store the backups of courses, with their read and write permissions.
- To test it, I backed up a test course. After completing the backup, I've downloaded and placed in the default path previously sandbox.
- Scheduled Tasks In Moodle, I activated the scheduled task to sandbox, and I run the cron manually on the server.

I have seen the log of cron, and this is what comes in part Sandbox plugin:

Execute scheduled task: Restore sandbox courses
... started 12:22:38. Current memory use 19.1MB.

WARNING: There is no existing course with shortname "copia_de_seguridad-moodle2-course-3-iesa_cfgmcyg_blo-20150129-1148", skipping file...

NOTICE: Sandbox has restored 0 courses
... used 1 dbqueries
... used 0.58944416046143 seconds
Scheduled task complete: Restore sandbox courses

Regards
• Fri, Jan 30, 2015, 5:32 PM
Hi Eduardo,

the way local_sandbox works, your course backup's filename needs to equal the shortname of the course which should be resetted. This is explained in the plugin's readme file.

Based on your current filename, your course shortname will probably be "iesa_cfgmcyg_blo". So you should rename the backup file to iesa_cfgmcyg_blo.mbz

Alex
• Fri, Feb 6, 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, Feb 7, 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, May 25, 2015, 8:17 PM
Hi Alex, do you have plans to update this tool for Moodle 2.9 soon?
• Tue, May 26, 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