Skip to content Skip to navigation

Back Up Drupal from the Command Line

Posted by: 
Topics: 

Seriously, the command line isn't that scary. Just follow along with this short screencast.

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.

Back up the files

  1. Enter the following text at the command prompt and then hit Enter:
    cp -r /afs/ir/group/groupname/cgi-bin ~/DrupalBackups/todaysdate
    • (This presumes that the DrupalBackups directory already exists.)
    What this command does, broken down into its component parts:
  • cp: the copy command
  • -r: tells the copy command to act recursively, that is, copy files, directories, and all their contents
  • /afs/ir/group/groupname/cgi-bin: the source directory path
  • ~/DrupalBackups/todaysdate: The destination directory path. In this case, it's a DrupalBackups/todaysdate subdirectory within your home AFS directory. (If a directory of that name already exists, a copy of the source directory will be made within it, e.g., DrupalBackups/todaysdate/todaysdate).
  • Don't forget the space in between the source and the destination paths
  • Note that there is no slash / at the end of the directory names for this command

Back up the database

  1. Enter the following text at the command prompt and then hit Enter:
    mysqldump -u databaseusername -h mysql-user.stanford.edu -p drupal_database_name > ~/DrupalBackups/todaysdate/drupal_database_name.sql
  2. Enter your database user password when prompted
    What this command does, broken down into its component parts:
  • mysqldump: The mysqldump command creates a backup of a MySQL database
  • -u databaseusername: The u option allows you to declare a user name. This is the user name you received when you set up your MySQL service. (Hint: If you have no idea what the database user name and password are, you can go to /afs/ir/group/groupname/db_private/db_info. That's a text file that has your initial database user name and password.)
  • -h mysql-user.stanford.edu: The h option allows you to declare a MySQL host, in this case mysql-user.stanford.edu
  • -p: The p option forces the mysqldump command to prompt you for a password
  • drupal_database_name: This is the name of your drupal database
  • >: This redirects the output of the mysqldump command to a file
  • ~/DrupalBackups/todaysdate/drupal_database_name.sql: The path and filename of the file to which you are redirecting the output of the mysqldump command

BAM! You've got a backup of your Drupal installation!

[Original post by John Bickar, modified by Sharon Krossa]