General help

Course backup fails to start

Picture of Nevin Reid
Course backup fails to start
  I'm new to using Moodle (Moodle 2.1.2+ (Build: 20111019)) and having a problem getting the backup to run on one particular course. We installed back in December 2011 and things were working fine up until after Christmas break when the person putting together the course reported that he could no longer run the backup. I had him create another course to see if it was something in his particular course. This new course backs up fine.
When I select his course and click the Backup option the browser works away for 20 seconds or so and then returns the following error:

Debug info: MySQL server has gone away
INSERT INTO mdl_backup_controllers (backupid,operation,type,itemid,format,interactive,purpose,userid,status,execution,executiontime,checksum,controller,timecreated,timemodified) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => 'd86268a945dca889a4e91acc13ed1782',
1 => 'backup',
2 => 'course',
3 => 2,
4 => 'moodle2',
5 => 1,
6 => 10,
7 => '2',
8 => 500,
9 => 1,
10 => 0,
11 => 'fd9695337d95be6a31527db7f4cb9a28',
12 => 'TzoxNzoiYmFja3... (over 1.3 million characters removed from here)...  MTE6IgAqAGNoZWNrc3VtIjtzOjMyOiJmZDk2OTUzMzdkOTViZTZhMzE1MjdkYjdmNGNiOWEyOCI7fQ==',
13 => 1327582412,
14 => 0,
Stack trace:

    line 397 of \lib\dml\moodle_database.php: dml_write_exception thrown
    line 893 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
    line 935 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
    line 69 of \backup\util\dbops\backup_controller_dbops.class.php: call to mysqli_native_moodle_database->insert_record()
    line 312 of \backup\controller\backup_controller.class.php: call to backup_controller_dbops::save_controller()
    line 137 of \backup\util\ui\base_ui.class.php: call to backup_controller->save_controller()
    line 91 of \backup\backup.php: call to base_ui->save_controller()

Error reading from database
Debug info: MySQL server has gone away
SELECT, AS blockpositionid,
COALESCE(bp.visible, 1) AS visible,
COALESCE(bp.region, bi.defaultregion) AS region,
COALESCE(bp.weight, bi.defaultweight) AS weight,
, AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel, ctx.instanceid AS ctxinstance

FROM mdl_block_instances bi
JOIN mdl_block b ON bi.blockname =
LEFT JOIN mdl_block_positions bp ON bp.blockinstanceid =
AND bp.contextid = ?
AND bp.pagetype = ?
AND bp.subpage = ?
LEFT JOIN mdl_context ctx ON (ctx.instanceid = AND ctx.contextlevel = 80)

(bi.parentcontextid = ? OR (bi.showinsubcontexts = 1 AND bi.parentcontextid IN (?,?)))
AND bi.pagetypepattern IN (?,?,?,?)
AND (bi.subpagepattern IS NULL OR bi.subpagepattern = ?)
AND (bp.visible = 1 OR bp.visible IS NULL)
AND b.visible = 1

COALESCE(bp.region, bi.defaultregion),
COALESCE(bp.weight, bi.defaultweight),
[array (
0 => '21',
1 => 'backup-backup',
2 => '',
3 => '21',
4 => '20',
5 => '1',
6 => 'backup-backup',
7 => 'backup-backup-*',
8 => 'backup-*',
9 => '*',
10 => '',
Stack trace:

    line 394 of \lib\dml\moodle_database.php: dml_read_exception thrown
    line 768 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
    line 599 of \lib\blocklib.php: call to mysqli_native_moodle_database->get_recordset_sql()
    line 1205 of \lib\pagelib.php: call to block_manager->load_blocks()
    line 720 of \lib\pagelib.php: call to moodle_page->starting_output()
    line 607 of \lib\outputrenderers.php: call to moodle_page->set_state()
    line 2026 of \lib\outputrenderers.php: call to core_renderer->header()
    line 328 of \lib\setuplib.php: call to core_renderer->fatal_error()
    line ? of unknownfile: call to default_exception_handler()

Fatal error: Exception thrown without a stack frame in Unknown on line 0

Then only thing that stands out for me is the value in the first query to mdl_backup_controllers for column controller (12 =>) there were over 1.3 million characters in that field. What is this field and could it be the source of my problems?

When I came in this morning and tried it again it returned this same error except at the very top of the page it included a line that it had received a packet larger than the set max_allowed_packet size, which at the time was 10MB. First and last time I've seen this message. I increased it to 32MB and then 64MB, both times got the same error above. I reduced it to 20, 16, 12, back to 10 and then to 1MB and always get the same error now.

Any insight from this community as to what is going on here or how to solve this issue would be much appreciated. Thanks in advance.

Average of ratings: -
Picture of Ken Task
Re: Course backup fails to start
Particularly helpful Moodlers

The first line: MySQL server has gone away tells all and probably causes all that follow.   You were on the right track.

not only max_allowed_packet size increased, but
wait_timeout should be increased

max_allowed_packet= 64M - adjust upwards, not downwards.
wait_timeout= 6000

Please see:

'spirit of sharing', Ken

Average of ratings: Useful (2)
Picture of Nevin Reid
Re: Course backup fails to start

Thanks, Ken, for you quick reply. I added the timeout and upped the packets to 100M. Still nothing. Then I realized that my variables weren't actually being set for some reason, so I had to set them via shell commands.

I ran the backup once more and this time it worked to the point of seeing the side menu but still an error. This time it reported Debug info: Data too long for column 'controller' at row 1, which is were I had thought the problem might be with that 1 million+ character string in the mdl_backup_controllers table.

Setting the datatype on that field to Blob from LongText did not help. Does anyone know what this table is for or where it collects the information for that column? Perhaps there is some way that I can trim it down, although at this point I'm not even getting to the first step of the backup.

Average of ratings: -
Picture of Ken Task
Re: Course backup fails to start
Particularly helpful Moodlers

Am guessing your situation is remotely hosted and the DB resides on another server … not where your Moodle lives.  While you are able to pass parameters via sql statements, it's my understanding that parameters sent to MySQL like that are temporary and lost when the MySQL daemon is restarted.  Only way to set them permanently is to edit cnf file for MySQL.

IF you are on a remotely hosted (shared server), there might be limits which shared customers cannot change.

This is a guess (am still trying to figure out the new file system):
This line:

11 => 'fd9695337d95be6a31527db7f4cb9a28',

Looks to be a hash tag for a file contained in the course.
In filedir of the data folder look for a folder (fd) and contained therein another folder (96).  Contained therein there might be a hashtag named file that is 1327582412 in size.

12 => 'TzoxNzoiYmFja3... (over 1.3 million characters removed from here)...  MTE6IgAqAGNoZWNrc3VtIjtzOjMyOiJmZDk2OTUzMzdkOTViZTZhMzE1MjdkYjdmNGNiOWEyOCI7fQ==',

If you notice, your comment above looks related to the next value below

13 => 1327582412,
(file size?)

In the course, is there a large file linked?  Got a copy of that file somewhere else?  If so, remove the file from the course and also in any other course where that file is available in the Moodle interface.  Do NOT remove the folders/files manually in filesdir.  To be honest, not sure how one forces the 'trash' to empty on version 2 of Moodle - am thinking cron job is supposed to clean up and remove the DB record.   Once that file is no longer referenced, then try the backup.

Is there any reference for hash type folders/files or xml files in data folder, temp, backup?

If I'm really 'off base' here maybe someone with more knowledge and experience with similar issues (a true DB Administrator) would be so kind as to jump in and correct suggestions!

'spirit of sharing', Ken

Average of ratings: -
Picture of Moisés Martínez Moreno
Re: Course backup fails to start

Hello everybody,

I just want to contribute my own experience with this issue:

  1. The Moodle environment version where I reproduced the problem is Moodle 1.9.10+ (Build: 20110112).
  2. The plataform has been working during two years and never got this problem before.
  3. Today I had to backup some courses and I got the same problem like initial poster told: Course backup fails.
  4. I tried what Ken Task mentioned about increase max_allowed_packet from 1MB (i think this is a very low value) to 16MB.
  5. Everything worked perfectly. The backups ran without errors.

The database works with some other Moodle plataforms, so i think i should increase the value of max_allowed_packet permanently.

I hope this help anyone who gets the same problem with Moodle 1.9.x and Moodle 2.x.



P.D.: I'm sorry, my English is not very good. I hope you to understand all well.

Average of ratings: Useful (3)