Note: You are currently viewing documentation for Moodle 3.1. Up-to-date documentation for the latest stable version of Moodle is probably available here: Moodle migration.

Talk:Moodle migration

From MoodleDocs

Moodle on Multiple Servers

This article is written with the assumption that Moodle will be hosted on a single server. But what about large Moodle installations that are hosted on multiple "load balanced" servers? These sites may share the Moodledata folder using e.g. NAS storage. The database may also be hosted on a different database server. Is the migration process any different for these multi-server sites? If so, what needs to be done differently when migrating these sites? Example: how should caching be configured on these multi-server environments? --Luis de Vasconcelos (talk) 17:51, 25 April 2016 (AWST)

Logical flaw in the "Quick and hacky method" (correction, along with some technical remarks)

The "Quick and hacky method" contains a logical flaw and some technical issues:

  • As stated, the step, "Replace any links in the database" is left dangling: it occurs after the (completed) DB content migration, and the argument file that the sed command is to operate on (i.e., "oldmysqldump.sql") is never created, nor is the output (i.e., "newmysqldump.sql") ever used. The sed command needs to be included right in the pipe that implements the "Dump existing database and move and import into database on new server" step.
  • In the corrected version, below, have replaced the '/' argument delimiter in the sed 's(ubstitute)' command by ';', which is less likely to occur in the "oldserver" and "newserver" specifications (which might include some top-level path, where all '/' would then need to be escaped…).
  • Note/reminder: The first argument to the 's' command is interpreted as a regular expression, not a plain string. In regular expressions, the dot ('.') is a placeholder for any character; to specify an 'actual period character' the dot needs to be escaped (i.e., stated as: \.). The second argument of the 's' command is a plain string, which is why in the code below there is no backslash in front of the '.' appearing in "newserver.com".
  • I needed to add the '--single-transaction' flag to mysqldump to prevent a locking error to occur.
  • I added the "-C" flag to the ssh invocation: it asks for compression of the (plain text) data over the network (cf. the comment on network transmission at the end of the original article).
  • Note that the pair of double quotes after the ssh are essential to ensure the second pipe is executed on the remote host, as intended, and not locally.
  • (side remark: To get the database import to work on the receiving host side, I had to replace the moodle MySQL_USERNAME by the mySQL root user (because of insufficient rights of the moodle MySQL_USERNAME) -- but this may be symptom of a lurking issue developed after many upgrades and migrations).

This would then be the revised "Dump existing database and move and import into database on new server, replacing all occurences of the old by the new server name" command:

mysqldump --single-transaction --allow-keywords --opt -uMySQL_USERNAME -pPASSWORD DATABASE | ssh -C USER@DOMAIN "sed -e 's;oldserver\.com;newserver.com;g' | mysql -uMySQL_USERNAME -pPASSWORD DATABASE"