Backup and restore Drupal sites with Drush
Submitted by abhishek on Thu, 11/08/2012 – 17:10
Drush is a really great tool! It provides two very useful commands to perform backup and restore operations on Drupal sites. Previously we had to create and restore sql dump and files tarball manually. With new Drush it’s really easy.
Please check you Drush version. This text was written for Drush 4.5.
The simplest way to make backup is to run Drush command inside drupal root.
If you have a record with root key in your aliases.drushrc.php file you don’t need enter Drupal root directory.
Let’s look inside out tarball.
Great! We have here all files from the Drupal root path, database dump and MANIFEST.ini. Here listing of MANIFEST.ini:
As we see, MANIFEST.ini includes really useful information about archive. So, we can have a good night’s sleep, we have our backup. Now let’s try to restore it.
Why so many errors? There are some problems in our command:
- Destination directory is already exists. Drush can’t overwrite it.
- Current system user has no permissions for some operations.
- Database is already exists. MySQL user from settings.php file has no permissions to drop database and create new.
Let’s look at the next command. It will correctly restore the archive.
- –db-su – account to use when creating the new database.
- –db-su-pw – password for the “db-su” account.
- –overwrite – allows Drush to overwrite any files in the destination.
Last command is to long. No problem! We can create site alias with command specific settings. Let’s add next lines to our aliases.drushrc.php.
Now we have a very neat command to restore the site from the archive.