Hướng dẫn drush Self Aliases

Hướng dẫn drush Self Aliases

I ran into an interesting problem with the drush @self alias today. I wanted to pull a fresh copy of the DB down from a client’s live site to my local development copy. Should be as easy as drush sql-sync @clientsite.live @self, right? I’ve done this a thousand times before.

And I’ve also ignored the warning message every time before, but today I thought I’d check it out:

WARNING: Using temporary files to store and transfer sql-dump. It is recommended that you specify —source-dump and —target-dump options on the command line, or set ‘%dump’ or ‘%dump-dir’ in the path-aliases section of your site alias records. This facilitates fast file transfer via rsync.

There are actually two possible solutions to this warning (that I can think of), and they illustrate some of the useful “power user” features of Drush that any frequent user should be aware of.

The warning is there because drush would prefer to rsync the DB dump from site1 to site2, rather than a one time copy. Rsync has lots of speed improvements, not the least being diff transfer. When transferring an updated copy of a file which already exists at the destination, rsync will only send over the changes rather than the whole file. This is pretty useful if you’re dealing with a large, text based file like an SQL dump – especially one that you’ll be transferring often. In order to use this efficient processing though, Drush needs to know a safe path where it can store the DB dump in each location.

First we’ll add the %dump-dir% attribute to our alias for clientsite:

~/.drush/clientsite.aliases.drush.php

<?php
// Site clientsite, environment live 
$aliases['live'] = array(
  'parent' => '@parent',
  'site' => 'clientsite',
  'env' => 'live',
  'root' => '/var/www/example.com/public_html',
  'remote-host' => 'example.com',
  'remote-user' => 'cvertesi',
  'path-aliases' => array(
    '%dump-dir' => '/home/cvertesi/.drush/db_dumps',
  ),
);

Notice that %dump-dir actually goes in a special sub-array for path-aliases. This is very likely the only time you’ll need to use that section, since most everything else in there is auto-detected. This is the directory on the remote side where drush will store the dump.

Our options come in with the @self alias. In a local dev environment, the most common way to handle this is in your drushrc.php file:

~/.drush/drushrc.php

$options['dump-dir'] = '~/.drush/db_dumps';

But this won’t work for all cases. You can also take advantage of Drush’s alias handling by creating a site alias with the settings you want, and letting Drush merge those settings into @self. When Drush builds its’ cache of path aliases, it uses the site path as the cache key (for local sites only). That means that if you have a local alias with the same path as whatever @self happens to resolve to, your alias options will make it into the definition for @self. So here’s the alternate solution:

~/.drush/clientsite.aliases.drush.php

$aliases['localdev'] = array(
  'root' => '/Users/cvertesi/Sites/clientsite',
  'uri' => 'default',
  'path-aliases' => array(
    '%dump-dir' => '/home/cvertesi/.drush/db_dumps',
  ),
);

There’s just one, obscure caveat with the latter method: somewhere in the alias merging process, BASH aliases are lost. That means that ‘~’ stops resolving to your home directory, and you have to write it out (as I did above).

Have fun!

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Rò rỉ thông số kĩ thuật của máy ảnh Sony Cyber-shot RX100 MkII

Rò rỉ thông số kĩ thuật của máy ảnh Sony Cyber-shot RX100 MkII

Sau khi tung ra Cyber-shot RX100 cách đây không lâu, có vẻ như Sony muốn tiếp tục gây ấn tượng với người dùng với kế hoạch phát hành Cyber-shot RX100 MkII.

Hướng dẫn Drupal 7: Load content nodes vào modal overlay sử dụng AJAX

Hướng dẫn Drupal 7: Load content nodes vào modal overlay sử dụng AJAX

AJAX to the rescue.  By loading each of the individual content nodes "on demand" we can cut the unnecessary burden of loading everything up front, and only load the content that is actually requested by the visitor

Google nâng cấp phiên bản Google+ mới cho iPhone

Google nâng cấp phiên bản Google+ mới cho iPhone

Google vừa mới nâng cấp ứng dụng Google+ trên iPhone, theo đó đã thêm vào tính năng tìm kiếm và 1 số tính năng khác mà trước đây chỉ có trên phiên bản dành cho PC.

Công ty diệt chuột T&C

 

Diet con trung