Skip to content Skip to navigation

Restore Drupal from a Backup

Posted by: 
Topics: 

So now you've hit the point every Drupaller fears: your site has crashed, and you need to restore it. When was the last time you backed it up?

Fortunately, if you've installed Drupal in AFS space, both the files and the database get backed up nightly (yay!), shortly after midnight. (If you want to make an intra-day backup, see this guide.)

There are two steps to this process:

  1. Restoring the database
  2. Restoring the files

You can do this using Terminal on the Mac (in /Applications/Utilities) or using SecureCRT on the PC.

Connect to Corn

  1. Enter the following text at the command prompt and then hit Enter:
    • ssh sunetid@corn.stanford.edu
  2. Enter your SUNet password when prompted.

Drop the (corrupt, existing) Database

  1. Enter the following text at the command prompt and then hit Enter:
    • mysqladmin -u databaseusername -h mysql-user.stanford.edu -p drop drupal_database_name
  2. Enter your database password when prompted.

Create a (so fresh and so clean, clean) New Database

  1. Enter the following text at the command prompt and then hit Enter:
    • mysqladmin -u databaseusername -h mysql-user.stanford.edu -p create drupal_database_name
  2. Enter your database password when prompted.

Restore from the .sql Backup File

  1. Enter the following text at the command prompt and then hit Enter after each line:
    • cd /afs/ir/group/groupname/db_private
    • gunzip drupal_database_name.sql.0.gz
    • mv drupal_database_name.sql.0 drupal_database_name.sql
    • mysql -u databaseusername -h mysql-user.stanford.edu -p drupal_database_name < drupal_database_name.sql
  2. Enter your database password when prompted.

Note About Error Messages
If, in restoring your database from the .sql backup, you encounter an error such as:
ERROR 1064 at line 2533: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1

do not fear. It refers to stored routines in a MySQL database, which Drupal typically does not use. The error should not stop your restore from working. For more information, search the drupallers listserv at https://mailman.stanford.edu/mailman/suprivate/drupallers/

Delete and Restore Your Files:
Enter the following text at the command prompt and then hit Enter after each line:

  • rm -fr /afs/ir/group/groupname/cgi-bin/drupal
  • cp -r /afs/ir/group/groupname/.backup/cgi-bin/drupal /afs/ir/group/groupname/cgi-bin/

Congratulations! You can breathe easy again!