Large course backups fail in Moodle 2

Have you ever encountered this error message whilst backing up a course on Moodle?

Coding error detected, it must be fixed by a programmer: backup_helper::store_backup_file() expects valid $filepath parameter

Or do your automated course backups fail and the error log simply says “Error”.
Then the chances are that your course backup is greater than 2GB.

Having spent several long days trying to solve this, I have finally figured out what the cause of the problem is.

Moodle 2 uses the native ZIP libraries found in PHP to backup a course and zip it up as an archive. The problem here is that this is platform dependent. And large course backups will fail on 32-Bit platforms.

This is due to integers and how they are stored. The technical explanation is that 32-bit platforms can hold a maximum value of two billion, and 64-bit platforms have a max value of 9E18.
PHP does not support unsigned integers and if an integer is greater than the max size supported then it is interpreted as a float instead.

What this means in simple terms is that it runs out of room to store the integer and the backup simply quits.

So does having a full 64-bit Web Server setup fix the problem?

Well, the answer is yes and no.

64-bit Linux platforms work fine, 64-Bit Windows environments do not.
So even if you have a 64-bit Windows Server, running 64-Bit Apache, PHP and MySQL, the maximum integer value that PHP can store is still a 32-bit value.

Why is this you may ask?
It’s because the underlying c-code, long is still 32-bit! Linux uses a 64-bit long and Windows doesn’t.

So how can we work around this?
Simple, run your Moodle installation on a 64-bit Linux System.
However, this isn’t always possible and a lot of organisations, colleges and Universities may have invested heavily in Windows platforms. The organization where I currently work has and we do not wish to switch exclusively to Linux servers.

So we are in the process of installing a single Linux server that will run the system cron and perform the automated backups and copy the backup file back onto the Windows servers.

This is not ideal we know, however, backups are crucial and courses only get bigger. So an additional virtual backup box bolted onto the existing setup is justified in this case.

A better solution in the long term would be for Moodle 2 to support external ZIP clients again, like it used to in Moodle 1. There has been some work done on this with a third party plugin but as it is only Linux based then it doesn’t help. If we were running Linux then we wouldn’t need it!

I hope this article helps other Moodle users in a similar situation and I hope my wasted hours spent on a fix provides you the time to deploy a 64-bit Linux setup.

Previous post Site Wide User Grade Report
Next post New responsive theme project for Leeds College of Music