Merging two Moodle sites

The other day I was asked if it would be possible to merge a number of Moodle sites into a single Master Moodle site. Well I gave it some thought. Considered all the relationships between the different database tables, what conflicts there might be, and how one would handle there. I finally concluded that it would just be to tricky to do.

So I considered a work-around. Simply backup and restore the courses from Moodle A into Moodle Master. To make matters a little more interesting, I deliberately tried to create conflicts.

My initial set-up of Moodle A and Moodle Master looked like this:

Moodle A
Create four users
john.smith – uid = 6
hannah.jones – uid = 7
clark.kent – uid = 6
charlie.brown – uid = 5

Create a new course
course id – 3
Course contains – quiz, movie, label, forum with two posts
Blocks – Course completion, Self Completion

Logged in as John and Hannah
View all topics
Completed the quiz

Performed a backup of the course, making sure to select all necessary options in the backup
Moodle Master
Create two users
johnsmith – ui = 10
hannahjones – uid = 11
charliebrown – uid = 5
clarkkent – uid = 4

Course with an id of 3 already existed in Moodle Master

With the set-up above I had made sure to have duplicate course ID’s as well as duplicate user ID’s. I know that Moodle auto-assigns these ID’s so that was fine. Moodle does not allow duplicate usernames or email addresses, so I made sure from the start that they were unique.

With my Moodle A course backed up, I proceeded to import it into Moodle Master.


From the front page settings – select ‘Restore’


Drag the backup into the upload area, and click the ‘Restore‘ button


Review the backup details and settings to make sure that all the information was correct. The only options not selected are the ones indicated with the X


Selected the option to restore as a new course and clicked the ‘Continue’ button


If you have tried the restore once before and it failed, you can re-run the restore and restore the course into your previous attempt.

NOTE: Once I had made the backup, I downloaded the .mbz file. The .mbz file contains a number of files, including the users.xml file. Open this file and change the admin username from <username>admin</username> to  <username>admin_moodleA</username>

If you don’t do this, you will get a username conflict during the restore. The restore will fail, but create a course with the course name restoring, as can be seen above.


Make sure all the boxes are selected for the content you wish to import.


Confirm the name of the course you wish to create with the restore, and click the Perform Restore button.


With any luck you should see the screen above.

Once I had done the restore, I went and checked what had happened to my course, data and users. The results are below:

  • The course restore successfully with a new ID of 7
  • All the grades were in place
  • The logs for the course were complete showing all interactions for the users
  • Notable changes were those to the user ids
    • john.smith – uid = 6 – new id = 15
    • hannah.jones – uid = 7 – new id = 16
    • clark.kent – uid = 4 – new id = 13
    • charlie.brown – uid = 5 – new id = 14

Finally as a warning.
These were my findings done between to different servers both running Moodle 2.6 and having similar users. The course was quiet small and I did not write any DB queries to check all the data. If you are going to do this in a production environment, then do some of you own tests first.

0 thoughts on “Merging two Moodle sites

Leave a Reply

Your email address will not be published. Required fields are marked *