I recently moved a number of Drupal sites to a new server and found the following drush commands to be particularly helpful in streamlining the process.
Place the current site in maintenance mode. This prevents users from updating content or data on the site during the move.
drush vset maintenance_mode 1
Clear the Drupal cache. This will reduce the size of the database file that needs to be moved. It also eliminates cached paths which may change. Select the "all" option.
If you are using database logging (dblog module), you may wish to further reduce the size of the database by clearing the watchdog table. This table can be quite large. Be sure to backup your database before clearing these logs. You can also use severity or type arguments to selectively delete less critical entries. Use "wd-list" to see all types and severity levels.
drush wd-list drush wd-del --severity=notice drush wd-del --type=cron drush wd-del all
Dump the cleaned database to a file.
drush sql-dump --result-file=prod_db.sql
I prefer moving the database and files separately and deploying code directly from a source code repository. However, you can use drush to archive the sites code, files and database into a single file, which can be easily moved to another server.
drush archive-dump --destination=./example.tar.gz
Once the file is move to the new server, restore it.
drush archive-restore ./example.tar.gz --destination=/var/www/example.com/docroot --db-url=mysql://root:firstname.lastname@example.org/dbname
Setup drush aliases on the new server. I recommend storing them in /etc/drush/aliases.drushrc.php.
<?php $aliases['prod1'] = array( 'root' => '/var/www/prod', 'uri' => 'prod1.example.com', ); $aliases['prod2'] = array( 'root' => '/var/www/prod', 'uri' => 'prod2.example.com', );
Validate that your Apache, PHP and MySQL configurations are correctly set in the new environment.
drush @prod1 status
You may need to update File System paths to reflect differences in the new environment. In this case, I was moving a number of separate sites into a single multi-site Drupal environment. So the paths needed to change from "sites/default/files" to "sites/domain.name.com/files". Also, the temporary directory may be in a different location on the new server.
drush @prod1 vset file_public_path "sites/prod1.example.com/files" drush @prod1 vset file_private_path "sites/prod1.example.com/files/private" drush @prod1 vset file_temporary_path "/tmp"
Run cron in the new environment.
drush @prod1 cron
Validate that your new site meets Drupal requirements and look for any issues by viewing the Status Report.
drush @prod1 status-report or drush @prod1 rq
Disable maintenance mode in the new site. Maintenance mode remains enabled in your old environment, ensuring that users are only able to modify data on the new server if their DNS has not yet been updated.
drush @prod1 vset maintenance_mode 1