Sauvegarde de site

Révision de 29 décembre 2013 à 17:37 par Nicolas Martignoni (discussion | contributions) (Début du travail (nouvelle page))

(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

Attention : vous consultez actuellement la documentation dédiée aux versions 2.x de Moodle. La documentation pour les versions 3.x de Moodle est consultable ici : Sauvegarde de site.

Remarque : cet article est en cours de rédaction. N'hésitez pas à le compléter. Veuillez utiliser la page de discussion ou un forum adéquat de Moodle en français pour vos recommandations et suggestions d'améliorations.

Une sauvegarde de site permet à l'administrateur d'un site d'enregistrer la totalité des données associées à un site Moodle. Les sauvegardes peuvent être restaurées afin de reconstituer un site dans l'état-même où il se trouvait au moment où la sauvegarde à été effectuée.

Il est vivement recommandé d'effectuer des sauvegardes de manière régulière afin de réduire la quantité de données perdues dans l'éventualité d'un problème sur le site et pour rendre plus rapide l'éventuel processus de restauration.

Qu'est-ce qui doit être sauvegardé ?

Un système Moodle comprend trois parties :

  1. les données stockées dans la base de données (par exemple une base de données MySQL) ;
  2. les fichiers déposés par les utilisateurs (par exemple les fichiers de cours déposés), stockés dans le dossier moodledata ;
  3. le code source de Moodle (tout ce qui est stocké par exemple dans le dossier server/htdocs/moodle.

You can confirm where all these things are located in a Moodle installation by checking the config.php file.

  1. $CFG->dbname shows the database name
  2. $CFG->prefix shows the the database table name prefix
  3. $CFG->dataroot controls where the uploaded files are stored; and
  4. $CFG->wwwroot points to where the code is stored.

Generally speaking, the database ("dbname and prefix") and the uploaded files (dataroot) are the two most important to copy on a regular basis. These contain information that will change most often.

The Moodle code (wwwroot) is less important as a frequent backup, since it will only change when the the actual code is changed through upgrades, addins and code tweaks. You can always get a copy of the standard Moodle code from so you only have to backup the parts you added or changed yourself.

Creating a backup of your Moodle site


The right way to back up your database depends on which database system you are using. The instructions below are one way to back up a MySQL database. Another option would be to use a tool like phpMyAdmin to manually make a backup. The documentation for your database will give more options.

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):

cd /my/backup/directory
mv moodle-database.sql.gz moodle-database-old.sql.gz
mysqldump -h -u myusername --password=mypassword -C -Q -e --create-options mydatabasename > moodle-database.sql
gzip moodle-database.sql

Character encoding

Make sure that a database backup uses the correct character encoding. In most databases, use UTF-8.

When dumping the entire Moodle database, check for possible character encoding issues. In some instances, backups created with mysqldump or phpMyAdmin may not properly encode all of the data. This will result in non-readable characters when the database is restored.

Tip: One solution is to use MySQL Administrator 1.1 or another tool that will force a UTF-8 dump of the data.

Tools for database backups

phpMyAdmin is the tool of choice with most web hosting providers.
MySQLDumper is a backup script for MySQL databases, written in PHP and Perl. MySQLDumper uses a proprietary technique to avoid execution interruption when running PHP scripts (the max. execution time is usually set to 30 seconds). MySQLDumper also cares for the encoding problems mentioned above. It also works with compressed files and allows setting up regular cron jobs for updating and updating to a remote FTP site.

Uploaded files (moodledata)

Through the Moodle interface, users can upload or create files and folders. These are located in a directory, often called "moodledata". Since they are just files and folders, there are many different ways to backup or copy moodledata.

  • For example, using a file transfer program, copy the entire moodledata directory to a different area, drive or computer. Example of file transfer programs include: FTP, WinSP, wget, rsync.
  • You might use a compression program to create compact files (tar, zip. 7z, XZ, BZIP2, GZIP, and WIM are a few file formats) of the entire directory. This can be done before or after file transfers.
  • Typically not all moodledata files change between regular/periodic backups. A new Administrator might want to look into incremental or other efficient backups procedures.
  • Depending upon the operating environment there are many tools for backing up server files and ways of backing up moodledata. See Tools_for_backing_up_server_files for tips on using rsync, FTP or Wget.

Moodle code

Backing up the Moodle code, will be similar to backing up moodledata. See Tools for backing up server files.


It is always a good idea to have several backup copies of your Moodle code files. While you can always download a fresh base copy of the Moodle code from, you might have customized that code. It is a good idea to create a separate backup of your Moodle code before you customize the code. This includes installing Contributed code, Themes and upgrading.

See also