Talk:Course backup
To be added to the 5.2 docs:
Customising default backup filenames
The default filenames of backups can be customised using templates (introduced in MDL-84440).
In Site administration > Courses > General backup defaults > Default backup filenames, templates can be used to customise the default backup filename when a course, section or activity is created.
Template variables
These templates use the Mustache template language. Mustache uses variables (temporary placeholders) which are eventually populated with the relevant data.
The admin settings page lists what variables are available to build your filename.
format- string - backup format, usually moodle2type- string - one of course, section or activityid- integer - the item's database IDuseidonly- bool - if the backup was created without thebackup_shortnameconfig enableddate- string - the date in format specified by thebackupnameformatlang stringusers- bool - if user data is includedanonymised- bool - if user data is anonymisedfiles- bool - if files are included
For example, {{type}} will be replaced with either `course` `section` or `activity` depending on the type of backup made.
{{type}}-{{date}}-{{id}}
// E.g. course-20251105-0215-3
Depending on the templates's context, some variables have more than one level of information available.
course.shortname- string - course shortnamecourse.fullname- string - course fullnamecourse.startdate- string - course start date in format specified by thebackupnameformatlang stringcourse.endddate- string - course end date in format specified by thebackupnameformatlang stringsection.name- string - section namesection.section- integer - section numberactivity.name- string - activity nameactivity.modname- integer - module name
{{course.shortname}}-{{course.fullname}}
// E.g. bio101-Biology_101
Conditional data
You can conditionally include data by using # before the variable name in the opening tag, and / before the variable name in the closing tag. This will check if the variable `files` is true and include the information between the tags.
Backup{{#files}}-with-files{{/files}}
// E.g. Backup-with-files (if `files` is true/has data)
The use of ^ will do the inverse and exclude the data.
Backup{{^files}}-without-files{{/files}}
// E.g. Backup-without-files (if `files` is false/has no data)
Moodle language strings can be included with the special variable #str.
{{#str}}backupfilename{{/str}}
{{#str}}mystring, local_myplugin{{/str}}
Important
- New backups with the same name will overwrite previous backups. A common way to avoid this is to add the
{{date}}variable to the backup filename. - Do not add the `.mbz` extension, it will automatically be added.
- Backup filenames will be truncated to 251 characters when created. This is because it must be less than or equal to 255 characters, and 4 characters are reserved for the added `.mbz` extension.
- Any empty spaces will be replaced with underscores `_`