Backing Up / Restoring Moodle

I've been maintaining a moodle server for some time now, and have backed up and restored my data a few times. Since I've not blogged about it before, I've not a got a reference on how to do it, until now!

Uploaded images and other files are stored under /var/ftp/pub. They are backed up with:

tar cvzPf moodle.ftp.tar.gz /var/ftp/pub

and restored with:

tar xvP moodle.ftp.tar.gz

The other data for moodle resides in a mysql database. I know I used this reference page from http://dev.mysql.com/doc/refman/5.1/en/backup-and-recovery.html.

To backup the database use:

mysqldump moodle -u root -p > moodle.mysqldump

After installing mysql and setting a root password for it, I login to mysql as root and create the moodle database and user, then restore the file.

# mysql -u root -p
> create database moodle;
> grant all on moodle.* to dbuser@localhost identified by 'password';
> quit
# mysql moodle -u root -p < moodle.mysqldump
Password: ******


Keith Wright said...

I ran into a problem with restoring a database where I received an error due to a packet being too large. The fix I found required both a server and client configuration change. For the mysqld server, I added to the /etc/my.cnf file the following line:


Remember to restart the mysqld after making this change to the server. For the client, I ran the restore with this command:

# mysql moodle -u root --max_allowed_packet=64M -p < moodle.mysqldump

Keith Wright said...

Another problem that you may run into with Moodle is after restoring the data files for /var/www/moodle (or wherever), that the user identity that runs the web server will need to have write permission in order for sessions to work. I think I used something like the following for setting permissions and ownerships:

find /var/www/moodle -type d -exec chmod 755 {} \;
find /var/www/moodle -type f -exec chmod 644 {} \;
chown -R apache /var/www/moodle

About Me - WrightRocket

My photo

I've worked with computers for over 30 years, programming, administering, using and building them from scratch.

I'm an instructor for technical computer courses, an editor and developer of training manuals, and an Android developer.