Attempting to recover a course but encountering a conflict with an existing account

This week I’ve dedicated significant time to working with course backup files. My goal was to locate the appropriate file and restore it for a student who had partially completed courses last year before being marked incomplete. My customer requested these courses be restored to allow the student another opportunity to finish them.

I was able to locate and restore the first course backup fairly easily, preserving the student’s previous progress.

However, finding the second course backup proved to be more challenging. Once we believed we had the correct backup file, Moodle presented us with an error message during the restoration process.

The error message, “trying to restore xxx from backup file will cause conflict,” appeared.

[Image of error message]

In my assessment, this error occurs because an account already exists for the student. It seems the restoration process cannot definitively determine if it’s the same individual. The error message itself is not particularly helpful as it points to role mappings when the issue actually lies with the conflicting accounts—one in the backup file and one within the database. Ideally, these accounts should automatically synchronize.

I consulted this specific post which offered some helpful insights. According to the post, the content of a Moodle .mbz file can be edited by changing its extension to .zip and extracting its contents. Within the extracted backup, there are .xml files containing user and grade data.

Unzipping the .mbz file allowed me to view the users included in the course backup.

I find this particularly useful because most of our backup files contain a large number of students. This method eliminates the need to restore the entire backup file just to determine if a specific student is included.

Furthermore, the linked post offered advice on resolving the account conflict error. I discovered that simply ensuring matching email addresses and usernames between the backup file and the existing Moodle account wasn’t sufficient. Only after changing the user ID within the users.xml file to match the existing account ID did the error resolve.

My objective is usually to restore grades and progress for a single student, so the other users included in the backup file are irrelevant. With this method, I can now unpack the .mbz file, remove unnecessary users from the users.xml file, and proceed with a targeted restoration.

Steps to edit the users.xml file within a Moodle .mbz file:

1a -  Download Notepad++ from here
2a -  Install Notepad++
1 - Locate the .mbz file and create a copy
2 - Rename the file extension from xxx.mbz to xxx.zip
3 - Double-click the renamed file (it will now appear as a compressed zipped folder)
4 - Extract the contents of the zipped folder into a new folder

[Image of zipped folder]

5 - Open the newly created folder, locate the users.xml file, right-click on it, and select Notepad++ for editing

[Image of extracted folder]

6 - Within Notepad++, edit the content by removing the unnecessary users. As an additional measure, you can note the user IDs present in the xml file and remove their corresponding entries from the gradebook.xml file to prevent any potential issues, as these users won’t be restored without a match in the users.xml file.

7 - Once you’ve finished editing, drag the modified file(s) back onto the renamed .zip file. A prompt will appear asking if you’d like to update the file within the archive—select yes.

[Image of dragging users.xml file]

You will now have a modified Moodle backup file with a .zip extension. This .zip file can be used directly for restoration.

Note: Renaming the backup file back to .mbz is unnecessary. I was able to upload and restore the backupfile.zip without any issues.

Licensed under CC BY-NC-SA 4.0
Last updated on Dec 18, 2022 08:48 +0100