<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>James&#039; Tools and Tricks &#187; Meld</title>
	<atom:link href="http://jrudd.org/wordpress/tag/meld/feed/" rel="self" type="application/rss+xml" />
	<link>http://jrudd.org/wordpress</link>
	<description>Tools, Tips and Hints for managing a network.</description>
	<lastBuildDate>Mon, 26 Jul 2010 03:13:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Moodle Structure Problems</title>
		<link>http://jrudd.org/wordpress/2009/06/18/moodle-structure-problems/</link>
		<comments>http://jrudd.org/wordpress/2009/06/18/moodle-structure-problems/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 07:10:44 +0000</pubDate>
		<dc:creator>James Rudd</dc:creator>
				<category><![CDATA[Moodle]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[Meld]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://jrudd.org/wordpress/?p=106</guid>
		<description><![CDATA[Recently I discovered our Moodle gradebook was playing up and not correctly recording marks from assignments as well as been unable to assign categories from quizes.
I tracked the problem down to the Moodle database losing all its default entries for its tables.]]></description>
			<content:encoded><![CDATA[<p>WARNING: DO NOT ATTEMPT ANY OF THIS IF YOU DO NOT FULLY UNDERSTAND IT. YOU CAN DESTROY YOUR MOODLE SITE.</p>
<p>Recently I discovered our Moodle gradebook was playing up and not correctly recording marks from assignments as well as been unable to assign categories from quizes.</p>
<p>I tracked the problem down to the Moodle database losing all its default entries for its tables. The cause is unknown but is quite likely the <a title="UTF Convert" href="http://moodle.org/mod/forum/discuss.php?d=97592">UTF conversion utility</a> I ran previously to make the system compatible with Asian languages for LOTE.</p>
<p>To fix this problem I needed to recreate the Moodle DB structure and then reimport the data.</p>
<h2>Backup</h2>
<p>First make a backup. I made a mistake the first time I tried repairing this and the backup I made saved me.</p>
<pre class="brush: bash;">mysqldump -u backupacc -p -Q --opt moodle &gt; moodleBackup.sql</pre>
<p>I created a duplicate site with a clean DB (copy the moodle folder and create a new DB) and went through the install. This needs to have all your modules and blocks to ensure all tables are created.</p>
<p>I then dumped the structure from this new DB and the old DB and compared them using Meld (or any other diffing program will work).</p>
<pre class="brush: bash;"> mysqldump -u backupacc -p --no-data --skip-add-drop-table moodletest2 &gt; moodleGoodStruc.sql
mysqldump -u backupacc -p -d --skip-add-drop-table moodle &gt; moodleOldStruc.sql</pre>
<p>Using Meld determine if there are any extra tables or fields in your current system that don&#8217;t exist in the clean one.</p>
<p>Then you need to determine if it is safe to delete those tables / field in your main DB or if they need to be added to the clean system. e.g. grade_items_history.decimals and grade_items_history.display were in the main DB but not the new one. After searching for it discovered they can be removed (<a href="http://tracker.moodle.org/browse/MDL-15985">MDL-15985</a>).</p>
<p>After getting them to match you need to dump your Moodle data from your main site.</p>
<p>You can speed up the next steps by reducing the size of backup_log if you wish. Just do a</p>
<pre class="brush: sql;">
Delete
FROM `mdl_backup_log`
WHERE `time` &lt;1242777600
</pre>
<p>Where the time code is <a href="http://converteverything.com/conversions/unix_time.htm">calculated as a unix time code</a> from about a month before todays date. This can reduce alot of space of your DB, and improve import/export times.</p>
<pre class="brush: bash;">mysqldump -u backupacc -p  --no-create-info --extended-insert --complete-insert moodle &gt; moodleData200906171559.sql</pre>
<p>You need the <strong>&#8211;complete-insert</strong> option to ensure each insert is labelled with field name, in case field order is different. I didn&#8217;t do this the first time and needed to restore the backup.</p>
<h2>Testing Merge</h2>
<p>Now you need to test it. Create a new empty DB and import the Structure then import your data.</p>
<pre class="brush: bash;">mysql -u root -p moodleTest3 &lt; moodleStruc.sql
mysql -u root -p moodleTest3 &lt; moodleData200906171559.sql</pre>
<p>Check that no errors occurred during import, this is when I discovered most of my problems with extra non existent field.</p>
<h2>Prep for Applying</h2>
<p>Put your site in Maintenance mode so no users can login while you are testing this. (i.e. when you restore data site will already be in maintenance mode)</p>
<p>When everything is OK do another backup, as after this you are going to <strong>delete it all</strong>. (I recommend taking your site completely offline for this, not just maintenance mode. Edit your config.php and temporarily change either the username, password or db name or your database settings.)</p>
<p>Now re-export the Data again (assuming your site has been running while you have been doing tests)</p>
<pre class="brush: bash;">mysqldump -u backupacc -p  --no-create-info --extended-insert --complete-insert moodle &gt; moodleData200906171559.sql</pre>
<h2>Applying to Site</h2>
<p><strong>WARNING: HAVE A GOOD RELIABLE BACKUP BEFORE THIS STEP.  THIS WILL DESTROY YOUR MOODLE SITE.</strong></p>
<p>Now use phpMyAdmin to drop every table in the Moodle main DB. Just use Check All at the bottom and select Drop.</p>
<p>Now you need to redo your test restore above but to your main DB.</p>
<p>Once complete reconnect your config.php file and check everything on your site looks the same. Open some courses, check some gradebooks, have a look around.</p>
<p>When its OK take out of Maintenance mode and you should be good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://jrudd.org/wordpress/2009/06/18/moodle-structure-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
