Backup and restore FAQ
- 1 How do I backup a course?
- 2 How do I backup my site?
- 3 Backup stops at Zipping backup
- 4 What are the pros and cons of course versus site backups?
- 5 What data is not contained in course backups?
- 6 The process ends with: "Error: An error occurred deleting old backup data". What should I do?
- 7 The process ends with: "XML error: not well-formed (invalid token) at line YYYY". What can I do?
- 8 I Still get an XML error. How can I clean the borked XML file?
- 9 What does "Some of your courses weren't saved!!" mean?
- 10 How can I restore pre 1.6 non-ISO-8859-1 backups to Moodle 1.6 (Unicode)?
- 11 Restoring a course results in broken HTML tags. What can I do?
- 12 Why are some courses being skipped?
- 13 Why does restore stop, rather than completing?
- 14 See also
How do I backup a course?
How do I backup my site?
See Site backup.
Backup stops at Zipping backup
Moodle 1.9 and lower use a PHP library to zip files that isn't very efficient and struggles to zip/unzip large files. You can use an external Zip binary to use a different process to handle your files - you can set this in Admin > Server > System Paths Moodle 2.0 uses new PHP zip functions so that specifying an external Zip binary isn't necessary see System_paths#Path_to_zip for help configuring an external zip binary.
What are the pros and cons of course versus site backups?
Site backups are recommended in order to have all data saved with the best confidence and the shortest recovery time.
Automated course backups are more expensive in terms of time and CPU usage. The recovery time to have your site running again is longer. Course backups are useful for obtaining "fresh" copies of courses to be re-used or distributed individually, however they should never be used as a primary backup system (unless your hosting doesn't allow the preferred site backups).
What data is not contained in course backups?
By selecting all the options when setting up the backup you can include almost all the data in the course. However you should be aware of the fact that some things are not backed up:
- Quiz questions are only backed up if at least one question from their category has been added to a quiz.
- Scales are only backed up if they are used by at least one activity.
The process ends with: "Error: An error occurred deleting old backup data". What should I do?
This part of the backup (or restore) procedure tries to delete old info, used in previous executions, performing the following tasks:
- Delete old records from "backup_ids" table: Check the table exists, repair it and try again.
- Delete old records from "backup_files" table: Check the table exists, repair it and try again.
- Delete old files from "moodledata/temp/backup": Delete the dir completely and try again.
For point 3 see below:
The error message states that the "directory not empty" and gives the path to that directory. If you go there with an FTP program you can see what is there and clean up. It could be just some empty subfolders that were leftover. Deleting these has been able to help. One can also delete the dir "moodledata/temp/backup" completely. That can take a bit longer but may solve several problems at once.
The process ends with: "XML error: not well-formed (invalid token) at line YYYY". What can I do?
This problem can appear at any point in the restore process. It's caused when the XML parser detects something incorrect in the backup file that prevent correct operation. Usually, it's caused by some "illegal" characters added in the original course due to some copy/paste of text containing them (control characters, or invalid sequences...).
The best method to handle this issue is:
- Unzip the problematic backup file under one empty folder.
- Open the moodle.xml with Firefox. It will show you where (exact char) the problem is happening.
- Edit the moodle.xml file with some UTF8-compatible editor and delete such characters. Save changes.
- Test the moodle.xml file again with Firefox until no error was displayed.
- Zip everything again (all the folder contents but not the folder itself!).
- Restore the course. It should work now.
- Restore still not working? See the next question.
Also, if possible, it's highly recommended to solve those problems in the original course too from Moodle itself. Once "repaired" there, problems will be out if you create new backup files in the future.
I Still get an XML error. How can I clean the borked XML file?
In some cases XML backup files may contain characters causing the restore process to abort, even after the steps described in the previous question. In such cases you may want to try the following:
- Unzip the problematic Moodle backup file under one empty folder. Moodle will create the course file folders as long as the unclean moodle.xml file. Please unzip using the Moodle unzip feature.
- Rename the unclean moodle.xml file to moodle-unclean.xml.
- If you don't have access to your Moodle server's command prompt, using the Moodle zip feature, zip the moodle-unclean.xml file only, download the zip file locally and unzip it. It is very important to download the xml file in zipped format to avoid unwanted character encoding when transferring from an operating system to another.
- Move the downloaded Atlassian XML Cleaner Utility in the same folder where is your moodle-unclean.xml file.
- Issue the following command from the command prompt:
java -jar atlassian-xml-cleaner-0.1.jar moodle-unclean.xml > moodle.xml
- If you launched the utility on your local computer, zip the just created (and hopefully cleaned) moodle.xml file and upload it in the same place from where you downloaded the moodle-unclean.xml file. Once uploaded, unzip it using the Moodle unzip feature.
- Zip everything again (all the folder contents but the folder itself!).
- Restore the course. It should work now.
What does "Some of your courses weren't saved!!" mean?
There are three possible causes of this problem:
- Error - this happens when the backup procedure has found an error and so hasn't finished the backup of a particular course. These are "controlled" errors and the scheduled backup continues with the next course.
- Unfinished - this happens when the backup procedure dies without knowing why. When the cron is next executed it detects that the last execution went wrong, and continues skipping the problematic course. A possible solution would be to raise the PHP/Apache limit in your installation (memory, time of execution...). By taking a look to your log tables you should be able to see if the "crash" is happening at exact time intervals (usually a problem with the max_execution_time php's variable), or if there is some exact point were all the courses are breaking (generally internal zip libraries, try to switch to external executables instead).
- Skipped - this happens when a course is unavailable to students and has not been changed in the last month (31 days). This isn't an error situation - it's a feature, especially useful for sites with many unavailable old courses, saving process time.
How can I restore pre 1.6 non-ISO-8859-1 backups to Moodle 1.6 (Unicode)?
Any backup files with contents which are not 100% ISO-8859-1 will be a problem to restore to Moodle 1.6 (and upwards) running under Unicode. Instead, please try the following:
- Make a clean install of Moodle 1.5.x (the latest version available)
- Restore all your courses there (they should work if they were working originally)
- Upgrade your site to Moodle 1.6 and run the UTF-8 migration script
- Backup your courses again
This will produce a new set of backup files that will be 100% UTF-8 and you will be able to use them with Moodle 1.6 without any problems.
This problem is due to a PHP bug in libxml2 2.7.1 (the same bug reported with version 2.7.2 and 2.7.3). All HTML entities, such as >, < and " are removed when a course is restored.
To resolve the problem, you should use a different version of libxml2 such as 2.7.0 or 2.6.32 or compile PHP against libexpat instead of libxml2.
At Gentoo servers, you can use
echo ">dev-libs/libxml2-2.6.32" >> /etc/portage/package.mask
See the discussion Restoring makes webpages and labels in code for further information.
Why are some courses being skipped?
From 1.6 onwards, course backups automatically skip courses which are unavailable to students and have not been changed in the last month.
Why does restore stop, rather than completing?
Attempting to restore a course to an older version of Moodle than the one the course was backed up on can result in the restore process failing to complete. To ensure a successful restore, make sure that the version of Moodle you are restoring the course to is the same, or newer, than the one the course was backed up on.
- Using Moodle Backup and Restore forum
- databasejournal.com article on repairing database corruption in MySQL
Using Moodle forum discussions: