Chapter 13. Backup and Restore

Your hosted Moodle application will contain a lot of very important data such as coursework, assignments, grades, and all administrative data, for example, users, cohorts, and roles. Therefore, it is vital that you have a good backup strategy in place.

Moodle itself supports two types of backups:

  • Course-level backup: Course backups are usually run on an ad hoc basis and only save the selected course. You will learn how to create course backups, restore courses, and how to copy course content using the related course import facility.
  • Site-level backup: The site backup option saves all courses and their related data to a specified location at regular intervals. You will learn how to set this up and recover data from it.

Both mechanisms will be covered in detail before we look at system-level backups, which include Moodle backups (covering the Moodle software itself as well as the data stored in it) and snapshot creation (full system images).

We will conclude the chapter with two applications that make use of the backup and restore facilities, namely, year-end procedure and course templates.

The course-level backup and restore

We will first have a look at the backup procedure before going into the details of how to recover data during the restore operation. Course backup is a four-step process:

The course-level backup and restore

The course backup

To back up an individual course, it is best if you are inside that course, where you have to select the Backup link in the Course administration section. The backup procedure comprises a number of steps, which are described in the sequel. You can navigate backward to any step via the process links at the top of the screen or using the navigation buttons at the bottom.

Initial settings

There are a number of settings that dictate how the backup will be performed and what type of information will be included.

Initial settings

Some settings are only available if other settings have been activated. This is described in the following table:

Setting

Description

Prerequisite

IMS Common Cartridge 1.1

In addition to the Moodle backup format, IMS CC is supported.

None

Include enrolled users

Records can be included in the backup of users who are enrolled in the course.

None

Anonymize user information

User data (username, first name, last name, and e-mail address) will be substituted by aliases. For example, Jonny Walker might become anonfirstname69 anonlastname69.

Include enrolled users

Include user role assignments

This specifies whether assigned roles (including locally assigned and overridden roles) should be included.

Include enrolled users

Include activities and resources

This specifies whether course activities are being shown for selection on the next screen.

None

Include blocks

This specifies whether blocks that are placed in the course and their settings (location, weight, and so on) should be included.

None

Include filters

This specifies whether locally used filters should be included.

None

Include comments

This specifies whether user comments should be included.

Enrolled users

Include badges

This specifies whether user badges should be included.

Enrolled users/activities

Include calendar events

This specifies whether calendar events should be included.

Enrolled users

Include user completion details

If set, course completion and progress tracking information will be backed up.

Enrolled users

Include course logs

This specifies whether log files should be included in the archive. Beware that log files can enlarge the backup files significantly.

Enrolled users

Include grade history

Moodle keeps a history of grade changes. Specify whether these should be included in the backup.

Enrolled users

Include question bank

This specifies whether a question bank should be included. If excluded, any quiz activities will also be excluded.

None

Include groups and groupings

This specifies whether information about groups and groupings is included.

None

Backup default values

By default, all options are available for selection to all users who have the appropriate permissions in the course context. If you wish to either change the default values and/or lock certain settings (such as Include course logs, as shown in the previous screenshot), go to Courses | Backups | General backup defaults:

Backup default values

For every single setting, there are two checkboxes. The first represents the default of the setting, whereas, the second value indicates whether it is locked or not. Locking allows you to force certain settings, for instance, the exclusion of users.

Content-only backup versus full-course backup

There are usually two types of course backups that you are likely to perform:

  • Content-only backups
  • Full-course backups

If you wish to pass a course on to another user or make it available for download, a content-only backup is the best option. Another use case is to create a new instance of a course for oneself, for example, taking a course backup from one semester to use in a different semester. As the name suggests, the content-only backup only contains content that can be passed on to another person without transferring any information about its users, roles, grades, and so on. To perform a content-only backup, you have to deselect Include enrolled users. You can see from the preceding table that this option is a prerequisite for most other backup options. When you publish courses on a community hub (refer to Chapter 16, Moodle Networking), you will also create a content-only backup.

Tip

By default, users with teaching rights can only perform content-only backups. This can be changed via the moodle/backup:userinfo capability, but it should be done with care.

If you wish to back up a course for potential recovery purposes, you should create a full-course backup, which includes user data (for example, forum posts), course data, and user information. To do this, you can leave all the settings in their default values, except Include grade history. You can turn off the Jump to final step button.

If you wish to back up the log information of the course as well, the Include course logs setting has to be enabled. Bear in mind that logs can be very large and often exceed multiple gigabytes when backing up all the courses.

Whether you choose to create a content-only or a full-course backup, Moodle will automatically include the configuration of a course. However, you might experience problems with content that's created by third-party add-ons. If you encounter any issues, you will have to exclude these items from the backup. Ideally, you should report the issue on the tracker (https://tracker.moodle.org) so that the maintainer of the module can fix any shortcomings and the contributed module can be included in your backup again.

Schema settings

All learning resources and activities are shown in the order in which they appear in the course. This also includes orphaned content, that is, resources and activities that have been placed in a section that is not shown in the course. If the Include activities parameter has been deactivated on the previous screen, only resources are available for inclusion. By default, all the available elements are selected. If you wish to exclude any individual items, you have to deselect them. Additionally, you can exclude/include all the items of a section by selecting/deselecting the section name itself. For instance, in the following screenshot, Topics 2 to 4 and the video resource have been excluded from the backup.

Moodle distinguishes between course content and user data. For example, in a forum activity, the forum description and all its settings are classified as course content, whereas, all topics, posts, and replies to a forum are classified as user data. If Include enrolled users has been left activated on the initial setup screen, user data can be included/excluded for each selected activity and resource. Selecting Show type options lets you select the All or none activities of a particular type.

Schema settings

Confirmation and review

The third screen lets you choose the backup filename and review the items to be included in the archive.

The default Filename is backup-<type>-<format>-<course name/id>-<year><month><day>-<hour><minute>[-nu].mbz.

Currently <type> is always set to moodle2, and the only value supported for <format> at the moment is course. The optional –nu parameter stands for no users.

If you have opted to create IMS Common Cartridge as the backup form, the .imscc extension will be used instead of .mbz.

Confirmation and review

The additional Backup settings section shows which item has been selected and deselected on the initial settings screen. The Included items section indicates with a green tick all resources and activities that will be included as well as any user data that will be part of the course backup. A red cross means that the item has been deselected, whereas, a red cross followed by a lock indicates that it wasn't possible to select the item since a prerequisite has not been fulfilled.

Finalizing a backup

Once you press the Perform backup button, the Moodle course archive will be created.

The actual archive file is saved in Course backup area. This can take a few minutes depending on the size of the data being backed up. If the Anonymize user data setting has been chosen at the beginning, the backup file will be placed in User private backup area.

After completion, a brief status message is shown as well as technical information and warnings. You will have to take appropriate actions if this contains any errors or warnings.

Moodle creates a bespoke file format for backups, known as the Moodle Backup Format, using the .mbz extension. A Moodle backup file is a compressed file (in the .tgz format), consisting of an XML file (which describes the content of the file) and the actual user, course, and log data.

Backups sometimes fail with regard to large courses. The cause is usually that the backup process runs out of time or memory. This usually happens on commercial web hosts that are not dedicated to Moodle. If this happens, increase the max_execution_time value in your php.ini file.

The course restore

To restore an entire course or parts thereof, use the Restore link within a course or in the course category screen. You will be directed to the area where both course backups, private, that is, anonymized, backups and automated backups are stored. Additionally, you can import backup files via the file picker.

The course restore

In the preceding example, a single course is present in the course backup area, called backup-moodle2-course-6-20141101-1127.mbz. From its name, we already know that the course ID is number 6 and was backed up on November 1, 2014 at 11.27.

Select the Restore link besides a backup file to kick off the recovery process. Like the backup, the restore procedure goes through a number of steps. The first screen displays information about the course backup (type, format, mode, backup date/time, Moodle version, backup version, and the URL of the .mbz file), backup settings (identical to the initial settings in the backup), and the course details. Once you have confirmed this screen, you have to specify the destination of where to recover the backup.

The restore destination

There are various options to restore a course backup:

  1. Restore as a new course.
  2. Restore into this course and merge the backup into this course.
  3. Restore into this course, delete the contents of this course, and then restore it.
  4. Restore into an existing course and merge the backup into the existing course.
  5. Restore in an existing course, delete the contents of the existing course, and then restore it.
    The restore destination

If you wish to Restore as a new course, you will have to select a category in which the new course will be created. If the number of categories exceeds 20, you will have to use the provided search facility. Alternatively, you can choose the current course as the destination (Restore into this course). You can either combine the current course content with the backup (Merge the backup course into this existing course) or replace it (Delete the contents of this course and then restore). If you choose the merging option and an activity or resource with the same name exists, both will be kept and not overridden. The third option is to restore the course into another existing course, which you have to select. The same options (merge and replace) exist to restore the backup in the current course. Make sure you click on the correct Continue button before you proceed.

Restore settings

The restore settings screen shows all the available options that have been selected during the backup process (refer to the preceding Initial settings section). As shown earlier, the choices made here dictate the types of data that will be recovered and which type of content will be offered for further selection. Also, most options have prerequisites that are identical to their backup counterparts.

The backup schema

The backup schema lets you specify a number of course settings. If you restore the backup to an existing course, you have the option to modify the existing settings. These are Course name, Course short name, and Course start date. You can further choose to Keep current roles and enrolments (if this is a part of the backup), Keep current groups and groupings (if stored in backup), and use the course settings of the backup file instead of the current ones (Overwrite course configuration).

Additionally, you have to chose which content and user data has to be included in the recovery procedure. The selection mechanism is very similar to the backup equivalent that was described earlier. By default, all the data that is present is selected. If you wish to narrow down the data to be restored, you have to deselect items manually.

The backup schema

Finalizing a restore

Once you have confirmed the Schema screen by clicking on the Perform restore button, any selected data will be recovered to the chosen destination. After completion, a brief summary message is shown.

If you see a topic heading labeled Orphaned activities in your recovered courses, go to the course settings and increase the number of topics. If you cancel a restore operation halfway, a course called Course restoration in progress might be displayed. It is usually safe to delete this course.

The course Import

It is sometimes necessary to copy data from one course to another. To achieve this, Moodle provides the import course data feature. However, unlike the backup function, it will not import user data, such as assignment submissions or forum posts. It will only import the structure of activities, blocks, and filters. For example, you might want to import a single quiz from one course to another.

Teachers are allowed to import content from courses for which they have editing rights; as an administrator, this restriction does not apply. This mechanism bypasses the requirement for a backup and restore procedure if you want to copy course content from one course to another and do not require user data.

First, select the Import link from the Course administration section. Here, you have to select a course that you wish to import content from. If the list exceeds 10 courses (or whatever has been specified when you go to Courses | Backups | General import defaults), you will have to use the provided search facility. You can also select the current course. This way, you can duplicate activities.

The course Import

Next, you have to choose whether you wish to import activities and resources, blocks, filters, calendar events, the question bank and/or groups and groupings:

The course Import

For activities, a familiar selection screen will be shown next. If you choose either filters or blocks, all their content and settings will be copied, that is, no selections will be possible.

As usual, a Review screen has to be confirmed with the Perform import button before the copying starts, and a concluding summary message will be displayed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.127.37