Full backup of an LMS platform

A Moodle™ website backup allows the administrator of the same to save everything related to the Moodle site. These backups can be restored to return the site to the point it was at when the backup was made, or to move the complete Moodle to another server™.
Performing full backups periodically is highly recommended to reduce lost information in case of a problem on the site and to accelerate the general recovery process.
You already know that you can backup courses, manually or automated, and restore those courses (with all their contents and even all their users -students and teachers-) in the same Moodle or in another, but it is also convenient to make full backups of the Moodle™ platform, which allows you to recover it in case of catastrophic failure, or to install your Moodle™ on another server.
What is necessary to make a backup?
A system with Moodle™ is composed of three parts:
- The data stored in the database (For example, a MySQL database)
- The uploaded files (For example, the site and course files uploaded by Moodle™ in moodledata)
- The Moodle™ code, its «executable» so to speak (For example, everything in server/htdocs/moodle)
- You can confirm where all these things are located in a Moodle™ installation by checking the configuration file config.php.
- $CFG->dbname shows the name of the database
- $CFG->prefix shows the name of the database table prefix
- $CFG->dataroot controls where uploaded files are stored (uploaded files, for example, images and PDF files used in courses)
- $CFG->wwwroot points to where the code (the executable) is stored.
Tip
- In general terms, the database («dbname and prefix») and the uploaded files (dataroot) are the most important to copy regularly. These contain the information that will change most often.
The Moodle™ code (wwwroot) is less important as a frequent backup, as it will only change when the actual code changes with updates, installed extensions and plugins. You can always get a copy of the standard Moodle™ code from https://download.moodle.org so it is only necessary to copy the parts that we have added or changed ourselves.
Creating a backup of your Moodle site
Database
The correct way to make a database backup depends on the database system being used. The following instructions are a way to make a backup of a MySQL database. Another option would be to use a tool like phpMyAdmin to make a manual backup. The documentation for your database will have more options.
There are many ways to make these backups. Here is an outline of a small script that can be run on Unix to make a database backup (it works well to have such a script running daily through a cron task):
cd /my/backup/directory
mv moodle-database.sql.gz moodle-database-old.sql.gz
mysqldump -h example.com -u myusername --password=mypassword -C -Q -e --create-options mydatabasename > moodle-database.sql
gzip moodle-database.sql
Character Encoding
Ensure that the database backup uses the correct encoding. UTF-8 is used in most databases.
When the entire Moodle database is dumped, you need to check for possible character encoding issues. In some instances, backups created with mysqldump or phpMyAdmin may not encode all data correctly. This will result in unreadable characters when the database is restored.
Tip: One solution is to use MySQL Administrator 1.1 or another tool that forces a dump of the data in UTF-8.
Database backup tools
phpMyAdmin
phpMyAdmin is very simple and is surely available from your web hosting control panel.
MySQLDumper
: MySQLDumper is a backup script for MySQL databases, written in PHP and Perl. MySQLDumper uses its own technique to avoid interruption of execution when running PHP scripts (the maximum execution time is usually set to 30 seconds in most web hostings). MySQLDumper also handles the aforementioned encoding issues. It also works with compressed files and allows configuring regular cron update jobs and updating a remote FTP site.
AutoMySQLBackup
AutoMySQLBackup is a backup script for MySQL databases, written in PHP. AutoMySQLBackup will create Daily, Weekly, and Monthly backups of one or more of your MySQL databases from one or more of your MySQL servers. Features include email notification, compression and encryption, configurable backup rotation, incremental database backups and more.
Uploaded files (moodledata)
Through the Moodle interface, course creators, teachers and other types of users can upload or create files and folders. These are located in a directory, often called “moodledata” (it is its default name, but as you know you can give it whatever name you want). Since these are just files and folders, there are many different ways to make a backup or copy moodledata.
For example, using a file transfer program, you can copy the entire directory moodledata to a different site, disk or computer. Examples of file transfer programs include: FTP, WinSP, wget, rsync.
You can use a compression program to create compact files (tar, zip, 7z, XZ, BZIP2, GZIP, and WIM are some formats) of the entire directory. This can be done before or after the file transfer.
Tips
Generally not all files in moodledata change between periodic/regular backups. Since this directory, in Moodle with extensive courses or with many courses, is usually large, it may be a good idea to perform incremental backups or other types of efficient backups.
Depending on the operating environment there are many tools to perform server file backups and many ways to copy moodledata, using tools like using rsync, FTP or Wget.
Moodle code
Backing up Moodle code will be similar to copying moodledata.
Tip
It is always a good idea to have several copies of the Moodle code files. It is true that you can always download a new copy of the Moodle base code from http://download.moodle.org, but that code may have been customised or changed, or extensions such as plugins or themes may have been added, and in this case those changes would be lost. It is a good idea to create separate backups of your Moodle code always before customising the code. This includes installing extensions that you can install, Themes and updates.
