Synchronize drupal installations with drush

Drush allows to easily synchronize drupal installations, from files to databases, with a simple drush command.

For that you need a php file  in ~/.drush or in your site /sites/all/drush directory to tell drush how to access your sites.

That’s a simple example file (I have moved my sites directory to /home/user/www):


(//local environment)

$aliases[‘sitename.local’] = array(
‘uri’ => ‘localhost/sitename’,
‘root’ => ‘/home/user/www/sitename/’,
‘path-aliases’ => array(
‘%files’ => ‘sites/default/files’,

(//and in my case a 1and1 hosting)

$aliases[‘sitename.remote’] = array(
‘uri’ => ‘hosturl/sitename’,
‘remote-host’ => ‘hostdirection’,
‘remote-user’ => ‘sshuser’,
‘root’ => ‘/kunden/homepages/xx/xxx/htdocs/sitename/’,
‘path-aliases’ => array(
‘%files’ => ‘sites/default/files’,

You will need to setup a ssh key to access remotely your host.

To test that it works:

drush @sitename.remote status

You can then sync your databases as follows:

drush sql-sync @sitename.remote @sitename.local

(from remote to local)