Wednesday, December 10, 2014

Trying to restore a course and getting a conflict with existing account...

I have spend lots of time this week working with course backup files, trying to find the correct one and then trying to restore it.  We have a student who completed most of a couple courses last year before we marked him incomplete.  The request came from my customer to restore his courses and give him a change to finish them now....

We had his name and a time frame when he was enrolled in the courses.  I found the first course back up without much trouble, and was able to restore it, previous progress in tact.

Finding the second one was a little more problematic and when we found the backup file we thought was the correct one, we tried to restore it only to have moodle rebuke us with this message.

trying to restore xxx from backup file will cause conflict












I think an account already exists for the user and the course being restored cannot reconcile with 100 % assurance that it is the same person.  The error message is pretty stupid and pointless - it has nothing to do with the role mappings and everything to do with the account in the file conflicting with an account already in the DB.  An account that should simply sync.

I found this post, that was a little helpful.  It explains that you can actually edit the content of the moodle .mbz file by changing its extension to .zip and then extracting the content.  In the extracted backup file, there are .xml files for users and grades.

Unzipping the .mbz file allows me to look at the users who are included in the course backup.

This is very useful for me, as we have many students in most of the backup files.  Being able to look into the backup file to see if who i am looking for exists is helpful.  Previously, I had to restore the backup file to see who was enrolled.

Additionally, the linked post above provides a couple pointers about how to remove the conflict error with the account.  Ensuring the email address and username was not enough for me.  I did that (verifying the username and email of the user in the backupfile with the existing account in the moodle user table - but still go this error.  It was not until I changed the id in the users.xml file to match that of the user account - that the error went away.

Typically, I am only trying to restore the grades/progress for a single moodle user, the other users in the backup file are not necessary or desirerable.  Now, I can unpack that mbz file and remove the users from the users.xml file and only restore what/who I want.

Steps to edit the users.xml file in the moodle .mbz file

1a -  download notepad ++ from here
2a -  install notepad++
1 - find the .mbz file - copy it
2 - rename the file from xxx.mbz to xxx.zip
3 - double click the file (a compressed zipped folder)
4 - extract the content into a new folder


5 - open the new folder and right click on the users.xml file - choose notepad ++ to edit it



6 - edit the content, removing the users from the file.  If you are really ambitious, note the userid in the xml file and remove the graded items for that user in the gradebook.xml file, since they won't restore anyway with no matching user in the users.xml file.

7 - Upon completion of the edits, drag the file(S) from the folder onto the renamed .zip file (you will be prompted to update the file in the zip file.




















Now you have an updated moodle backup file that ends in .zip.  You can actually use the file in its current .zip format to restore.   

You do not have to rezip or rename the backup file to .mbz.  I did not have to.  I was able to upload and restore the backupfile.zip.

No comments:

Post a Comment