Talk:Course backup

From MoodleDocs

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 moodle2
  • type - string - one of course, section or activity
  • id - integer - the item's database ID
  • useidonly - bool - if the backup was created without the backup_shortname config enabled
  • date - string - the date in format specified by the backupnameformat lang string
  • users - bool - if user data is included
  • anonymised - bool - if user data is anonymised
  • files - 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 shortname
  • course.fullname - string - course fullname
  • course.startdate - string - course start date in format specified by the backupnameformat lang string
  • course.endddate - string - course end date in format specified by the backupnameformat lang string
  • section.name - string - section name
  • section.section - integer - section number
  • activity.name - string - activity name
  • activity.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 `_`