Use Drush to Upgrade from Drupal 6 to Drupal 7

Moshe Weitzman's picture

The Drush site-upgrade command supports upgrades from Drupal 6.x to Drupal 7.x. If you are just doing a minor version upgrade (e.g. 6.20 to 6.21), please use drush pm-update instead.

To begin, make sure that your current Drupal installation is running the most recent version of Drupal 6.x (currently 6.22). The most recent version is listed on the Drupal project page

Upgrade a Copy of your Site

site-upgrade always upgrades from the current Drupal site to an empty Drupal site. Drush never alters your source site, so it is safe to run this command from within your production site. It is necessary to create a site alias to describe the destination site. Site aliases are described in drush topic docs-aliases. A canonical site alias is adequate to define your target site for upgrade:

$aliases['onward'] = {
  'root' => '/path/to/upgraded/drupalroot',
  'uri' => 'http://onward.mysite.org',
}

Optionally, you might also want to define a db_url to specify the name of your target database. If you do not, drush will compose a database name for you based on the name of your site alias.

Running the Site-upgrade Command

Drush will upgrade the current bootstrapped site (D6), and will put the result in the target site specified by the argument to the command. For example:

drush site-upgrade @onward

The site-upgrade command will perform the following operations:

  • Download latest stable release of Drupal 7 and store the files in the target site.
  • Write a new settings.php file with an appropriate databases structure for the new target site.
  • Make a copy of the SQL database for the new site.
  • The default theme for the new site will be set to Garland", and the admin theme will be set to Seven.
  • All non-core extensions will be disabled in the target database, and updatedb will be run on Drupal core.
  • All of the modules disabled in the previous step will be downloaded again, if they have a release for Drupal 7 (a dev snapshot is OK).
  • drush updatedb will be run again to update the non-core modules.
  • All of the non-core modules will be enabled again.

Before Drush begins this process, it will first print out a list of warnings for any modules that may not be ready to upgrade yet. Please read all of these messages carefully before proceeding. Here are some of the situations you may encounter.

  • If a module has no recommended release, then drush will continue, downloading an available release for the upgrade.
  • If a module has no release at all, then Drush will skip it. The module's data will remain in the database.
  • You may discover that some modules, such as date_api, might cause the Drupal core updatedb to fail. In this instance, you may use the --uninstall option to list the modules to uninstall prior to upgrade. Modules uninstalled in this manner will have all of their data removed from the target database; the database of the source site is not affected.

When Drush is enabling the modules in the upgraded site, if there are any new dependencies, they will also be identified and downloaded if possible. For example, views-7.x depends on the ctools module from the Chaos tool suite, whereas views-6 did not; drush will therefore download and enable ctools when upgrading the Views module from Drupal 6 to Drupal 7.

There will still be some work left to do after the site-upgrade command has completed; for example, you will still need to port your theme and any custom modules to the new version of Drupal, and some contrib modules may require additional work to update their configuration settings. Using site-upgrade will save you a considerable amount of time. There is no risk in trying it; if it does not work, you can always start over, or run it at a later date when more contrib modules have been updated. If you do run site-upgrade a second time on the same site, drush will ask you if you want to replace the existing target site, effectively starting over from the beginning, or re-use the code that is already present. In the latter case, drush will use the existing code, but will re-copy the source database and run updatedb on it again. This allows you to attempt to fix any non-working contrib modules yourself to get your site-upgrade working.

Enjoy!

Comments

Posted on by Yannick Lyn Fatt.

If I run a Drupal Multi-Site setup how would this handle running database updates for the other sites? And what about modules that exist but are not enabled, will they be upgraded to their D7 versions as well?

Posted on by Rick Umali.

I wish I had tried this on my own D6-to-D7 upgrade! It looks like this would have handled a lot of the mechanical tasks (e.g. module and dependencies download, settings.php, etc.).

Once the site-upgrade is finished, and you want to deploy the upgraded Drupal, you'd only need to delete (or move aside) the old Drupal (at /path/to/old/drupalroot, for example), and then copy the /path/to/upgraded/drupalroot into its place?

Posted on by mweitzman.

The best practice for going live is to make your D7 site live at a temporary domain like new.example.com. Once you are ready to cut over to the D7 site, change your www.example.com virtual host (or equivalent) to point to the new.example.com codebase. This technique makes rollback easier.

Posted on by KatherineK (not verified).

The drush command 'site-upgrade' could not be found.

Posted on by Dun Tuk.

the code above should use () and not {}

Posted on by ñull (not verified).

Not only the round brackets, also the word array is missing. I wasted ages on this error. It should be:

$aliases['onward'] = array (
'root' => '/path/to/upgraded/drupalroot',
'uri' => 'http://onward.mysite.org',
);

Posted on by Rob (not verified).

The 6>7 drush site upgrade command is now a separate module: http://drupal.org/project/d rush_sup

Posted on by Charlie (not verified).

Can you explain "to an empty Drupal site"? Are you referring to an empty folder somewhere on the server, a new database, or what exactly?

Posted on by sokratis lasdas.

The site that should be aliased is the new site and also the alias should be inside php brackets.So this should be something like that:
<?php
$aliases['test'] = array(
'root' => '/var/www/d7',
'uri' => 'localhost',
);
?>

Posted on by FranK (not verified).

I have followed the whole procedure and it looks like working until 12-a. At that point, all the tables from the source database are dropped and the system stops because it can't find the tables.

Posted on by chao (not verified).

me too ,Now you solve this problem?

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Filtered HTML

  • Use [acphone_sales], [acphone_sales_text], [acphone_support], [acphone_international], [acphone_devcloud], [acphone_extra1] and [acphone_extra2] as placeholders for Acquia phone numbers. Add class "acquia-phones-link" to wrapper element to make number a link.
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <h4> <h5> <h2> <img>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.