Site restore: Difference between revisions

From MoodleDocs
mNo edit summary
(→‎Change site identifier: Reworded to make it clearer a new siteidentifier is only needed for site copies.)
 
(3 intermediate revisions by 3 users not shown)
Line 18: Line 18:


2. If you are running MySQL, a backup of the database should be a .sql, .gz or .tar.gz file.  If it is .tar.gz or .gz you need to extract it until it is an sql file.
2. If you are running MySQL, a backup of the database should be a .sql, .gz or .tar.gz file.  If it is .tar.gz or .gz you need to extract it until it is an sql file.
If originally created with tar, also extract it with tar:


  tar -xzvf moodlesqlfile.tar.gz
  tar -xzvf moodlesqlfile.tar.gz


If originally created with gzip, extract it with gunzip:
gunzip moodlesqlfile.sql.gz
3. If you are running mysql, import the SQL file back into a newly created database on the MySQL server.  Be careful here, some backups try to import right back into the same working database that Moodle is connected to.  This causes database problems that damage a Moodle installation.  The best thing to do is make a new database, restore the backed up database into it, and change the Moodle '''config.php''' file to connect to this new database (this way you still have the original database).
3. If you are running mysql, import the SQL file back into a newly created database on the MySQL server.  Be careful here, some backups try to import right back into the same working database that Moodle is connected to.  This causes database problems that damage a Moodle installation.  The best thing to do is make a new database, restore the backed up database into it, and change the Moodle '''config.php''' file to connect to this new database (this way you still have the original database).


Line 38: Line 42:
# Open the database to restore
# Open the database to restore
# Click the SQL tab.
# Click the SQL tab.
# On the "SQL"-page , unclick the show query here again.
# On the "SQL"-page, unclick the show query here again.
# Browse to your backup of the database.
# Browse to your backup of the database.
# Click Go.
# Click Go.
== Change site identifier ==
If this a clone of the original site – for example, a test copy of a live site – generate a new identifier for the new site after restoring:
# Delete the 'siteidentifier' record in <code>mdl_config</code>, for example, using <code>DELETE FROM mdl_config WHERE name = 'siteidentifier'</code>. Change 'mdl_' if the site has a different <code>$CFG->prefix</code>.
# [[Developer_tools#Purge_all_caches|Purge all caches]].
This prevents problems mapping users when restoring course backups from the original site.


== See also ==
== See also ==

Latest revision as of 13:27, 6 September 2024


If you have followed the Site backup instructions and created a backup of a Moodle site, you may need to know how to restore the site backup you created.

There are 3 areas that could be restored individually or together:

  • Moodle code
  • Moodle uploaded or created files
  • Moodle database - MySQL, Progres or other

The location and names of these areas can be found in the Configuration file.

Command line (linux) restore

Here is a set of basic steps that make up the restore process.

1. Rename the original Moodle directory to something different (so you still have it) and copy the backed up Moodle directory or a newly downloaded Moodle directory in its place.

2. If you are running MySQL, a backup of the database should be a .sql, .gz or .tar.gz file. If it is .tar.gz or .gz you need to extract it until it is an sql file.

If originally created with tar, also extract it with tar:

tar -xzvf moodlesqlfile.tar.gz

If originally created with gzip, extract it with gunzip:

gunzip moodlesqlfile.sql.gz

3. If you are running mysql, import the SQL file back into a newly created database on the MySQL server. Be careful here, some backups try to import right back into the same working database that Moodle is connected to. This causes database problems that damage a Moodle installation. The best thing to do is make a new database, restore the backed up database into it, and change the Moodle config.php file to connect to this new database (this way you still have the original database).

Once you have created the new database:

mysql -p new_database < moodlesqlfile.sql

For other databases, follow their instructions for restoring a backup.

Tools for site backup and restore

  • phpMyAdmin
  • MySQLdump

Tools for backing up data files

Restore with phpMyAdmin

Restoring a backup of a MySql database

  1. Open the database to restore
  2. Click the SQL tab.
  3. On the "SQL"-page, unclick the show query here again.
  4. Browse to your backup of the database.
  5. Click Go.

Change site identifier

If this a clone of the original site – for example, a test copy of a live site – generate a new identifier for the new site after restoring:

  1. Delete the 'siteidentifier' record in mdl_config, for example, using DELETE FROM mdl_config WHERE name = 'siteidentifier'. Change 'mdl_' if the site has a different $CFG->prefix.
  2. Purge all caches.


This prevents problems mapping users when restoring course backups from the original site.

See also