3

I have set up post-receive hook on my staging server, so whenever I push from dev server a master branch, it updates staging webroot and triggers drush rsync to update live site.

#!/bin/bash

    while read oldrev newrev ref
    do
      branch=`echo $ref | cut -d/ -f3`

      if [ "master" == "$branch" ]; then
    git --work-tree=/var/www/drupal/ checkout -f $branch
    drush rsync --delete --exclude='.htaccess' --exclude='io' --log-file=rsynclog.txt --exclude-files @stage @live 

        echo 'Changes pushed live.'
      fi

      if [ "dev" == "$branch" ]; then
        git --work-tree=/var/www/drupal/ checkout -f $branch
        echo 'Changes pushed to staging.'
      fi
    done

Or i hoped to do so :) I have ssh keys in place and that is not the problem, what i can see is that it hangs on destroy yes no question. Output after git push origin from dev machine:

Counting objects: 15, done.

Delta compression using up to 4 threads. Compressing objects: 100% (8/8), done. Writing objects: 100% (8/8), 762 bytes, done. Total 8 (delta 5), reused 0 (delta 0)

remote: Already on 'master'

remote: You will destroy data from mydomain.com:/var/www/drupal/ and replace with data from /var/www/drupal// remote: Do you really want to continue? (y/n): Aborting. [cancel]

remote: Changes pushed live. To root@dev:/git/drupal 65abd19..7205946 master -> master

So I would need somehow to tell script that answer is y, or I need a way to avoid that question at all.

Also, I am not pro bash scripter ;) , are those commands being excecuted in line, like in php, so one is not executed before other finishes ? (to make sure changes are propagated on staging webroot first, then rsynced all to live).

5

Add the --yes option to your Drush command. This assuredly will work if you place it before the rsync directive.

For example:

drush --yes rsync @dev @live

Drush rsync is different than most Drush commands in that it uses strict option handling. Commands that work with strict options pass all extra flags that appear after the Drush command name on to the tool that is being invoked. Thus, drush rsync --yes @dev @live will fail, because the --yes will be ignored by Drush and passed on to rsync.

For more information, see:

drush topic docs-strict-options

  • 1
    Thank heavens for the maintainers. :) Thanks Greg. +1 – webkenny Mar 6 '13 at 19:44
  • I had not chance to test this yet, but I bet it works as described here. I am lucky to receive an answer from a authentic Drupal Overlord :) – NenadP Mar 6 '13 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.