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 – john@ilite.com uid = 6
hannah.jones – hannah@ilite.com uid = 7
clark.kent – clark@ilite.com uid = 6
charlie.brown – charlie@ilite.com 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 – john@localhost.com ui = 10
hannahjones – hannah@localhost.com uid = 11
charliebrown – charlie@localhost.com uid = 5
clarkkent – clark@localhost.com 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.

restore_1

From the front page settings – select ‘Restore’

restore_2

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

restore_3

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

restore_4

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

restore_5

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.

restore_6

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

restore_7

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

restore_8

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 – john@ilite.com uid = 6 – new id = 15
    • hannah.jones – hannah@ilite.com uid = 7 – new id = 16
    • clark.kent – clark@ilite.com uid = 4 – new id = 13
    • charlie.brown – charlie@ilite.com 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 *