I'm trying to use the path-aliases feature but they don't seem to be resolving.

drush sa @local

returns:

$aliases['local'] = array (
  'root' => '/Users/christian/Sites/site-name',
  'uri' => 'default',
  'path-aliases' => 
  array (
    '%files' => 'sites/default/files',
  ),
);

but when I type

drush dd @local:%files

it returns:

/Users/christian/Sites/site-name/%files

It's literally outputting "%files" rather than sites/default/files

Comments

luchochs’s picture

You can omit the 'uri' item (assuming your site isn't part of a multisite instance).

luchochs’s picture

And if your 'files' directory is in the conventional place, you don't need define it explicitly via 'path-aliases'.
If so, this is another command that can help you:
shell> drush @local dd files

jh3’s picture

I'm also having a similar issue. My files directory is also in the standard place, but doing something like "drush dd @dev:%files" when I have %files set will literally print out "/path/to/drupal/%files".

Also, I have a "%dump" key set and when I do "drush @dev sql-dump > `drush dd @dev:%dump`" i get a file called "/path/to/drupal/%dump" instead of the one I provided in my aliases.drushrc.php file.

What's the reason for this happening?

cschlens’s picture

Actually the real issue I'm having is when trying to rsync files with a remote alias called @dev

I enter:

 drush rsync @dev:%files ~/Desktop/files/

and it returns:

You will destroy data from /Users/christian/Desktop/files/ and replace with data from @dev:/Users/christian/Sites/site-name/%files

Even though @dev is a remote alias and I've been able to run other drush commands on it successfully it thinks @dev:%files is on my local machine, specifically wherever I was when I called the drush rsync command.

sharpbites’s picture

Version: 6.x-3.2 » All-versions-3.3

I have the same problem with version 3.3. It only happens (to me) when the aliases file is inside de sites/default folder. If I move it to .drush/ everything works fine, but I would very much prefer to put the file inside the project root so that it can be versioned.

For the record, it also happens with @self:

drush dd @self:%files
/home/username/public_html/projectname/%files

jh3’s picture

@sharpbites: I was just about to respond with the same problem.

When I have an alias file on my local machine, it works fine in ~/.drush. If I move it to /projects/path/to/drupal/sites/default, it's not recognized.

If I copy the same alias file to the remote server and place it in /path/to/drupal/sites/default, drush recognizes it.

Like sharpbites, I'd like to have separate alias files for each site stored in sites/default working locally.

jh3’s picture

Of course I (kind of) figure out why this is happening a few minutes later.

I'm not tracking settings.php in my local repository. When that file is not present, and you have aliases.drushrc.php in sites/default on your local box, drush site-alias will not run. I don't want to track settings.php though because I push the site to different servers that require different DB information. Plus, if I have settings.php on my local machine with remote DB information, I receive annoying warnings from drush:

PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) environment.inc:952                                                                                                    [warning]
SQLSTATE[HY000] [2002] No such file or directory                                                                                                                                                                                 [warning]

Is there any way around this?

sharpbites’s picture

@ejh3
Copying the aliases file to the remote site (another drupal in the same machine, in my case) didn't work for me.
I didn't really understand the part about having settings.php under source control or not.

I have found one way to make it work with local aliases files. You have to use your sitename when calling drush, like this:
drush default rsync @dev:%files @local:%files

I don't know if this is the expected use, I dind't find it in the docs. I have to use it like that even from inside the site/default folder.

I guess this is to bootstrap it, whatever that means, as per the comments in the example.aliases file:

* 3. Inside the sites folder of any bootstrapped Drupal site,
* or any local Drupal site indicated by an alias used as
* a parameter to a command

jh3’s picture

Here is an example of one of my aliases:

$aliases['my_alias'] = array(
  'remote-host' => '111.111.111.111',
  'remote-user' => 'username',
  'uri' => 'default',
  'root' => '/path/to/website',
  'path-aliases' => array(
    '%files' => 'sites/default/files',
    '%dump' => '/path/to/website/sql-sync-dev-local.sql',
   ),
  'command-specific' => array (
    'sql-sync' => array (
      'simulate' => '0',
      'structure-tables' => array(
        'custom' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history', 'sessions', 'watchdog'),
      ),
    ),
    'rsync' => array (
      'simulate' => '0',
      'mode' => 'rlptDz',
    ),
  ),
);

And here is what I've encountered (locally):

Having the aliases.drushrc.php file in sites/default without a settings.php file, drush doesn't recognize any of the following:
drush @my_alias status
drush default @my_alias status

Instead if spits back:
Could not find a Drupal settings.php file at ./sites/default/settings.php. The drush command 'default @my_alias st' could not be found.

Having aliases.drushrc.php in sites/default with a vanilla settings.php file (no DB information), drush @my_alias status will work. Local commands will not work because the DB information is missing from settings.php. I can put the database URL in settings.php, but that causes warnings (which I guess really do no harm, but they are just annoying).

All of the above is probably supposed to happen and I'm probably just doing something wrong. I would just really like to have the aliases working when in sites/default instead of having to store them in $HOME/.drush.

Also, I found this post not too long ago, but it didn't really solve any of my problems -- http://drupal.org/node/766278

greg.1.anderson’s picture

Status: Active » Fixed

There is a chicken-and-egg problem with storing your aliases in sites/default. The alias defines where drush should look to find your settings.php file. sites/default is not a valid location for alias files until the 'default' site has been bootstrapped.

Should drush look in sites/default even if the site has not yet been bootstrapped? There are a couple of problems with this. For one thing, it is the alias that defines where the Drupal root is; drush can't find sites/default until it has used the alias to find the Drupal root. Oops. The other problem is that aliases in sites/default are intended to be aliases that are only relevant for that one site (e.g. the live site for your dev site, or visa-versa). If drush used aliases for sites that had not yet been bootstrapped, and there were multiple sites to consider, then all of their local aliases would be loaded -- and then those aliases wouldn't be local any more. If you only have one site, then you don't really need aliases; you can just use $options['root'] and $options['uri'] in your drushrc.php file.

There is one instance where drush will load aliases for sites that have not been bootstrapped, as mentioned above. If you rsync or sql-sync to or from a site identified by a global alias (e.g. in .drush/aliases.drushrc.php, etc.), then you may use a local alias of that site for the other target.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.