How to migrate your drupal site with drush

How to migrate your drupal site with drush?

I have recently tried to move a large database to another host and I have encountered problems regarding this.

I have decided to document this so that other Drupal users may benefit from it.

There are many ways to restoring a database to different host but this has worked for me.

First, you need to have a working drush system in your both drupal installations.

Start with clearing all of your database cache

$cd /home/home/public_html or wherever is your root Drupal installation
$drush cc all

to clear all cache
Some of the cache tables may not be cleared properly so that I would recommend to go your database with phpmysql and clear all the tables that start with cache. You can also empty accesslog, watchdog and search tables.

After that take a dump of your sql database

$ drush sql-dump --result-file=yourfile_name_date.sql

A yourfile_name_date.sql is created on your root Drupal site. Create a tar.gz folder of your drupal folder/site.

$tar -zcvf myfoldername_date.tar.gz /home/Your_Home_name/public_html
this will create a file called myfoldername_date.tar.gz

Now, download them and move both your files to the new host using your favourite tool such as ftp,scp etc.

Now create an empty database with same username and password if possible at your new host. It doesn't have to be same but this will safe a little bit of time for you because your don't have to change the settings.php file.

Untar your my foldername_date.tar.gz by using this command. Please navigate your home folder

$tar -zxvf myfoldername_date.tar.gz -C /home/yourhome_name/public_html

$cd /home/yourhome_name/public_html
$ ls -al
to list your files and check it.

Now, edit settings.php to match your database name and password

It is time to dump your previous uploaded database to your new database.
You can also dumb the database before you untar your home_folder

There are two ways you can do this, your just use mysql to dump your database by using this command

mysql -u root -p new_database_name < yourprevious_databse.sql

In this case your database is uploaded in /var/lib/mysql, you navigate to this place to do it easily.

The other way is to use drush sql-query

In this case, your created .sql file is in /home/yourhome/public_html and run this command

$drush sql-query < yourprevious_database.sql

Put your new site in maintenance mode and run update one more time.
$drush updb
Take another sql dump using the above command just in case
Navigate to your drupal public_html folder and run
$ drush updb to update your database one more time.

You may experience permission issues, this is normal and you need to read your apache error files.
You can chmod or chown folders and and files if you upload your files as root
$chown -R username:groupname folder_to_chown
$chomd -R 0755 folders_to_chmod

If you restored your database as root then you need to chown your
new database to belong mysql:your_user_name

Navigate to your database folder, main is /var/lib/mysql

$chown -R mysql:usernamel yourdatabase_name
Please mysql:username is user and group name which own the database,
yours could be different so please check.

And that is it.

This should not take more 10 minutes depending how big are your files and database.
If your database is not big enough you can just use the excellent back up and migrate module
which can do this much quicker but the approach is different.


Apache Yahoo News Feed

Drupal Yahoo News

Linux Yahoo News Feed

Mysql Yahoo News Feed