V. Restore Drupal site from backup

Just as backing up a Drupal site involves backing up both the database and the Drupal directory, restoring a Drupal site involves restoring the database and restoring the directory. Both are done from the command line using standard Unix commands, but we'll use Drush to get some of the information we need for those commands.

But first, for this workshop, let's change some content so you can see a difference between before and restored. In your web browser, go to your Drupal site and log in (covered in the Set site status to Off-line section of Drupal Workshop, Part 2—Basic configuration, continued), then add a new story (covered in step 6 of the Add sample story content section of Drupal Workshop, Part 2—Basic configuration, continued).

Restore the database

  1. In the command line, change directories to the main Drupal directory. At the end of the previous section, we were in the cgi-bin directory, so at the prompt, we can just type:
    cd yourdrupaldir
    (e.g., cd drpl3a)
  2. We'll use Drush to get information about the database that we'll need for the commands. At the prompt, type:
    drush sql conf
    The result should look something like this:
    Array
    (
    [driver] => mysql
    [username] => gsudtraining1d2
    [password] => secretpassword
    [port] =>
    [host] => 127.0.0.1
    [database] => g_sudtraining1_drupal8
    )
  3. Drop the existing existing database. At the prompt, type:
    mysqladmin -u [username] -h [host] -p drop [database]
    replacing the bracketed words with the corresponding information from the previous step
    (e.g., mysqladmin -u gsudtraining1d2 -h 127.0.0.1 -p drop g_sudtraining1_drupal8)
  4. Enter the database password from step 2 when prompted.
  5. You will get a warning that "Dropping the database is potentially a very bad thing to do." and be asked if you really want to do it. You do. Type y when prompted.
  6. Create a fresh, clean database. At the prompt, type:
    mysqladmin -u [username] -h [host] -p create [database]
    replacing the bracketed words with the corresponding information from step 2
    (e.g., mysqladmin -u gsudtraining1d2 -h 127.0.0.1 -p create g_sudtraining1_drupal8)
    • Tip: The only difference between this command and the previous (step 3) command is that drop had been changed to create. This is where a clever Unix trick comes in handy. Instead of typing out the whole command, just press the up arrow key once to recall the previous command line entry, then use the left arrow key to move the cursor to just after drop, the delete key to delete drop, and then type in create. Make sure there is a single space before and after create, then press the enter key. The result is the same as if you had typed it all out from scratch.
  7. Enter the database password from step 2 when prompted.
  8. Restore/import the backed up database from the .sql backup file. At the prompt, type:
    mysql -u [username] -h [host] -p [database] < ../../DrupalBackups/nameofbackupfile.sql
    replacing the bracketed words with the corresponding information from step 2
    (e.g., mysql -u gsudtraining1d2 -h 127.0.0.1 -p g_sudtraining1_drupal8 < ../../DrupalBackups/drpl3a-drupalworkshop3-2010-01-22-1430-drupal-db.sql)
  9. Enter the database password from step 2 when prompted.
  10. If you get a MySQL error message that is ERROR 1064, don't worry. It has to do with MySQL stuff that doesn't normally affect Drupal. (If you get a different error number, then there may be an actual problem.)

The database is now restored to how it was when the backup was made. Next step: restore the code and files.

Restore the Drupal directory

  1. Change directories to the top level directory for the account. At the prompt, type:
    cd ../..
  2. Remove (delete) the existing Drupal directory. At the prompt, type:
    rm -rf cgi-bin/yourdrupaldir
    (e.g., rm -rf cgi-bin/drpl3a)
  3. Expand the .tar.gz directory backup file into the cgi-bin directory. At the prompt, type:
    tar -xzvf DrupalBackups/nameofbackupfile.tar.gz -C cgi-bin
    (e.g., tar -xzvf DrupalBackups/drpl3a-drupalworkshop3-2010-01-22-0230-drupal-dir.tar.gz -C cgi-bin)
  4. Wait patiently until it finishes.
  5. Note: This is the step that was missing at the Tech Briefing, causing the Upgrader fail.If this site was installed with the Collaboration Tools Installer, restore write permissions to the directory for the Collaboration Tools Upgrader. At the prompt, type:
    fsr sa cgi-bin/yourdrupaldir service.tools write
    (e.g., fsr sa cgi-bin/drpl3a service.tools write)

Your Drupal site is now restored from backup! In your browser, go to your Drupal site. The new story you just added should be gone.