Backup and restore FAQ
- Site backups
- Site backups, as explained in upgrading Moodle, are recommended in order to have all data saved with the best confidence and the shorter recovery time.
- Course backups
- Course backups, configured on the backup page, 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).
How do I backup my whole Moodle site?
There are two main things you need to make a copy of - the database and the uploaded files. The Moodle scripts themselves are less important, since you can always download a fresh copy if you have to.
There are many ways to do such backups. Here is an outline of a little script you can run on Unix to backup the database (it works well to have such a script run daily via a cron task):
mv moodle-database.sql.gz moodle-database-old.sql.gz
mysqldump -h example.com -u myusername --password=mypassword -C -Q -e -a mydatabasename > moodle-database.sql gzip moodle-database.sql
For the files, you can use rsync regularly to copy only the changed files to another host:
rsync -auvtz --delete -e ssh email@example.com:/my/server/directory /my/backup/directory/
Error: An error occurred deleting old backup data
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.
There are various ways of repairing tables, including using MySQL Admin.
Some of your courses weren't saved!!
There are two possible causes of this problem:
- 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.
- 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).