Restoring Large Courses : May be a solution?

Restoring Large Courses : May be a solution?

by panagiotis karageorgos -
Number of replies: 3

I've tried this and it actually worked ! to a moodle 2.3.6, Ubuntu 12.04.

I had to face a difficult situation. The problem occurred when I actually tried to restore Large Courses from their Backups. The procedure hanged with “internal server error”. I ve made many tries and tried to watch the debugger also, but with no luck.

Although, as I have noticed my system was working fine when backing up and restoring backup files smaller than 450MB.

So, I had to restore a course about 800MB and to make this happen I have followed the steps as described:

1)     I had to increase the post_max_size , and upload_max_filesize to 600M in php.ini. Also I had to change max_execution_time = 600 and to put max_input_vars to 8000 at the end of php.ini configuration in all folders where php.ini resides

2)     I had to run automated backup using command line in order to watch and be sure that the large course I m interesting in having a full backup, will complete successfully.

(Saw the logs also in /moodledata/ – log with 0 bytes means that backup completed successfully.)

3)     I ve downloaded the .mbz file in a local test folder (in a windows pc) and worked with a *copy of the .mbz file* [not the original], changed the extension of the file to .zip. 

Next I Unzipped it. You can then inspect everything contained in the backup.

4)     As Ken Task said in his post https://moodle.org/mod/forum/discuss.php?d=207287#p904178 It *might* be possible to find the largest items and remove them by inspecting 'files.xml' file and removing references to items found in the folder called 'files'.

Here's an example ... of my files.xml there is a reference to:

<file id="35285">

<contenthash>0012fff69e842c5b6b9b8076472743e25401249e</contenthash>

<contextid>9359</contextid>

<component>mod_scorm</component>

<filearea>content</filearea>

<itemid>0</itemid>

<filepath>/course/</filepath>

<filename>1747963.xml</filename>

<userid>5</userid>

<filesize>1358</filesize>

<mimetype>application/xml</mimetype>

<status>0</status>

<timecreated>1371394236</timecreated>

<timemodified>1371394236</timemodified>

<source>$@NULL@$</source>

<author>$@NULL@$</author>

<license>$@NULL@$</license>

<sortorder>0</sortorder>

<repositorytype>$@NULL@$</repositorytype>

<repositoryid>$@NULL@$</repositoryid>

<reference>$@NULL@$</reference>

</file>

 

Someone can see the file name and type above. As explained:

The '00' exactly after the “contenthash” tag appears to be the folder in the “files” folder of the backup and inside this folder are files such as

00ca52c8b73d419e2926e50c38711402b93f6ff1

0012fff69e842c5b6b9b8076472743e25401249e

Etc.. that are the MD5 hash algorithm coded names that moodle uses for the backup files.

Also in <filesize> tag I can see the original file size.

So removing the references in the files.xml file and the '00' folder, then re-zipping, re-naming back to an .mbz file **might** enable a smaller backup thus restorable course.

But as we speak, the “files.xml” happened to be a large xml file (1200KB aprox.) and it would be difficult to search manually and count the size of the files that I would try to exclude from my new backup and after delete them from the folders before re-zipping, re-naming back to an .mbz file.

5)    So I decided to sort this xml by the contents of the subnode <contenthash> and also sort by name in a window the directories inside the folder ‘files’.

When the sorting  the ‘files.xml’ will be done and also the directories will be sorted it would be much easier for me to “cut” the files.xml in 3 or more files and also change the contents of the subfolder ‘files’ (‘00’,’01’,’03’ …) but according to the contents of the files.xml file.

This procedure must be executed with caution because after each “cut” the files.xml file must keep its original filename, that is “files.xml” and the contents of the “files” folder must have only the folders described in “files.xml”.  

For example if the “files.xml” appears to be:

<?xml version="1.0" encoding="UTF-8"?>

<files>

<file id="35285">

<contenthash>0012fff69e842c5b6b9b8076472743e25401249e</contenthash>

<contextid>9359</contextid>

</file>

<file id="49818">

<contenthash>0012fff69e842c5b6b9b8076472743e25401249e</contenthash>

<contextid>13724</contextid>

<component>mod_scorm</component>

</file>

<file id="71604">

<contenthash>01275af52de0724746c1d9a6646597227b9dd17c</contenthash>

<contextid>17567</contextid>

<component>mod_folder</component>

</file>

</files>

Then the contents of the files folder must be 2 folders “00” and “01”. Inside folder “00” must be the “0012fff69e842c5b6b9b8076472743e25401249e” file and inside “01” the “01275af52de0724746c1d9a6646597227b9dd17c” file.

 

So that can be done, by moving the files remaining  in ‘files’ folder to other temporary folders that will not be zipped to the new backup, and the move them back again, etc.

 6)    To make the contents of the ‘files” folder to appear sorted in a window is an easy thing and can be done with a click, but for the sorting of the large file “files.xml” I followed 2 solutions.

At first I used the free tool “Alphabetizer” from codeproject.com (http://www.codeproject.com/Articles/166357/XML-Alphabetizer). A very good tool that I recommend but must be compiled and test with MSBuild if you don’t have last Visual Studio installed.

This gave me a sorted result of my “files.xml” by subnode.

At second, to test again the sorted result and compare them both, i decided to create an .xsl in order to sort the “files.xml”. 

I had to include the lines:

<xsl:apply-templates select="file">
<xsl:sort select="contenthash"/> in my .xsl file

This, gave me the exact sorted content for the “files.xml” as the tool I mentioned before in the form of xml.

The sorted result can be found with a simple browser, but anyway I m using the “xml tools” add-on of the Notepad++ that I find very useful.

7)    After the sort was done my job was easy. I ve made the “cut” to 3 (files.xml & files folder), zipped all the files (inluding the rest of the bakup files that i left intact), uploaded into a repository in moodle , rename them to .mbz. and made the restoring procedure in 3 phases.

Because my full backup was approx 800MB and as I said my system was working fine with 450 MB, each backup I ve created was about 300MB.

8)     By making the restore with “merge” in the same course, some similar activities and resources with no content or broken links appeared, but for each one of them, always exists another with the same name and identity that was working in the same section of the course, so I had to delete everything that appears empty and broken, and finally thats it!.

Hope this helps someone

Any contribution will be appreciated,

Thanks

Average of ratings: Useful (1)
In reply to panagiotis karageorgos

Re: Restoring Large Courses : May be a solution?

by Philippe Decloitre -

Hello,

This is a very interesting topic.

I wonder if someone could say _for sure_ if there is  way to copy a whole (large) course directly from the database where it has been set up (if we have root access of course) and paste it onto another one (with same priviledge).

Would it work?

If so, how to go about it?

Thanks you so much for the time that woulmd be saved!! smile

Philippe

In reply to Philippe Decloitre

Re: Restoring Large Courses : May be a solution?

by panagiotis karageorgos -

Hello and thank you for the reply

Excuse me but if i understand you mean to export a mysql string from the database or to work with folders ?

 

In reply to panagiotis karageorgos

Re: Restoring Large Courses : May be a solution?

by Philippe Decloitre -

I would go for folders but have not tested anyting yet.

Has anyone out there tried it in any way?

 

Thanks for any light on the subject.